]>
Commit | Line | Data |
---|---|---|
3a30508b | 1 | from .common import InfoExtractor |
a0904c5d YCH |
2 | from ..utils import ( |
3 | determine_ext, | |
564275e2 RA |
4 | int_or_none, |
5 | parse_iso8601, | |
6 | try_get, | |
a0904c5d | 7 | ) |
3a30508b S |
8 | |
9 | ||
10 | class TelegraafIE(InfoExtractor): | |
564275e2 | 11 | _VALID_URL = r'https?://(?:www\.)?telegraaf\.nl/video/(?P<id>\d+)' |
3a30508b | 12 | _TEST = { |
564275e2 | 13 | 'url': 'https://www.telegraaf.nl/video/734366489/historisch-scheepswrak-slaat-na-100-jaar-los', |
3a30508b | 14 | 'info_dict': { |
564275e2 | 15 | 'id': 'gaMItuoSeUg2', |
3a30508b | 16 | 'ext': 'mp4', |
564275e2 RA |
17 | 'title': 'Historisch scheepswrak slaat na 100 jaar los', |
18 | 'description': 'md5:6f53b7c4f55596722ac24d6c0ec00cfb', | |
19 | 'thumbnail': r're:^https?://.*\.jpg', | |
20 | 'duration': 55, | |
21 | 'timestamp': 1572805527, | |
22 | 'upload_date': '20191103', | |
3a30508b | 23 | }, |
a0904c5d YCH |
24 | 'params': { |
25 | # m3u8 download | |
26 | 'skip_download': True, | |
27 | }, | |
3a30508b S |
28 | } |
29 | ||
30 | def _real_extract(self, url): | |
564275e2 | 31 | article_id = self._match_id(url) |
3a30508b | 32 | |
564275e2 RA |
33 | video_id = self._download_json( |
34 | 'https://www.telegraaf.nl/graphql', article_id, query={ | |
35 | 'query': '''{ | |
36 | article(uid: %s) { | |
37 | videos { | |
38 | videoId | |
39 | } | |
40 | } | |
41 | }''' % article_id, | |
42 | })['data']['article']['videos'][0]['videoId'] | |
3a30508b | 43 | |
564275e2 RA |
44 | item = self._download_json( |
45 | 'https://content.tmgvideo.nl/playlist/item=%s/playlist.json' % video_id, | |
46 | video_id)['items'][0] | |
47 | title = item['title'] | |
a0904c5d | 48 | |
a0904c5d | 49 | formats = [] |
564275e2 | 50 | locations = item.get('locations') or {} |
a0904c5d | 51 | for location in locations.get('adaptive', []): |
564275e2 RA |
52 | manifest_url = location.get('src') |
53 | if not manifest_url: | |
54 | continue | |
a0904c5d YCH |
55 | ext = determine_ext(manifest_url) |
56 | if ext == 'm3u8': | |
57 | formats.extend(self._extract_m3u8_formats( | |
f75e6890 | 58 | manifest_url, video_id, ext='mp4', m3u8_id='hls', fatal=False)) |
a0904c5d | 59 | elif ext == 'mpd': |
d9cb92c8 S |
60 | formats.extend(self._extract_mpd_formats( |
61 | manifest_url, video_id, mpd_id='dash', fatal=False)) | |
a0904c5d YCH |
62 | else: |
63 | self.report_warning('Unknown adaptive format %s' % ext) | |
64 | for location in locations.get('progressive', []): | |
564275e2 RA |
65 | src = try_get(location, lambda x: x['sources'][0]['src']) |
66 | if not src: | |
67 | continue | |
68 | label = location.get('label') | |
a0904c5d | 69 | formats.append({ |
564275e2 RA |
70 | 'url': src, |
71 | 'width': int_or_none(location.get('width')), | |
72 | 'height': int_or_none(location.get('height')), | |
73 | 'format_id': 'http' + ('-%s' % label if label else ''), | |
a0904c5d YCH |
74 | }) |
75 | ||
76 | self._sort_formats(formats) | |
3a30508b | 77 | |
a0904c5d YCH |
78 | return { |
79 | 'id': video_id, | |
80 | 'title': title, | |
564275e2 | 81 | 'description': item.get('description'), |
a0904c5d | 82 | 'formats': formats, |
564275e2 RA |
83 | 'duration': int_or_none(item.get('duration')), |
84 | 'thumbnail': item.get('poster'), | |
85 | 'timestamp': parse_iso8601(item.get('datecreated'), ' '), | |
a0904c5d | 86 | } |