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.

90 lines
3.3 KiB

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