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