]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/dumpert.py
[cleanup] Misc
[yt-dlp.git] / yt_dlp / extractor / dumpert.py
1 from .common import InfoExtractor
2 from ..utils import (
3 determine_ext,
4 int_or_none,
5 qualities,
6 )
7
8
9 class DumpertIE(InfoExtractor):
10 _VALID_URL = r'''(?x)
11 (?P<protocol>https?)://(?:(?:www|legacy)\.)?dumpert\.nl(?:
12 /(?:mediabase|embed|item)/|
13 (?:/toppers|/latest|/?)\?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,
27 }
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,
48 },
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
61 def _real_extract(self, url):
62 video_id = self._match_id(url).replace('_', '/')
63 item = self._download_json(
64 'http://api-live.dumpert.nl/mobile_api/json/info/' + video_id.replace('/', '_'),
65 video_id)['items'][0]
66 title = item['title']
67 media = next(m for m in item['media'] if m.get('mediatype') == 'VIDEO')
68
69 quality = qualities(['flv', 'mobile', 'tablet', '720p', '1080p'])
70 formats = []
71 for variant in media.get('variants', []):
72 uri = variant.get('uri')
73 if not uri:
74 continue
75 version = variant.get('version')
76 preference = quality(version)
77 if determine_ext(uri) == 'm3u8':
78 formats.extend(self._extract_m3u8_formats(
79 uri, video_id, 'mp4', m3u8_id=version, quality=preference))
80 else:
81 formats.append({
82 'url': uri,
83 'format_id': version,
84 'quality': preference,
85 })
86
87 thumbnails = []
88 stills = item.get('stills') or {}
89 for t in ('thumb', 'still'):
90 for s in ('', '-medium', '-large'):
91 still_id = t + s
92 still_url = stills.get(still_id)
93 if not still_url:
94 continue
95 thumbnails.append({
96 'id': still_id,
97 'url': still_url,
98 })
99
100 stats = item.get('stats') or {}
101
102 return {
103 'id': video_id,
104 'title': title,
105 'description': item.get('description'),
106 'thumbnails': thumbnails,
107 'formats': formats,
108 'duration': int_or_none(media.get('duration')),
109 'like_count': int_or_none(stats.get('kudos_total')),
110 'view_count': int_or_none(stats.get('views_total')),
111 }