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.

167 lines
6.4 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>[^/]+?)(?:\.(?:cnn|hln|ktvk)(?:-ap)?|(?=&)))'''
  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. def _real_extract(self, url):
  48. mobj = re.match(self._VALID_URL, url)
  49. path = mobj.group('path')
  50. page_title = mobj.group('title')
  51. info_url = 'http://edition.cnn.com/video/data/3.0/%s/index.xml' % path
  52. info = self._download_xml(info_url, page_title)
  53. formats = []
  54. rex = re.compile(r'''(?x)
  55. (?P<width>[0-9]+)x(?P<height>[0-9]+)
  56. (?:_(?P<bitrate>[0-9]+)k)?
  57. ''')
  58. for f in info.findall('files/file'):
  59. video_url = 'http://ht.cdn.turner.com/cnn/big%s' % (f.text.strip())
  60. fdct = {
  61. 'format_id': f.attrib['bitrate'],
  62. 'url': video_url,
  63. }
  64. mf = rex.match(f.attrib['bitrate'])
  65. if mf:
  66. fdct['width'] = int(mf.group('width'))
  67. fdct['height'] = int(mf.group('height'))
  68. fdct['tbr'] = int_or_none(mf.group('bitrate'))
  69. else:
  70. mf = rex.search(f.text)
  71. if mf:
  72. fdct['width'] = int(mf.group('width'))
  73. fdct['height'] = int(mf.group('height'))
  74. fdct['tbr'] = int_or_none(mf.group('bitrate'))
  75. else:
  76. mi = re.match(r'ios_(audio|[0-9]+)$', f.attrib['bitrate'])
  77. if mi:
  78. if mi.group(1) == 'audio':
  79. fdct['vcodec'] = 'none'
  80. fdct['ext'] = 'm4a'
  81. else:
  82. fdct['tbr'] = int(mi.group(1))
  83. formats.append(fdct)
  84. self._sort_formats(formats)
  85. thumbnails = [{
  86. 'height': int(t.attrib['height']),
  87. 'width': int(t.attrib['width']),
  88. 'url': t.text,
  89. } for t in info.findall('images/image')]
  90. metas_el = info.find('metas')
  91. upload_date = (
  92. metas_el.attrib.get('version') if metas_el is not None else None)
  93. duration_el = info.find('length')
  94. duration = parse_duration(duration_el.text)
  95. return {
  96. 'id': info.attrib['id'],
  97. 'title': info.find('headline').text,
  98. 'formats': formats,
  99. 'thumbnails': thumbnails,
  100. 'description': info.find('description').text,
  101. 'duration': duration,
  102. 'upload_date': upload_date,
  103. }
  104. class CNNBlogsIE(InfoExtractor):
  105. _VALID_URL = r'https?://[^\.]+\.blogs\.cnn\.com/.+'
  106. _TEST = {
  107. 'url': 'http://reliablesources.blogs.cnn.com/2014/02/09/criminalizing-journalism/',
  108. 'md5': '3e56f97b0b6ffb4b79f4ea0749551084',
  109. 'info_dict': {
  110. 'id': 'bestoftv/2014/02/09/criminalizing-journalism.cnn',
  111. 'ext': 'mp4',
  112. 'title': 'Criminalizing journalism?',
  113. 'description': 'Glenn Greenwald responds to comments made this week on Capitol Hill that journalists could be criminal accessories.',
  114. 'upload_date': '20140209',
  115. },
  116. 'add_ie': ['CNN'],
  117. }
  118. def _real_extract(self, url):
  119. webpage = self._download_webpage(url, url_basename(url))
  120. cnn_url = self._html_search_regex(r'data-url="(.+?)"', webpage, 'cnn url')
  121. return {
  122. '_type': 'url',
  123. 'url': cnn_url,
  124. 'ie_key': CNNIE.ie_key(),
  125. }
  126. class CNNArticleIE(InfoExtractor):
  127. _VALID_URL = r'https?://(?:(?:edition|www)\.)?cnn\.com/(?!video/)'
  128. _TEST = {
  129. 'url': 'http://www.cnn.com/2014/12/21/politics/obama-north-koreas-hack-not-war-but-cyber-vandalism/',
  130. 'md5': '689034c2a3d9c6dc4aa72d65a81efd01',
  131. 'info_dict': {
  132. 'id': 'bestoftv/2014/12/21/ip-north-korea-obama.cnn',
  133. 'ext': 'mp4',
  134. 'title': 'Obama: Cyberattack not an act of war',
  135. 'description': 'md5:51ce6750450603795cad0cdfbd7d05c5',
  136. 'upload_date': '20141221',
  137. },
  138. 'add_ie': ['CNN'],
  139. }
  140. def _real_extract(self, url):
  141. webpage = self._download_webpage(url, url_basename(url))
  142. cnn_url = self._html_search_regex(r"video:\s*'([^']+)'", webpage, 'cnn url')
  143. return {
  144. '_type': 'url',
  145. 'url': 'http://cnn.com/video/?/video/' + cnn_url,
  146. 'ie_key': CNNIE.ie_key(),
  147. }