cnn.py 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. from .common import InfoExtractor
  2. from .turner import TurnerBaseIE
  3. from ..utils import merge_dicts, try_call, url_basename
  4. class CNNIE(TurnerBaseIE):
  5. _VALID_URL = r'''(?x)https?://(?:(?P<sub_domain>edition|www|money)\.)?cnn\.com/(?:video/(?:data/.+?|\?)/)?videos?/
  6. (?P<path>.+?/(?P<title>[^/]+?)(?:\.(?:[a-z\-]+)|(?=&)))'''
  7. _TESTS = [{
  8. 'url': 'http://edition.cnn.com/video/?/video/sports/2013/06/09/nadal-1-on-1.cnn',
  9. 'md5': '3e6121ea48df7e2259fe73a0628605c4',
  10. 'info_dict': {
  11. 'id': 'sports/2013/06/09/nadal-1-on-1.cnn',
  12. 'ext': 'mp4',
  13. 'title': 'Nadal wins 8th French Open title',
  14. 'description': 'World Sport\'s Amanda Davies chats with 2013 French Open champion Rafael Nadal.',
  15. 'duration': 135,
  16. 'upload_date': '20130609',
  17. },
  18. 'expected_warnings': ['Failed to download m3u8 information'],
  19. }, {
  20. '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',
  21. 'md5': 'b5cc60c60a3477d185af8f19a2a26f4e',
  22. 'info_dict': {
  23. 'id': 'us/2013/08/21/sot-student-gives-epic-speech.georgia-institute-of-technology',
  24. 'ext': 'mp4',
  25. 'title': "Student's epic speech stuns new freshmen",
  26. 'description': 'A Georgia Tech student welcomes the incoming freshmen with an epic speech backed by music from "2001: A Space Odyssey."',
  27. 'upload_date': '20130821',
  28. },
  29. 'expected_warnings': ['Failed to download m3u8 information'],
  30. }, {
  31. 'url': 'http://www.cnn.com/video/data/2.0/video/living/2014/12/22/growing-america-nashville-salemtown-board-episode-1.hln.html',
  32. 'md5': 'f14d02ebd264df951feb2400e2c25a1b',
  33. 'info_dict': {
  34. 'id': 'living/2014/12/22/growing-america-nashville-salemtown-board-episode-1.hln',
  35. 'ext': 'mp4',
  36. 'title': 'Nashville Ep. 1: Hand crafted skateboards',
  37. 'description': 'md5:e7223a503315c9f150acac52e76de086',
  38. 'upload_date': '20141222',
  39. },
  40. 'expected_warnings': ['Failed to download m3u8 information'],
  41. }, {
  42. 'url': 'http://money.cnn.com/video/news/2016/08/19/netflix-stunning-stats.cnnmoney/index.html',
  43. 'md5': '52a515dc1b0f001cd82e4ceda32be9d1',
  44. 'info_dict': {
  45. 'id': '/video/news/2016/08/19/netflix-stunning-stats.cnnmoney',
  46. 'ext': 'mp4',
  47. 'title': '5 stunning stats about Netflix',
  48. '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.',
  49. 'upload_date': '20160819',
  50. },
  51. 'params': {
  52. # m3u8 download
  53. 'skip_download': True,
  54. },
  55. }, {
  56. 'url': 'http://cnn.com/video/?/video/politics/2015/03/27/pkg-arizona-senator-church-attendance-mandatory.ktvk',
  57. 'only_matching': True,
  58. }, {
  59. 'url': 'http://cnn.com/video/?/video/us/2015/04/06/dnt-baker-refuses-anti-gay-order.wkmg',
  60. 'only_matching': True,
  61. }, {
  62. 'url': 'http://edition.cnn.com/videos/arts/2016/04/21/olympic-games-cultural-a-z-brazil.cnn',
  63. 'only_matching': True,
  64. }]
  65. _CONFIG = {
  66. # http://edition.cnn.com/.element/apps/cvp/3.0/cfg/spider/cnn/expansion/config.xml
  67. 'edition': {
  68. 'data_src': 'http://edition.cnn.com/video/data/3.0/video/%s/index.xml',
  69. 'media_src': 'http://pmd.cdn.turner.com/cnn/big',
  70. },
  71. # http://money.cnn.com/.element/apps/cvp2/cfg/config.xml
  72. 'money': {
  73. 'data_src': 'http://money.cnn.com/video/data/4.0/video/%s.xml',
  74. 'media_src': 'http://ht3.cdn.turner.com/money/big',
  75. },
  76. }
  77. def _extract_timestamp(self, video_data):
  78. # TODO: fix timestamp extraction
  79. return None
  80. def _real_extract(self, url):
  81. sub_domain, path, page_title = self._match_valid_url(url).groups()
  82. if sub_domain not in ('money', 'edition'):
  83. sub_domain = 'edition'
  84. config = self._CONFIG[sub_domain]
  85. return self._extract_cvp_info(
  86. config['data_src'] % path, page_title, {
  87. 'default': {
  88. 'media_src': config['media_src'],
  89. },
  90. 'f4m': {
  91. 'host': 'cnn-vh.akamaihd.net',
  92. },
  93. })
  94. class CNNBlogsIE(InfoExtractor):
  95. _VALID_URL = r'https?://[^\.]+\.blogs\.cnn\.com/.+'
  96. _TEST = {
  97. 'url': 'http://reliablesources.blogs.cnn.com/2014/02/09/criminalizing-journalism/',
  98. 'md5': '3e56f97b0b6ffb4b79f4ea0749551084',
  99. 'info_dict': {
  100. 'id': 'bestoftv/2014/02/09/criminalizing-journalism.cnn',
  101. 'ext': 'mp4',
  102. 'title': 'Criminalizing journalism?',
  103. 'description': 'Glenn Greenwald responds to comments made this week on Capitol Hill that journalists could be criminal accessories.',
  104. 'upload_date': '20140209',
  105. },
  106. 'expected_warnings': ['Failed to download m3u8 information'],
  107. 'add_ie': ['CNN'],
  108. }
  109. def _real_extract(self, url):
  110. webpage = self._download_webpage(url, url_basename(url))
  111. cnn_url = self._html_search_regex(r'data-url="(.+?)"', webpage, 'cnn url')
  112. return self.url_result(cnn_url, CNNIE.ie_key())
  113. class CNNArticleIE(InfoExtractor):
  114. _VALID_URL = r'https?://(?:(?:edition|www)\.)?cnn\.com/(?!videos?/)'
  115. _TEST = {
  116. 'url': 'http://www.cnn.com/2014/12/21/politics/obama-north-koreas-hack-not-war-but-cyber-vandalism/',
  117. 'md5': '689034c2a3d9c6dc4aa72d65a81efd01',
  118. 'info_dict': {
  119. 'id': 'bestoftv/2014/12/21/ip-north-korea-obama.cnn',
  120. 'ext': 'mp4',
  121. 'title': 'Obama: Cyberattack not an act of war',
  122. 'description': 'md5:0a802a40d2376f60e6b04c8d5bcebc4b',
  123. 'upload_date': '20141221',
  124. },
  125. 'expected_warnings': ['Failed to download m3u8 information'],
  126. 'add_ie': ['CNN'],
  127. }
  128. def _real_extract(self, url):
  129. webpage = self._download_webpage(url, url_basename(url))
  130. cnn_url = self._html_search_regex(r"video:\s*'([^']+)'", webpage, 'cnn url')
  131. return self.url_result('http://cnn.com/video/?/video/' + cnn_url, CNNIE.ie_key())
  132. class CNNIndonesiaIE(InfoExtractor):
  133. _VALID_URL = r'https?://www\.cnnindonesia\.com/[\w-]+/(?P<upload_date>\d{8})\d+-\d+-(?P<id>\d+)/(?P<display_id>[\w-]+)'
  134. _TESTS = [{
  135. 'url': 'https://www.cnnindonesia.com/ekonomi/20220909212635-89-845885/alasan-harga-bbm-di-indonesia-masih-disubsidi',
  136. 'info_dict': {
  137. 'id': '845885',
  138. 'ext': 'mp4',
  139. 'description': 'md5:e7954bfa6f1749bc9ef0c079a719c347',
  140. 'upload_date': '20220909',
  141. 'title': 'Alasan Harga BBM di Indonesia Masih Disubsidi',
  142. 'timestamp': 1662859088,
  143. 'duration': 120.0,
  144. 'thumbnail': r're:https://akcdn\.detik\.net\.id/visual/2022/09/09/thumbnail-ekopedia-alasan-harga-bbm-disubsidi_169\.jpeg',
  145. 'tags': ['ekopedia', 'subsidi bbm', 'subsidi', 'bbm', 'bbm subsidi', 'harga pertalite naik'],
  146. 'age_limit': 0,
  147. 'release_timestamp': 1662859088,
  148. 'release_date': '20220911',
  149. 'uploader': 'Asfahan Yahsyi',
  150. },
  151. }, {
  152. 'url': 'https://www.cnnindonesia.com/internasional/20220911104341-139-846189/video-momen-charles-disambut-meriah-usai-dilantik-jadi-raja-inggris',
  153. 'info_dict': {
  154. 'id': '846189',
  155. 'ext': 'mp4',
  156. 'upload_date': '20220911',
  157. 'duration': 76.0,
  158. 'timestamp': 1662869995,
  159. 'description': 'md5:ece7b003b3ee7d81c6a5cfede7d5397d',
  160. 'thumbnail': r're:https://akcdn\.detik\.net\.id/visual/2022/09/11/thumbnail-video-1_169\.jpeg',
  161. 'title': 'VIDEO: Momen Charles Disambut Meriah usai Dilantik jadi Raja Inggris',
  162. 'tags': ['raja charles', 'raja charles iii', 'ratu elizabeth', 'ratu elizabeth meninggal dunia', 'raja inggris', 'inggris'],
  163. 'age_limit': 0,
  164. 'release_date': '20220911',
  165. 'uploader': 'REUTERS',
  166. 'release_timestamp': 1662869995,
  167. },
  168. }]
  169. def _real_extract(self, url):
  170. upload_date, video_id, display_id = self._match_valid_url(url).group('upload_date', 'id', 'display_id')
  171. webpage = self._download_webpage(url, display_id)
  172. json_ld_list = list(self._yield_json_ld(webpage, display_id))
  173. json_ld_data = self._json_ld(json_ld_list, display_id)
  174. embed_url = next(
  175. json_ld.get('embedUrl') for json_ld in json_ld_list if json_ld.get('@type') == 'VideoObject')
  176. return merge_dicts(json_ld_data, {
  177. '_type': 'url_transparent',
  178. 'url': embed_url,
  179. 'upload_date': upload_date,
  180. 'tags': try_call(lambda: self._html_search_meta('keywords', webpage).split(', ')),
  181. })