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.

57 lines
2.1 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. }, {
  16. 'url': 'http://www.bloomberg.com/news/articles/2015-11-12/five-strange-things-that-have-been-happening-in-financial-markets',
  17. 'only_matching': True,
  18. }, {
  19. 'url': 'http://www.bloomberg.com/politics/videos/2015-11-25/karl-rove-on-jeb-bush-s-struggles-stopping-trump',
  20. 'only_matching': True,
  21. }]
  22. def _real_extract(self, url):
  23. name = self._match_id(url)
  24. webpage = self._download_webpage(url, name)
  25. video_id = self._search_regex(
  26. r'["\']bmmrId["\']\s*:\s*(["\'])(?P<url>.+?)\1',
  27. webpage, 'id', group='url')
  28. title = re.sub(': Video$', '', self._og_search_title(webpage))
  29. embed_info = self._download_json(
  30. 'http://www.bloomberg.com/api/embed?id=%s' % video_id, video_id)
  31. formats = []
  32. for stream in embed_info['streams']:
  33. stream_url = stream.get('url')
  34. if not stream_url:
  35. continue
  36. if stream['muxing_format'] == 'TS':
  37. formats.extend(self._extract_m3u8_formats(
  38. stream_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  39. else:
  40. formats.extend(self._extract_f4m_formats(
  41. stream_url, video_id, f4m_id='hds', fatal=False))
  42. self._sort_formats(formats)
  43. return {
  44. 'id': video_id,
  45. 'title': title,
  46. 'formats': formats,
  47. 'description': self._og_search_description(webpage),
  48. 'thumbnail': self._og_search_thumbnail(webpage),
  49. }