bloomberg.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import re
  2. from .common import InfoExtractor
  3. class BloombergIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?bloomberg\.com/(?:[^/]+/)*(?P<id>[^/?#]+)'
  5. _TESTS = [{
  6. 'url': 'https://www.bloomberg.com/news/videos/2021-09-14/apple-unveils-the-new-iphone-13-stock-doesn-t-move-much-video',
  7. 'info_dict': {
  8. 'id': 'V8cFcYMxTHaMcEiiYVr39A',
  9. 'ext': 'flv',
  10. 'title': 'Apple Unveils the New IPhone 13, Stock Doesn\'t Move Much',
  11. },
  12. 'params': {
  13. 'format': 'best[format_id^=hds]',
  14. },
  15. }, {
  16. # video ID in BPlayer(...)
  17. 'url': 'http://www.bloomberg.com/features/2016-hello-world-new-zealand/',
  18. 'info_dict': {
  19. 'id': '938c7e72-3f25-4ddb-8b85-a9be731baa74',
  20. 'ext': 'flv',
  21. 'title': 'Meet the Real-Life Tech Wizards of Middle Earth',
  22. 'description': 'Hello World, Episode 1: New Zealand’s freaky AI babies, robot exoskeletons, and a virtual you.',
  23. },
  24. 'params': {
  25. 'format': 'best[format_id^=hds]',
  26. },
  27. }, {
  28. # data-bmmrid=
  29. 'url': 'https://www.bloomberg.com/politics/articles/2017-02-08/le-pen-aide-briefed-french-central-banker-on-plan-to-print-money',
  30. 'only_matching': True,
  31. }, {
  32. 'url': 'http://www.bloomberg.com/news/articles/2015-11-12/five-strange-things-that-have-been-happening-in-financial-markets',
  33. 'only_matching': True,
  34. }, {
  35. 'url': 'http://www.bloomberg.com/politics/videos/2015-11-25/karl-rove-on-jeb-bush-s-struggles-stopping-trump',
  36. 'only_matching': True,
  37. }]
  38. def _real_extract(self, url):
  39. name = self._match_id(url)
  40. webpage = self._download_webpage(url, name)
  41. video_id = self._search_regex(
  42. (r'["\']bmmrId["\']\s*:\s*(["\'])(?P<id>(?:(?!\1).)+)\1',
  43. r'videoId\s*:\s*(["\'])(?P<id>(?:(?!\1).)+)\1',
  44. r'data-bmmrid=(["\'])(?P<id>(?:(?!\1).)+)\1'),
  45. webpage, 'id', group='id', default=None)
  46. if not video_id:
  47. bplayer_data = self._parse_json(self._search_regex(
  48. r'BPlayer\(null,\s*({[^;]+})\);', webpage, 'id'), name)
  49. video_id = bplayer_data['id']
  50. title = re.sub(': Video$', '', self._og_search_title(webpage))
  51. embed_info = self._download_json(
  52. f'http://www.bloomberg.com/multimedia/api/embed?id={video_id}', video_id)
  53. formats = []
  54. for stream in embed_info['streams']:
  55. stream_url = stream.get('url')
  56. if not stream_url:
  57. continue
  58. if stream['muxing_format'] == 'TS':
  59. formats.extend(self._extract_m3u8_formats(
  60. stream_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  61. else:
  62. formats.extend(self._extract_f4m_formats(
  63. stream_url, video_id, f4m_id='hds', fatal=False))
  64. return {
  65. 'id': video_id,
  66. 'title': title,
  67. 'formats': formats,
  68. 'description': self._og_search_description(webpage),
  69. 'thumbnail': self._og_search_thumbnail(webpage),
  70. }