You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class BloombergIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?bloomberg\.com/(?:[^/]+/)*(?P<id>[^/?#]+)'
  7. _TESTS = [{
  8. 'url': 'http://www.bloomberg.com/news/videos/b/aaeae121-5949-481e-a1ce-4562db6f5df2',
  9. # The md5 checksum changes
  10. 'info_dict': {
  11. 'id': 'qurhIVlJSB6hzkVi229d8g',
  12. 'ext': 'flv',
  13. 'title': 'Shah\'s Presentation on Foreign-Exchange Strategies',
  14. 'description': 'md5:a8ba0302912d03d246979735c17d2761',
  15. },
  16. 'params': {
  17. 'format': 'best[format_id^=hds]',
  18. },
  19. }, {
  20. # video ID in BPlayer(...)
  21. 'url': 'http://www.bloomberg.com/features/2016-hello-world-new-zealand/',
  22. 'info_dict': {
  23. 'id': '938c7e72-3f25-4ddb-8b85-a9be731baa74',
  24. 'ext': 'flv',
  25. 'title': 'Meet the Real-Life Tech Wizards of Middle Earth',
  26. 'description': 'Hello World, Episode 1: New Zealand’s freaky AI babies, robot exoskeletons, and a virtual you.',
  27. },
  28. 'params': {
  29. 'format': 'best[format_id^=hds]',
  30. },
  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<url>.+?)\1',
  43. webpage, 'id', group='url', default=None)
  44. if not video_id:
  45. bplayer_data = self._parse_json(self._search_regex(
  46. r'BPlayer\(null,\s*({[^;]+})\);', webpage, 'id'), name)
  47. video_id = bplayer_data['id']
  48. title = re.sub(': Video$', '', self._og_search_title(webpage))
  49. embed_info = self._download_json(
  50. 'http://www.bloomberg.com/api/embed?id=%s' % video_id, video_id)
  51. formats = []
  52. for stream in embed_info['streams']:
  53. stream_url = stream.get('url')
  54. if not stream_url:
  55. continue
  56. if stream['muxing_format'] == 'TS':
  57. formats.extend(self._extract_m3u8_formats(
  58. stream_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  59. else:
  60. formats.extend(self._extract_f4m_formats(
  61. stream_url, video_id, f4m_id='hds', fatal=False))
  62. self._sort_formats(formats)
  63. return {
  64. 'id': video_id,
  65. 'title': title,
  66. 'formats': formats,
  67. 'description': self._og_search_description(webpage),
  68. 'thumbnail': self._og_search_thumbnail(webpage),
  69. }