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.

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