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.

94 lines
3.4 KiB

10 years ago
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. from .common import InfoExtractor
  6. from ..utils import remove_start
  7. class CBSNewsIE(InfoExtractor):
  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': 'flv',
  30. 'title': 'Fort Hood shooting: Army downplays mental illness as cause of attack',
  31. 'thumbnail': 're:^https?://.*\.jpg$',
  32. 'duration': 205,
  33. },
  34. 'params': {
  35. # rtmp download
  36. 'skip_download': True,
  37. },
  38. },
  39. ]
  40. def _real_extract(self, url):
  41. mobj = re.match(self._VALID_URL, url)
  42. video_id = mobj.group('id')
  43. webpage = self._download_webpage(url, video_id)
  44. video_info = json.loads(self._html_search_regex(
  45. r'(?:<ul class="media-list items" id="media-related-items"><li data-video-info|<div id="cbsNewsVideoPlayer" data-video-player-options)=\'({.+?})\'',
  46. webpage, 'video JSON info'))
  47. item = video_info['item'] if 'item' in video_info else video_info
  48. title = item.get('articleTitle') or item.get('hed')
  49. duration = item.get('duration')
  50. thumbnail = item.get('mediaImage') or item.get('thumbnail')
  51. formats = []
  52. for format_id in ['RtmpMobileLow', 'RtmpMobileHigh', 'Hls', 'RtmpDesktop']:
  53. uri = item.get('media' + format_id + 'URI')
  54. if not uri:
  55. continue
  56. uri = remove_start(uri, '{manifest:none}')
  57. fmt = {
  58. 'url': uri,
  59. 'format_id': format_id,
  60. }
  61. if uri.startswith('rtmp'):
  62. play_path = re.sub(
  63. r'{slistFilePath}', '',
  64. uri.split('<break>')[-1].split('{break}')[-1])
  65. play_path = re.sub(
  66. r'{manifest:.+}.*$', '', play_path)
  67. fmt.update({
  68. 'app': 'ondemand?auth=cbs',
  69. 'play_path': 'mp4:' + play_path,
  70. 'player_url': 'http://www.cbsnews.com/[[IMPORT]]/vidtech.cbsinteractive.com/player/3_3_0/CBSI_PLAYER_HD.swf',
  71. 'page_url': 'http://www.cbsnews.com',
  72. 'ext': 'flv',
  73. })
  74. elif uri.endswith('.m3u8'):
  75. fmt['ext'] = 'mp4'
  76. formats.append(fmt)
  77. return {
  78. 'id': video_id,
  79. 'title': title,
  80. 'thumbnail': thumbnail,
  81. 'duration': duration,
  82. 'formats': formats,
  83. }