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.

144 lines
6.3 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from .turner import TurnerBaseIE
  5. from ..utils import url_basename
  6. class CNNIE(TurnerBaseIE):
  7. _VALID_URL = r'''(?x)https?://(?:(?P<sub_domain>edition|www|money)\.)?cnn\.com/(?:video/(?:data/.+?|\?)/)?videos?/
  8. (?P<path>.+?/(?P<title>[^/]+?)(?:\.(?:[a-z\-]+)|(?=&)))'''
  9. _TESTS = [{
  10. 'url': 'http://edition.cnn.com/video/?/video/sports/2013/06/09/nadal-1-on-1.cnn',
  11. 'md5': '3e6121ea48df7e2259fe73a0628605c4',
  12. 'info_dict': {
  13. 'id': 'sports/2013/06/09/nadal-1-on-1.cnn',
  14. 'ext': 'mp4',
  15. 'title': 'Nadal wins 8th French Open title',
  16. 'description': 'World Sport\'s Amanda Davies chats with 2013 French Open champion Rafael Nadal.',
  17. 'duration': 135,
  18. 'upload_date': '20130609',
  19. },
  20. 'expected_warnings': ['Failed to download m3u8 information'],
  21. }, {
  22. 'url': 'http://edition.cnn.com/video/?/video/us/2013/08/21/sot-student-gives-epic-speech.georgia-institute-of-technology&utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+rss%2Fcnn_topstories+%28RSS%3A+Top+Stories%29',
  23. 'md5': 'b5cc60c60a3477d185af8f19a2a26f4e',
  24. 'info_dict': {
  25. 'id': 'us/2013/08/21/sot-student-gives-epic-speech.georgia-institute-of-technology',
  26. 'ext': 'mp4',
  27. 'title': "Student's epic speech stuns new freshmen",
  28. 'description': "A Georgia Tech student welcomes the incoming freshmen with an epic speech backed by music from \"2001: A Space Odyssey.\"",
  29. 'upload_date': '20130821',
  30. },
  31. 'expected_warnings': ['Failed to download m3u8 information'],
  32. }, {
  33. 'url': 'http://www.cnn.com/video/data/2.0/video/living/2014/12/22/growing-america-nashville-salemtown-board-episode-1.hln.html',
  34. 'md5': 'f14d02ebd264df951feb2400e2c25a1b',
  35. 'info_dict': {
  36. 'id': 'living/2014/12/22/growing-america-nashville-salemtown-board-episode-1.hln',
  37. 'ext': 'mp4',
  38. 'title': 'Nashville Ep. 1: Hand crafted skateboards',
  39. 'description': 'md5:e7223a503315c9f150acac52e76de086',
  40. 'upload_date': '20141222',
  41. },
  42. 'expected_warnings': ['Failed to download m3u8 information'],
  43. }, {
  44. 'url': 'http://money.cnn.com/video/news/2016/08/19/netflix-stunning-stats.cnnmoney/index.html',
  45. 'md5': '52a515dc1b0f001cd82e4ceda32be9d1',
  46. 'info_dict': {
  47. 'id': '/video/news/2016/08/19/netflix-stunning-stats.cnnmoney',
  48. 'ext': 'mp4',
  49. 'title': '5 stunning stats about Netflix',
  50. 'description': 'Did you know that Netflix has more than 80 million members? Here are five facts about the online video distributor that you probably didn\'t know.',
  51. 'upload_date': '20160819',
  52. },
  53. 'params': {
  54. # m3u8 download
  55. 'skip_download': True,
  56. },
  57. }, {
  58. 'url': 'http://cnn.com/video/?/video/politics/2015/03/27/pkg-arizona-senator-church-attendance-mandatory.ktvk',
  59. 'only_matching': True,
  60. }, {
  61. 'url': 'http://cnn.com/video/?/video/us/2015/04/06/dnt-baker-refuses-anti-gay-order.wkmg',
  62. 'only_matching': True,
  63. }, {
  64. 'url': 'http://edition.cnn.com/videos/arts/2016/04/21/olympic-games-cultural-a-z-brazil.cnn',
  65. 'only_matching': True,
  66. }]
  67. _CONFIG = {
  68. # http://edition.cnn.com/.element/apps/cvp/3.0/cfg/spider/cnn/expansion/config.xml
  69. 'edition': {
  70. 'data_src': 'http://edition.cnn.com/video/data/3.0/video/%s/index.xml',
  71. 'media_src': 'http://pmd.cdn.turner.com/cnn/big',
  72. },
  73. # http://money.cnn.com/.element/apps/cvp2/cfg/config.xml
  74. 'money': {
  75. 'data_src': 'http://money.cnn.com/video/data/4.0/video/%s.xml',
  76. 'media_src': 'http://ht3.cdn.turner.com/money/big',
  77. },
  78. }
  79. def _extract_timestamp(self, video_data):
  80. # TODO: fix timestamp extraction
  81. return None
  82. def _real_extract(self, url):
  83. sub_domain, path, page_title = re.match(self._VALID_URL, url).groups()
  84. if sub_domain not in ('money', 'edition'):
  85. sub_domain = 'edition'
  86. config = self._CONFIG[sub_domain]
  87. return self._extract_cvp_info(
  88. config['data_src'] % path, page_title, {
  89. 'default': {
  90. 'media_src': config['media_src'],
  91. }
  92. })
  93. class CNNBlogsIE(InfoExtractor):
  94. _VALID_URL = r'https?://[^\.]+\.blogs\.cnn\.com/.+'
  95. _TEST = {
  96. 'url': 'http://reliablesources.blogs.cnn.com/2014/02/09/criminalizing-journalism/',
  97. 'md5': '3e56f97b0b6ffb4b79f4ea0749551084',
  98. 'info_dict': {
  99. 'id': 'bestoftv/2014/02/09/criminalizing-journalism.cnn',
  100. 'ext': 'mp4',
  101. 'title': 'Criminalizing journalism?',
  102. 'description': 'Glenn Greenwald responds to comments made this week on Capitol Hill that journalists could be criminal accessories.',
  103. 'upload_date': '20140209',
  104. },
  105. 'expected_warnings': ['Failed to download m3u8 information'],
  106. 'add_ie': ['CNN'],
  107. }
  108. def _real_extract(self, url):
  109. webpage = self._download_webpage(url, url_basename(url))
  110. cnn_url = self._html_search_regex(r'data-url="(.+?)"', webpage, 'cnn url')
  111. return self.url_result(cnn_url, CNNIE.ie_key())
  112. class CNNArticleIE(InfoExtractor):
  113. _VALID_URL = r'https?://(?:(?:edition|www)\.)?cnn\.com/(?!videos?/)'
  114. _TEST = {
  115. 'url': 'http://www.cnn.com/2014/12/21/politics/obama-north-koreas-hack-not-war-but-cyber-vandalism/',
  116. 'md5': '689034c2a3d9c6dc4aa72d65a81efd01',
  117. 'info_dict': {
  118. 'id': 'bestoftv/2014/12/21/ip-north-korea-obama.cnn',
  119. 'ext': 'mp4',
  120. 'title': 'Obama: Cyberattack not an act of war',
  121. 'description': 'md5:0a802a40d2376f60e6b04c8d5bcebc4b',
  122. 'upload_date': '20141221',
  123. },
  124. 'expected_warnings': ['Failed to download m3u8 information'],
  125. 'add_ie': ['CNN'],
  126. }
  127. def _real_extract(self, url):
  128. webpage = self._download_webpage(url, url_basename(url))
  129. cnn_url = self._html_search_regex(r"video:\s*'([^']+)'", webpage, 'cnn url')
  130. return self.url_result('http://cnn.com/video/?/video/' + cnn_url, CNNIE.ie_key())