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.

60 lines
2.2 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. class BloombergIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:www\.)?bloomberg\.com/(?:[^/]+/)*(?P<id>[^/?#]+)'
  6. _TESTS = [{
  7. 'url': 'http://www.bloomberg.com/news/videos/b/aaeae121-5949-481e-a1ce-4562db6f5df2',
  8. # The md5 checksum changes
  9. 'info_dict': {
  10. 'id': 'qurhIVlJSB6hzkVi229d8g',
  11. 'ext': 'flv',
  12. 'title': 'Shah\'s Presentation on Foreign-Exchange Strategies',
  13. 'description': 'md5:a8ba0302912d03d246979735c17d2761',
  14. },
  15. 'params': {
  16. 'format': 'best[format_id^=hds]',
  17. },
  18. }, {
  19. 'url': 'http://www.bloomberg.com/news/articles/2015-11-12/five-strange-things-that-have-been-happening-in-financial-markets',
  20. 'only_matching': True,
  21. }, {
  22. 'url': 'http://www.bloomberg.com/politics/videos/2015-11-25/karl-rove-on-jeb-bush-s-struggles-stopping-trump',
  23. 'only_matching': True,
  24. }]
  25. def _real_extract(self, url):
  26. name = self._match_id(url)
  27. webpage = self._download_webpage(url, name)
  28. video_id = self._search_regex(
  29. r'["\']bmmrId["\']\s*:\s*(["\'])(?P<url>.+?)\1',
  30. webpage, 'id', group='url')
  31. title = re.sub(': Video$', '', self._og_search_title(webpage))
  32. embed_info = self._download_json(
  33. 'http://www.bloomberg.com/api/embed?id=%s' % video_id, video_id)
  34. formats = []
  35. for stream in embed_info['streams']:
  36. stream_url = stream.get('url')
  37. if not stream_url:
  38. continue
  39. if stream['muxing_format'] == 'TS':
  40. formats.extend(self._extract_m3u8_formats(
  41. stream_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  42. else:
  43. formats.extend(self._extract_f4m_formats(
  44. stream_url, video_id, f4m_id='hds', fatal=False))
  45. self._sort_formats(formats)
  46. return {
  47. 'id': video_id,
  48. 'title': title,
  49. 'formats': formats,
  50. 'description': self._og_search_description(webpage),
  51. 'thumbnail': self._og_search_thumbnail(webpage),
  52. }