cbsnews.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. from .theplatform import ThePlatformIE
  6. from ..utils import remove_start
  7. class CBSNewsIE(ThePlatformIE):
  8. IE_DESC = 'CBS News'
  9. _VALID_URL = r'http://(?:www\.)?cbsnews\.com/(?:[^/]+/)+(?P<id>[\da-z_-]+)'
  10. _TESTS = [
  11. {
  12. 'url': 'http://www.cbsnews.com/news/tesla-and-spacex-elon-musks-industrial-empire/',
  13. 'info_dict': {
  14. 'id': 'tesla-and-spacex-elon-musks-industrial-empire',
  15. 'ext': 'flv',
  16. 'title': 'Tesla and SpaceX: Elon Musk\'s industrial empire',
  17. 'thumbnail': 'http://beta.img.cbsnews.com/i/2014/03/30/60147937-2f53-4565-ad64-1bdd6eb64679/60-0330-pelley-640x360.jpg',
  18. 'duration': 791,
  19. },
  20. 'params': {
  21. # rtmp download
  22. 'skip_download': True,
  23. },
  24. },
  25. {
  26. 'url': 'http://www.cbsnews.com/videos/fort-hood-shooting-army-downplays-mental-illness-as-cause-of-attack/',
  27. 'info_dict': {
  28. 'id': 'fort-hood-shooting-army-downplays-mental-illness-as-cause-of-attack',
  29. 'ext': 'mp4',
  30. 'title': 'Fort Hood shooting: Army downplays mental illness as cause of attack',
  31. 'thumbnail': 're:^https?://.*\.jpg$',
  32. 'duration': 205,
  33. 'subtitles': {
  34. 'en': [{
  35. 'ext': 'ttml',
  36. }],
  37. },
  38. },
  39. 'params': {
  40. # m3u8 download
  41. 'skip_download': True,
  42. },
  43. },
  44. ]
  45. def _real_extract(self, url):
  46. mobj = re.match(self._VALID_URL, url)
  47. video_id = mobj.group('id')
  48. webpage = self._download_webpage(url, video_id)
  49. video_info = json.loads(self._html_search_regex(
  50. r'(?:<ul class="media-list items" id="media-related-items"><li data-video-info|<div id="cbsNewsVideoPlayer" data-video-player-options)=\'({.+?})\'',
  51. webpage, 'video JSON info'))
  52. item = video_info['item'] if 'item' in video_info else video_info
  53. title = item.get('articleTitle') or item.get('hed')
  54. duration = item.get('duration')
  55. thumbnail = item.get('mediaImage') or item.get('thumbnail')
  56. subtitles = {}
  57. if 'mpxRefId' in video_info:
  58. subtitles['en'] = [{
  59. 'ext': 'ttml',
  60. 'url': 'http://www.cbsnews.com/videos/captions/%s.adb_xml' % video_info['mpxRefId'],
  61. }]
  62. formats = []
  63. for format_id in ['RtmpMobileLow', 'RtmpMobileHigh', 'Hls', 'RtmpDesktop']:
  64. pid = item.get('media' + format_id)
  65. if not pid:
  66. continue
  67. release_url = 'http://link.theplatform.com/s/dJ5BDC/%s?format=SMIL&mbr=true' % pid
  68. tp_formats, tp_subtitles = self._extract_theplatform_smil(release_url, video_id, 'Downloading %s SMIL data' % pid)
  69. formats.extend(tp_formats)
  70. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  71. self._sort_formats(formats)
  72. return {
  73. 'id': video_id,
  74. 'title': title,
  75. 'thumbnail': thumbnail,
  76. 'duration': duration,
  77. 'formats': formats,
  78. 'subtitles': subtitles,
  79. }