youtube-dl

Another place where youtube-dl lives on
git clone git://git.oshgnacknak.de/youtube-dl.git
Log | Files | Refs | README | LICENSE

cnn.py (6524B)


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