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.

87 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 .common import InfoExtractor
  6. class CBSNewsIE(InfoExtractor):
  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': 'flv',
  29. 'title': 'Fort Hood shooting: Army downplays mental illness as cause of attack',
  30. 'thumbnail': 'http://cbsnews2.cbsistatic.com/hub/i/r/2014/04/04/0c9fbc66-576b-41ca-8069-02d122060dd2/thumbnail/140x90/6dad7a502f88875ceac38202984b6d58/en-0404-werner-replace-640x360.jpg',
  31. 'duration': 205,
  32. },
  33. 'params': {
  34. # rtmp download
  35. 'skip_download': True,
  36. },
  37. },
  38. ]
  39. def _real_extract(self, url):
  40. mobj = re.match(self._VALID_URL, url)
  41. video_id = mobj.group('id')
  42. webpage = self._download_webpage(url, video_id)
  43. video_info = json.loads(self._html_search_regex(
  44. r'(?:<ul class="media-list items" id="media-related-items"><li data-video-info|<div id="cbsNewsVideoPlayer" data-video-player-options)=\'({.+?})\'',
  45. webpage, 'video JSON info'))
  46. item = video_info['item'] if 'item' in video_info else video_info
  47. title = item.get('articleTitle') or item.get('hed')
  48. duration = item.get('duration')
  49. thumbnail = item.get('mediaImage') or item.get('thumbnail')
  50. formats = []
  51. for format_id in ['RtmpMobileLow', 'RtmpMobileHigh', 'Hls', 'RtmpDesktop']:
  52. uri = item.get('media' + format_id + 'URI')
  53. if not uri:
  54. continue
  55. fmt = {
  56. 'url': uri,
  57. 'format_id': format_id,
  58. }
  59. if uri.startswith('rtmp'):
  60. fmt.update({
  61. 'app': 'ondemand?auth=cbs',
  62. 'play_path': 'mp4:' + uri.split('<break>')[-1],
  63. 'player_url': 'http://www.cbsnews.com/[[IMPORT]]/vidtech.cbsinteractive.com/player/3_3_0/CBSI_PLAYER_HD.swf',
  64. 'page_url': 'http://www.cbsnews.com',
  65. 'ext': 'flv',
  66. })
  67. elif uri.endswith('.m3u8'):
  68. fmt['ext'] = 'mp4'
  69. formats.append(fmt)
  70. return {
  71. 'id': video_id,
  72. 'title': title,
  73. 'thumbnail': thumbnail,
  74. 'duration': duration,
  75. 'formats': formats,
  76. }