]> jfr.im git - yt-dlp.git/commitdiff
[extractor/ViMP] Add playlist extractor (#4147)
authorFestplattenSchnitzel <redacted>
Wed, 29 Jun 2022 00:06:25 +0000 (02:06 +0200)
committerGitHub <redacted>
Wed, 29 Jun 2022 00:06:25 +0000 (05:36 +0530)
Authored by: FestplattenSchnitzel

yt_dlp/extractor/_extractors.py
yt_dlp/extractor/videocampus_sachsen.py

index f142a178057e390a83efd66e2c5bac7fae6584da..b2a072fc16fd82e44b6a92376aa9946eef978cd4 100644 (file)
 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 (
index 679574bd731fee5bc6b1e5d0b8c4ce24f8678608..1aa84ea701c152128f00f851b7fb340e438992ee 100644 (file)
@@ -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)(?P<host>https?://(?:%s))/(?:
+        album/view/aid/(?P<album_id>[0-9]+)|
+        (?P<mode>category|channel)/(?P<name>[\w-]+)/(?P<id>[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}')