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.

170 lines
6.5 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. parse_duration,
  7. url_basename,
  8. )
  9. class CNNIE(InfoExtractor):
  10. _VALID_URL = r'''(?x)https?://(?:(?:edition|www)\.)?cnn\.com/video/(?:data/.+?|\?)/
  11. (?P<path>.+?/(?P<title>[^/]+?)(?:\.(?:[a-z\-]+)|(?=&)))'''
  12. _TESTS = [{
  13. 'url': 'http://edition.cnn.com/video/?/video/sports/2013/06/09/nadal-1-on-1.cnn',
  14. 'md5': '3e6121ea48df7e2259fe73a0628605c4',
  15. 'info_dict': {
  16. 'id': 'sports/2013/06/09/nadal-1-on-1.cnn',
  17. 'ext': 'mp4',
  18. 'title': 'Nadal wins 8th French Open title',
  19. 'description': 'World Sport\'s Amanda Davies chats with 2013 French Open champion Rafael Nadal.',
  20. 'duration': 135,
  21. 'upload_date': '20130609',
  22. },
  23. }, {
  24. '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',
  25. 'md5': 'b5cc60c60a3477d185af8f19a2a26f4e',
  26. 'info_dict': {
  27. 'id': 'us/2013/08/21/sot-student-gives-epic-speech.georgia-institute-of-technology',
  28. 'ext': 'mp4',
  29. 'title': "Student's epic speech stuns new freshmen",
  30. 'description': "A Georgia Tech student welcomes the incoming freshmen with an epic speech backed by music from \"2001: A Space Odyssey.\"",
  31. 'upload_date': '20130821',
  32. }
  33. }, {
  34. 'url': 'http://www.cnn.com/video/data/2.0/video/living/2014/12/22/growing-america-nashville-salemtown-board-episode-1.hln.html',
  35. 'md5': 'f14d02ebd264df951feb2400e2c25a1b',
  36. 'info_dict': {
  37. 'id': 'living/2014/12/22/growing-america-nashville-salemtown-board-episode-1.hln',
  38. 'ext': 'mp4',
  39. 'title': 'Nashville Ep. 1: Hand crafted skateboards',
  40. 'description': 'md5:e7223a503315c9f150acac52e76de086',
  41. 'upload_date': '20141222',
  42. }
  43. }, {
  44. 'url': 'http://cnn.com/video/?/video/politics/2015/03/27/pkg-arizona-senator-church-attendance-mandatory.ktvk',
  45. 'only_matching': True,
  46. }, {
  47. 'url': 'http://cnn.com/video/?/video/us/2015/04/06/dnt-baker-refuses-anti-gay-order.wkmg',
  48. 'only_matching': True,
  49. }]
  50. def _real_extract(self, url):
  51. mobj = re.match(self._VALID_URL, url)
  52. path = mobj.group('path')
  53. page_title = mobj.group('title')
  54. info_url = 'http://edition.cnn.com/video/data/3.0/%s/index.xml' % path
  55. info = self._download_xml(info_url, page_title)
  56. formats = []
  57. rex = re.compile(r'''(?x)
  58. (?P<width>[0-9]+)x(?P<height>[0-9]+)
  59. (?:_(?P<bitrate>[0-9]+)k)?
  60. ''')
  61. for f in info.findall('files/file'):
  62. video_url = 'http://ht.cdn.turner.com/cnn/big%s' % (f.text.strip())
  63. fdct = {
  64. 'format_id': f.attrib['bitrate'],
  65. 'url': video_url,
  66. }
  67. mf = rex.match(f.attrib['bitrate'])
  68. if mf:
  69. fdct['width'] = int(mf.group('width'))
  70. fdct['height'] = int(mf.group('height'))
  71. fdct['tbr'] = int_or_none(mf.group('bitrate'))
  72. else:
  73. mf = rex.search(f.text)
  74. if mf:
  75. fdct['width'] = int(mf.group('width'))
  76. fdct['height'] = int(mf.group('height'))
  77. fdct['tbr'] = int_or_none(mf.group('bitrate'))
  78. else:
  79. mi = re.match(r'ios_(audio|[0-9]+)$', f.attrib['bitrate'])
  80. if mi:
  81. if mi.group(1) == 'audio':
  82. fdct['vcodec'] = 'none'
  83. fdct['ext'] = 'm4a'
  84. else:
  85. fdct['tbr'] = int(mi.group(1))
  86. formats.append(fdct)
  87. self._sort_formats(formats)
  88. thumbnails = [{
  89. 'height': int(t.attrib['height']),
  90. 'width': int(t.attrib['width']),
  91. 'url': t.text,
  92. } for t in info.findall('images/image')]
  93. metas_el = info.find('metas')
  94. upload_date = (
  95. metas_el.attrib.get('version') if metas_el is not None else None)
  96. duration_el = info.find('length')
  97. duration = parse_duration(duration_el.text)
  98. return {
  99. 'id': info.attrib['id'],
  100. 'title': info.find('headline').text,
  101. 'formats': formats,
  102. 'thumbnails': thumbnails,
  103. 'description': info.find('description').text,
  104. 'duration': duration,
  105. 'upload_date': upload_date,
  106. }
  107. class CNNBlogsIE(InfoExtractor):
  108. _VALID_URL = r'https?://[^\.]+\.blogs\.cnn\.com/.+'
  109. _TEST = {
  110. 'url': 'http://reliablesources.blogs.cnn.com/2014/02/09/criminalizing-journalism/',
  111. 'md5': '3e56f97b0b6ffb4b79f4ea0749551084',
  112. 'info_dict': {
  113. 'id': 'bestoftv/2014/02/09/criminalizing-journalism.cnn',
  114. 'ext': 'mp4',
  115. 'title': 'Criminalizing journalism?',
  116. 'description': 'Glenn Greenwald responds to comments made this week on Capitol Hill that journalists could be criminal accessories.',
  117. 'upload_date': '20140209',
  118. },
  119. 'add_ie': ['CNN'],
  120. }
  121. def _real_extract(self, url):
  122. webpage = self._download_webpage(url, url_basename(url))
  123. cnn_url = self._html_search_regex(r'data-url="(.+?)"', webpage, 'cnn url')
  124. return {
  125. '_type': 'url',
  126. 'url': cnn_url,
  127. 'ie_key': CNNIE.ie_key(),
  128. }
  129. class CNNArticleIE(InfoExtractor):
  130. _VALID_URL = r'https?://(?:(?:edition|www)\.)?cnn\.com/(?!video/)'
  131. _TEST = {
  132. 'url': 'http://www.cnn.com/2014/12/21/politics/obama-north-koreas-hack-not-war-but-cyber-vandalism/',
  133. 'md5': '689034c2a3d9c6dc4aa72d65a81efd01',
  134. 'info_dict': {
  135. 'id': 'bestoftv/2014/12/21/ip-north-korea-obama.cnn',
  136. 'ext': 'mp4',
  137. 'title': 'Obama: Cyberattack not an act of war',
  138. 'description': 'md5:51ce6750450603795cad0cdfbd7d05c5',
  139. 'upload_date': '20141221',
  140. },
  141. 'add_ie': ['CNN'],
  142. }
  143. def _real_extract(self, url):
  144. webpage = self._download_webpage(url, url_basename(url))
  145. cnn_url = self._html_search_regex(r"video:\s*'([^']+)'", webpage, 'cnn url')
  146. return {
  147. '_type': 'url',
  148. 'url': 'http://cnn.com/video/?/video/' + cnn_url,
  149. 'ie_key': CNNIE.ie_key(),
  150. }