]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/bloomberg.py
debian/patches: Drop patch included in version 2017.02.07.
[youtubedl] / youtube_dl / extractor / bloomberg.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7
8
9 class BloombergIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?bloomberg\.com/(?:[^/]+/)*(?P<id>[^/?#]+)'
11
12 _TESTS = [{
13 'url': 'http://www.bloomberg.com/news/videos/b/aaeae121-5949-481e-a1ce-4562db6f5df2',
14 # The md5 checksum changes
15 'info_dict': {
16 'id': 'qurhIVlJSB6hzkVi229d8g',
17 'ext': 'flv',
18 'title': 'Shah\'s Presentation on Foreign-Exchange Strategies',
19 'description': 'md5:a8ba0302912d03d246979735c17d2761',
20 },
21 'params': {
22 'format': 'best[format_id^=hds]',
23 },
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 },
36 }, {
37 'url': 'http://www.bloomberg.com/news/articles/2015-11-12/five-strange-things-that-have-been-happening-in-financial-markets',
38 'only_matching': True,
39 }, {
40 'url': 'http://www.bloomberg.com/politics/videos/2015-11-25/karl-rove-on-jeb-bush-s-struggles-stopping-trump',
41 'only_matching': True,
42 }]
43
44 def _real_extract(self, url):
45 name = self._match_id(url)
46 webpage = self._download_webpage(url, name)
47 video_id = self._search_regex(
48 (r'["\']bmmrId["\']\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1',
49 r'videoId\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1'),
50 webpage, 'id', group='url', default=None)
51 if not video_id:
52 bplayer_data = self._parse_json(self._search_regex(
53 r'BPlayer\(null,\s*({[^;]+})\);', webpage, 'id'), name)
54 video_id = bplayer_data['id']
55 title = re.sub(': Video$', '', self._og_search_title(webpage))
56
57 embed_info = self._download_json(
58 'http://www.bloomberg.com/api/embed?id=%s' % video_id, video_id)
59 formats = []
60 for stream in embed_info['streams']:
61 stream_url = stream.get('url')
62 if not stream_url:
63 continue
64 if stream['muxing_format'] == 'TS':
65 formats.extend(self._extract_m3u8_formats(
66 stream_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
67 else:
68 formats.extend(self._extract_f4m_formats(
69 stream_url, video_id, f4m_id='hds', fatal=False))
70 self._sort_formats(formats)
71
72 return {
73 'id': video_id,
74 'title': title,
75 'formats': formats,
76 'description': self._og_search_description(webpage),
77 'thumbnail': self._og_search_thumbnail(webpage),
78 }