]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/br.py
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
19 class BRIE(InfoExtractor
):
20 IE_DESC
= 'Bayerischer Rundfunk'
21 _VALID_URL
= r
'(?P<base_url>https?://(?:www\.)?br(?:-klassik)?\.de)/(?:[a-z0-9\-_]+/)+(?P<id>[a-z0-9\-_]+)\.html'
25 'url': 'http://www.br.de/mediathek/video/sendungen/abendschau/betriebliche-altersvorsorge-104.html',
26 'md5': '83a0477cf0b8451027eb566d88b51106',
28 'id': '48f656ef-287e-486f-be86-459122db22cc',
30 'title': 'Die böse Überraschung',
31 'description': 'md5:ce9ac81b466ce775b8018f6801b48ac9',
33 'uploader': 'Reinhard Weber',
34 'upload_date': '20150422',
36 'skip': '404 not found',
39 'url': 'http://www.br.de/nachrichten/oberbayern/inhalt/muenchner-polizeipraesident-schreiber-gestorben-100.html',
40 'md5': 'af3a3a4aa43ff0ce6a89504c67f427ef',
42 'id': 'a4b83e34-123d-4b81-9f4e-c0d3121a4e05',
44 'title': 'Manfred Schreiber ist tot',
45 'description': 'md5:b454d867f2a9fc524ebe88c3f5092d97',
48 'skip': '404 not found',
51 'url': 'https://www.br-klassik.de/audio/peeping-tom-premierenkritik-dance-festival-muenchen-100.html',
52 'md5': '8b5b27c0b090f3b35eac4ab3f7a73d3d',
54 'id': '74c603c9-26d3-48bb-b85b-079aeed66e0b',
56 'title': 'Kurzweilig und sehr bewegend',
57 'description': 'md5:0351996e3283d64adeb38ede91fac54e',
60 'skip': '404 not found',
63 'url': 'http://www.br.de/radio/bayern1/service/team/videos/team-video-erdelt100.html',
64 'md5': 'dbab0aef2e047060ea7a21fc1ce1078a',
66 'id': '6ba73750-d405-45d3-861d-1ce8c524e059',
68 'title': 'Umweltbewusster Häuslebauer',
69 'description': 'md5:d52dae9792d00226348c1dbb13c9bae2',
74 'url': 'http://www.br.de/fernsehen/br-alpha/sendungen/kant-fuer-anfaenger/kritik-der-reinen-vernunft/kant-kritik-01-metaphysik100.html',
75 'md5': '23bca295f1650d698f94fc570977dae3',
77 'id': 'd982c9ce-8648-4753-b358-98abb8aec43d',
79 'title': 'Folge 1 - Metaphysik',
80 'description': 'md5:bb659990e9e59905c3d41e369db1fbe3',
82 'uploader': 'Eva Maria Steimle',
83 'upload_date': '20170208',
88 def _real_extract(self
, url
):
89 base_url
, display_id
= re
.search(self
._VALID
_URL
, url
).groups()
90 page
= self
._download
_webpage
(url
, display_id
)
91 xml_url
= self
._search
_regex
(
92 r
"return BRavFramework\.register\(BRavFramework\('avPlayer_(?:[a-f0-9-]{36})'\)\.setup\({dataURL:'(/(?:[a-z0-9\-]+/)+[a-z0-9/~_.-]+)'}\)\);", page
, 'XMLURL')
93 xml
= self
._download
_xml
(base_url
+ xml_url
, display_id
)
97 for xml_media
in xml
.findall('video') + xml
.findall('audio'):
98 media_id
= xml_media
.get('externalId')
101 'title': xpath_text(xml_media
, 'title', 'title', True),
102 'duration': parse_duration(xpath_text(xml_media
, 'duration')),
103 'formats': self
._extract
_formats
(xpath_element(
104 xml_media
, 'assets'), media_id
),
105 'thumbnails': self
._extract
_thumbnails
(xpath_element(
106 xml_media
, 'teaserImage/variants'), base_url
),
107 'description': xpath_text(xml_media
, 'desc'),
108 'webpage_url': xpath_text(xml_media
, 'permalink'),
109 'uploader': xpath_text(xml_media
, 'author'),
111 broadcast_date
= xpath_text(xml_media
, 'broadcastDate')
113 media
['upload_date'] = ''.join(reversed(broadcast_date
.split('.')))
117 self
._downloader
.report_warning(
118 'found multiple medias; please '
119 'report this with the video URL to http://yt-dl.org/bug')
121 raise ExtractorError('No media entries found')
124 def _extract_formats(self
, assets
, media_id
):
126 for asset
in assets
.findall('asset'):
127 format_url
= xpath_text(asset
, ['downloadUrl', 'url'])
128 asset_type
= asset
.get('type')
129 if asset_type
.startswith('HDS'):
130 formats
.extend(self
._extract
_f
4m
_formats
(
131 format_url
+ '?hdcore=3.2.0', media_id
, f4m_id
='hds', fatal
=False))
132 elif asset_type
.startswith('HLS'):
133 formats
.extend(self
._extract
_m
3u8_formats
(
134 format_url
, media_id
, 'mp4', 'm3u8_native', m3u8_id
='hds', fatal
=False))
137 'ext': xpath_text(asset
, 'mediaType'),
138 'width': int_or_none(xpath_text(asset
, 'frameWidth')),
139 'height': int_or_none(xpath_text(asset
, 'frameHeight')),
140 'tbr': int_or_none(xpath_text(asset
, 'bitrateVideo')),
141 'abr': int_or_none(xpath_text(asset
, 'bitrateAudio')),
142 'vcodec': xpath_text(asset
, 'codecVideo'),
143 'acodec': xpath_text(asset
, 'codecAudio'),
144 'container': xpath_text(asset
, 'mediaType'),
145 'filesize': int_or_none(xpath_text(asset
, 'size')),
147 format_url
= self
._proto
_relative
_url
(format_url
)
149 http_format_info
= format_info
.copy()
150 http_format_info
.update({
152 'format_id': 'http-%s' % asset_type
,
154 formats
.append(http_format_info
)
155 server_prefix
= xpath_text(asset
, 'serverPrefix')
157 rtmp_format_info
= format_info
.copy()
158 rtmp_format_info
.update({
159 'url': server_prefix
,
160 'play_path': xpath_text(asset
, 'fileName'),
161 'format_id': 'rtmp-%s' % asset_type
,
163 formats
.append(rtmp_format_info
)
164 self
._sort
_formats
(formats
)
167 def _extract_thumbnails(self
, variants
, base_url
):
169 'url': base_url
+ xpath_text(variant
, 'url'),
170 'width': int_or_none(xpath_text(variant
, 'width')),
171 'height': int_or_none(xpath_text(variant
, 'height')),
172 } for variant
in variants
.findall('variant') if xpath_text(variant
, 'url')]
173 thumbnails
.sort(key
=lambda x
: x
['width'] * x
['height'], reverse
=True)
177 class BRMediathekIE(InfoExtractor
):
178 IE_DESC
= 'Bayerischer Rundfunk Mediathek'
179 _VALID_URL
= r
'https?://(?:www\.)?br\.de/mediathek/video/[^/?&#]*?-(?P<id>av:[0-9a-f]{24})'
182 'url': 'https://www.br.de/mediathek/video/gesundheit-die-sendung-vom-28112017-av:5a1e6a6e8fce6d001871cc8e',
183 'md5': 'fdc3d485835966d1622587d08ba632ec',
185 'id': 'av:5a1e6a6e8fce6d001871cc8e',
187 'title': 'Die Sendung vom 28.11.2017',
188 'description': 'md5:6000cdca5912ab2277e5b7339f201ccc',
189 'timestamp': 1511942766,
190 'upload_date': '20171129',
194 def _real_extract(self
, url
):
195 clip_id
= self
._match
_id
(url
)
197 clip
= self
._download
_json
(
198 'https://proxy-base.master.mango.express/graphql',
199 clip_id
, data
=json
.dumps({
246 }""" % clip_id
}).encode(), headers
={
247 'Content-Type': 'application/json',
248 })['data']['viewer']['clip']
249 title
= clip
['title']
252 for edge
in clip
.get('videoFiles', {}).get('edges', []):
253 node
= edge
.get('node', {})
254 n_url
= node
.get('publicLocation')
257 ext
= determine_ext(n_url
)
259 formats
.extend(self
._extract
_m
3u8_formats
(
260 n_url
, clip_id
, 'mp4', 'm3u8_native',
261 m3u8_id
='hls', fatal
=False))
263 video_profile
= node
.get('videoProfile', {})
264 tbr
= int_or_none(video_profile
.get('bitrate'))
267 format_id
+= '-%d' % tbr
269 'format_id': format_id
,
271 'width': int_or_none(video_profile
.get('width')),
272 'height': int_or_none(video_profile
.get('height')),
274 'filesize': int_or_none(node
.get('fileSize')),
276 self
._sort
_formats
(formats
)
279 for edge
in clip
.get('captionFiles', {}).get('edges', []):
280 node
= edge
.get('node', {})
281 n_url
= node
.get('publicLocation')
284 subtitles
.setdefault('de', []).append({
289 for edge
in clip
.get('teaserImages', {}).get('edges', []):
290 for image_edge
in edge
.get('node', {}).get('imageFiles', {}).get('edges', []):
291 node
= image_edge
.get('node', {})
292 n_url
= node
.get('publicLocation')
297 'width': int_or_none(node
.get('width')),
298 'height': int_or_none(node
.get('height')),
304 'description': clip
.get('description'),
305 'duration': int_or_none(clip
.get('duration')),
306 'timestamp': parse_iso8601(clip
.get('createdAt')),
307 'age_limit': int_or_none(clip
.get('ageRestriction')),
309 'subtitles': subtitles
,
310 'thumbnails': thumbnails
,