[cleanup] Make more playlist entries lazy (#11763)
[yt-dlp.git] / yt_dlp / extractor / dumpert.py
blob1c2050cc17eb41219041f90c806361d788aa6549
1 from .common import InfoExtractor
2 from ..utils import (
3 determine_ext,
4 int_or_none,
5 qualities,
9 class DumpertIE(InfoExtractor):
10 _VALID_URL = r'''(?x)
11 (?P<protocol>https?)://(?:(?:www|legacy)\.)?dumpert\.nl/(?:
12 (?:mediabase|embed|item)/|
13 [^#]*[?&]selectedId=
14 )(?P<id>[0-9]+[/_][0-9a-zA-Z]+)'''
15 _TESTS = [{
16 'url': 'https://www.dumpert.nl/item/6646981_951bc60f',
17 'md5': '1b9318d7d5054e7dcb9dc7654f21d643',
18 'info_dict': {
19 'id': '6646981/951bc60f',
20 'ext': 'mp4',
21 'title': 'Ik heb nieuws voor je',
22 'description': 'Niet schrikken hoor',
23 'thumbnail': r're:^https?://.*\.jpg$',
24 'duration': 9,
25 'view_count': int,
26 'like_count': int,
28 }, {
29 'url': 'https://www.dumpert.nl/embed/6675421_dc440fe7',
30 'only_matching': True,
31 }, {
32 'url': 'http://legacy.dumpert.nl/mediabase/6646981/951bc60f',
33 'only_matching': True,
34 }, {
35 'url': 'http://legacy.dumpert.nl/embed/6675421/dc440fe7',
36 'only_matching': True,
37 }, {
38 'url': 'https://www.dumpert.nl/item/100031688_b317a185',
39 'info_dict': {
40 'id': '100031688/b317a185',
41 'ext': 'mp4',
42 'title': 'Epic schijnbeweging',
43 'description': '<p>Die zag je niet eh</p>',
44 'thumbnail': r're:^https?://.*\.(?:jpg|png)$',
45 'duration': 12,
46 'view_count': int,
47 'like_count': int,
49 'params': {'skip_download': 'm3u8'},
50 }, {
51 'url': 'https://www.dumpert.nl/toppers?selectedId=100031688_b317a185',
52 'only_matching': True,
53 }, {
54 'url': 'https://www.dumpert.nl/latest?selectedId=100031688_b317a185',
55 'only_matching': True,
56 }, {
57 'url': 'https://www.dumpert.nl/?selectedId=100031688_b317a185',
58 'only_matching': True,
59 }, {
60 'url': 'https://www.dumpert.nl/toppers/dag?selectedId=100086074_f5cef3ac',
61 'only_matching': True,
64 def _real_extract(self, url):
65 video_id = self._match_id(url).replace('_', '/')
66 item = self._download_json(
67 'http://api-live.dumpert.nl/mobile_api/json/info/' + video_id.replace('/', '_'),
68 video_id)['items'][0]
69 title = item['title']
70 media = next(m for m in item['media'] if m.get('mediatype') == 'VIDEO')
72 quality = qualities(['flv', 'mobile', 'tablet', '720p', '1080p'])
73 formats = []
74 for variant in media.get('variants', []):
75 uri = variant.get('uri')
76 if not uri:
77 continue
78 version = variant.get('version')
79 preference = quality(version)
80 if determine_ext(uri) == 'm3u8':
81 formats.extend(self._extract_m3u8_formats(
82 uri, video_id, 'mp4', m3u8_id=version, quality=preference))
83 else:
84 formats.append({
85 'url': uri,
86 'format_id': version,
87 'quality': preference,
90 thumbnails = []
91 stills = item.get('stills') or {}
92 for t in ('thumb', 'still'):
93 for s in ('', '-medium', '-large'):
94 still_id = t + s
95 still_url = stills.get(still_id)
96 if not still_url:
97 continue
98 thumbnails.append({
99 'id': still_id,
100 'url': still_url,
103 stats = item.get('stats') or {}
105 return {
106 'id': video_id,
107 'title': title,
108 'description': item.get('description'),
109 'thumbnails': thumbnails,
110 'formats': formats,
111 'duration': int_or_none(media.get('duration')),
112 'like_count': int_or_none(stats.get('kudos_total')),
113 'view_count': int_or_none(stats.get('views_total')),