]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/bloomberg.py
[spotify] Detect iframe embeds (#3430)
[yt-dlp.git] / yt_dlp / extractor / bloomberg.py
1 import re
2
3 from .common import InfoExtractor
4
5
6 class BloombergIE(InfoExtractor):
7 _VALID_URL = r'https?://(?:www\.)?bloomberg\.com/(?:[^/]+/)*(?P<id>[^/?#]+)'
8
9 _TESTS = [{
10 'url': 'http://www.bloomberg.com/news/videos/b/aaeae121-5949-481e-a1ce-4562db6f5df2',
11 # The md5 checksum changes
12 'info_dict': {
13 'id': 'qurhIVlJSB6hzkVi229d8g',
14 'ext': 'flv',
15 'title': 'Shah\'s Presentation on Foreign-Exchange Strategies',
16 'description': 'md5:a8ba0302912d03d246979735c17d2761',
17 },
18 'params': {
19 'format': 'best[format_id^=hds]',
20 },
21 }, {
22 # video ID in BPlayer(...)
23 'url': 'http://www.bloomberg.com/features/2016-hello-world-new-zealand/',
24 'info_dict': {
25 'id': '938c7e72-3f25-4ddb-8b85-a9be731baa74',
26 'ext': 'flv',
27 'title': 'Meet the Real-Life Tech Wizards of Middle Earth',
28 'description': 'Hello World, Episode 1: New Zealand’s freaky AI babies, robot exoskeletons, and a virtual you.',
29 },
30 'params': {
31 'format': 'best[format_id^=hds]',
32 },
33 }, {
34 # data-bmmrid=
35 'url': 'https://www.bloomberg.com/politics/articles/2017-02-08/le-pen-aide-briefed-french-central-banker-on-plan-to-print-money',
36 'only_matching': True,
37 }, {
38 'url': 'http://www.bloomberg.com/news/articles/2015-11-12/five-strange-things-that-have-been-happening-in-financial-markets',
39 'only_matching': True,
40 }, {
41 'url': 'http://www.bloomberg.com/politics/videos/2015-11-25/karl-rove-on-jeb-bush-s-struggles-stopping-trump',
42 'only_matching': True,
43 }]
44
45 def _real_extract(self, url):
46 name = self._match_id(url)
47 webpage = self._download_webpage(url, name)
48 video_id = self._search_regex(
49 (r'["\']bmmrId["\']\s*:\s*(["\'])(?P<id>(?:(?!\1).)+)\1',
50 r'videoId\s*:\s*(["\'])(?P<id>(?:(?!\1).)+)\1',
51 r'data-bmmrid=(["\'])(?P<id>(?:(?!\1).)+)\1'),
52 webpage, 'id', group='id', default=None)
53 if not video_id:
54 bplayer_data = self._parse_json(self._search_regex(
55 r'BPlayer\(null,\s*({[^;]+})\);', webpage, 'id'), name)
56 video_id = bplayer_data['id']
57 title = re.sub(': Video$', '', self._og_search_title(webpage))
58
59 embed_info = self._download_json(
60 'http://www.bloomberg.com/api/embed?id=%s' % video_id, video_id)
61 formats = []
62 for stream in embed_info['streams']:
63 stream_url = stream.get('url')
64 if not stream_url:
65 continue
66 if stream['muxing_format'] == 'TS':
67 formats.extend(self._extract_m3u8_formats(
68 stream_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
69 else:
70 formats.extend(self._extract_f4m_formats(
71 stream_url, video_id, f4m_id='hds', fatal=False))
72 self._sort_formats(formats)
73
74 return {
75 'id': video_id,
76 'title': title,
77 'formats': formats,
78 'description': self._og_search_description(webpage),
79 'thumbnail': self._og_search_thumbnail(webpage),
80 }