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