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