From 1db146127292e31fa8e8cb47e9ce2b696bbe173b Mon Sep 17 00:00:00 2001 From: FestplattenSchnitzel <45077355+FestplattenSchnitzel@users.noreply.github.com> Date: Wed, 29 Jun 2022 02:06:25 +0200 Subject: [PATCH] [extractor/ViMP] Add playlist extractor (#4147) Authored by: FestplattenSchnitzel --- yt_dlp/extractor/_extractors.py | 5 +- yt_dlp/extractor/videocampus_sachsen.py | 71 ++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/yt_dlp/extractor/_extractors.py b/yt_dlp/extractor/_extractors.py index f142a1780..b2a072fc1 100644 --- a/yt_dlp/extractor/_extractors.py +++ b/yt_dlp/extractor/_extractors.py @@ -1934,7 +1934,10 @@ from .vidbit import VidbitIE from .viddler import ViddlerIE from .videa import VideaIE -from .videocampus_sachsen import VideocampusSachsenIE +from .videocampus_sachsen import ( + VideocampusSachsenIE, + ViMPPlaylistIE, +) from .videodetective import VideoDetectiveIE from .videofyme import VideofyMeIE from .videomore import ( diff --git a/yt_dlp/extractor/videocampus_sachsen.py b/yt_dlp/extractor/videocampus_sachsen.py index 679574bd7..1aa84ea70 100644 --- a/yt_dlp/extractor/videocampus_sachsen.py +++ b/yt_dlp/extractor/videocampus_sachsen.py @@ -1,8 +1,9 @@ +import functools import re from .common import InfoExtractor from ..compat import compat_HTTPError -from ..utils import ExtractorError +from ..utils import ExtractorError, OnDemandPagedList, urlencode_postdata class VideocampusSachsenIE(InfoExtractor): @@ -183,3 +184,71 @@ def _real_extract(self, url): 'formats': formats, 'subtitles': subtitles, } + + +class ViMPPlaylistIE(InfoExtractor): + IE_NAME = 'ViMP:Playlist' + _VALID_URL = r'''(?x)(?Phttps?://(?:%s))/(?: + album/view/aid/(?P[0-9]+)| + (?Pcategory|channel)/(?P[\w-]+)/(?P[0-9]+) + )''' % '|'.join(map(re.escape, VideocampusSachsenIE._INSTANCES)) + + _TESTS = [{ + 'url': 'https://vimp.oth-regensburg.de/channel/Designtheorie-1-SoSe-2020/3', + 'info_dict': { + 'id': 'channel-3', + 'title': 'Designtheorie 1 SoSe 2020 :: Channels :: ViMP OTH Regensburg', + }, + 'playlist_mincount': 9, + }, { + 'url': 'https://www.fh-bielefeld.de/medienportal/album/view/aid/208', + 'info_dict': { + 'id': 'album-208', + 'title': 'KG Praktikum ABT/MEC :: Playlists :: FH-Medienportal', + }, + 'playlist_mincount': 4, + }, { + 'url': 'https://videocampus.sachsen.de/category/online-tutorials-onyx/91', + 'info_dict': { + 'id': 'category-91', + 'title': 'Online-Seminare ONYX - BPS - Bildungseinrichtungen - VCS', + }, + 'playlist_mincount': 7, + }] + _PAGE_SIZE = 10 + + def _fetch_page(self, host, url_part, id, data, page): + webpage = self._download_webpage( + f'{host}/media/ajax/component/boxList/{url_part}', id, + query={'page': page, 'page_only': 1}, data=urlencode_postdata(data)) + urls = re.findall(r'"([^"]+/video/[^"]+)"', webpage) + + for url in urls: + yield self.url_result(host + url, VideocampusSachsenIE) + + def _real_extract(self, url): + host, album_id, mode, name, id = self._match_valid_url(url).group( + 'host', 'album_id', 'mode', 'name', 'id') + + webpage = self._download_webpage(url, album_id or id, fatal=False) or '' + title = (self._html_search_meta('title', webpage, fatal=False) + or self._html_extract_title(webpage)) + + url_part = (f'aid/{album_id}' if album_id + else f'category/{name}/category_id/{id}' if mode == 'category' + else f'title/{name}/channel/{id}') + + mode = mode or 'album' + data = { + 'vars[mode]': mode, + f'vars[{mode}]': album_id or id, + 'vars[context]': '4' if album_id else '1' if mode == 'category' else '3', + 'vars[context_id]': album_id or id, + 'vars[layout]': 'thumb', + 'vars[per_page][thumb]': str(self._PAGE_SIZE), + } + + return self.playlist_result( + OnDemandPagedList(functools.partial( + self._fetch_page, host, url_part, album_id or id, data), self._PAGE_SIZE), + playlist_title=title, id=f'{mode}-{album_id or id}')