]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/umg.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / umg.py
1 from .common import InfoExtractor
2 from ..utils import (
3 int_or_none,
4 parse_filesize,
5 parse_iso8601,
6 )
7
8
9 class UMGDeIE(InfoExtractor):
10 IE_NAME = 'umg:de'
11 IE_DESC = 'Universal Music Deutschland'
12 _VALID_URL = r'https?://(?:www\.)?universal-music\.de/[^/]+/videos/[^/?#]+-(?P<id>\d+)'
13 _TEST = {
14 'url': 'https://www.universal-music.de/sido/videos/jedes-wort-ist-gold-wert-457803',
15 'md5': 'ebd90f48c80dcc82f77251eb1902634f',
16 'info_dict': {
17 'id': '457803',
18 'ext': 'mp4',
19 'title': 'Jedes Wort ist Gold wert',
20 'timestamp': 1513591800,
21 'upload_date': '20171218',
22 }
23 }
24
25 def _real_extract(self, url):
26 video_id = self._match_id(url)
27 video_data = self._download_json(
28 'https://graphql.universal-music.de/',
29 video_id, query={
30 'query': '''{
31 universalMusic(channel:16) {
32 video(id:%s) {
33 headline
34 formats {
35 formatId
36 url
37 type
38 width
39 height
40 mimeType
41 fileSize
42 }
43 duration
44 createdDate
45 }
46 }
47 }''' % video_id})['data']['universalMusic']['video']
48
49 title = video_data['headline']
50 hls_url_template = 'http://mediadelivery.universal-music-services.de/vod/mp4:autofill/storage/' + '/'.join(list(video_id)) + '/content/%s/file/playlist.m3u8'
51
52 thumbnails = []
53 formats = []
54
55 def add_m3u8_format(format_id):
56 formats.extend(self._extract_m3u8_formats(
57 hls_url_template % format_id, video_id, 'mp4',
58 'm3u8_native', m3u8_id='hls', fatal=False))
59
60 for f in video_data.get('formats', []):
61 f_url = f.get('url')
62 mime_type = f.get('mimeType')
63 if not f_url or mime_type == 'application/mxf':
64 continue
65 fmt = {
66 'url': f_url,
67 'width': int_or_none(f.get('width')),
68 'height': int_or_none(f.get('height')),
69 'filesize': parse_filesize(f.get('fileSize')),
70 }
71 f_type = f.get('type')
72 if f_type == 'Image':
73 thumbnails.append(fmt)
74 elif f_type == 'Video':
75 format_id = f.get('formatId')
76 if format_id:
77 fmt['format_id'] = format_id
78 if mime_type == 'video/mp4':
79 add_m3u8_format(format_id)
80 urlh = self._request_webpage(f_url, video_id, fatal=False)
81 if urlh:
82 first_byte = urlh.read(1)
83 if first_byte not in (b'F', b'\x00'):
84 continue
85 formats.append(fmt)
86 if not formats:
87 for format_id in (867, 836, 940):
88 add_m3u8_format(format_id)
89
90 return {
91 'id': video_id,
92 'title': title,
93 'duration': int_or_none(video_data.get('duration')),
94 'timestamp': parse_iso8601(video_data.get('createdDate'), ' '),
95 'thumbnails': thumbnails,
96 'formats': formats,
97 }