youtube-dl

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

washingtonpost.py (5257B)


      1 # coding: utf-8
      2 from __future__ import unicode_literals
      3 
      4 import re
      5 
      6 from .common import InfoExtractor
      7 
      8 
      9 class WashingtonPostIE(InfoExtractor):
     10     IE_NAME = 'washingtonpost'
     11     _VALID_URL = r'(?:washingtonpost:|https?://(?:www\.)?washingtonpost\.com/(?:video|posttv)/(?:[^/]+/)*)(?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'
     12     _EMBED_URL = r'https?://(?:www\.)?washingtonpost\.com/video/c/embed/[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}'
     13     _TESTS = [{
     14         'url': 'https://www.washingtonpost.com/video/c/video/480ba4ee-1ec7-11e6-82c2-a7dcb313287d',
     15         'md5': '6f537e1334b714eb15f9563bd4b9cdfa',
     16         'info_dict': {
     17             'id': '480ba4ee-1ec7-11e6-82c2-a7dcb313287d',
     18             'ext': 'mp4',
     19             'title': 'Egypt finds belongings, debris from plane crash',
     20             'description': 'md5:a17ceee432f215a5371388c1f680bd86',
     21             'upload_date': '20160520',
     22             'timestamp': 1463775187,
     23         },
     24     }, {
     25         'url': 'https://www.washingtonpost.com/video/world/egypt-finds-belongings-debris-from-plane-crash/2016/05/20/480ba4ee-1ec7-11e6-82c2-a7dcb313287d_video.html',
     26         'only_matching': True,
     27     }, {
     28         'url': 'https://www.washingtonpost.com/posttv/world/iraq-to-track-down-antiquities-after-islamic-state-museum-rampage/2015/02/28/7c57e916-bf86-11e4-9dfb-03366e719af8_video.html',
     29         'only_matching': True,
     30     }]
     31 
     32     @classmethod
     33     def _extract_urls(cls, webpage):
     34         return re.findall(
     35             r'<iframe[^>]+\bsrc=["\'](%s)' % cls._EMBED_URL, webpage)
     36 
     37     def _real_extract(self, url):
     38         video_id = self._match_id(url)
     39         return self.url_result(
     40             'arcpublishing:wapo:' + video_id, 'ArcPublishing', video_id)
     41 
     42 
     43 class WashingtonPostArticleIE(InfoExtractor):
     44     IE_NAME = 'washingtonpost:article'
     45     _VALID_URL = r'https?://(?:www\.)?washingtonpost\.com/(?:[^/]+/)*(?P<id>[^/?#]+)'
     46     _TESTS = [{
     47         'url': 'http://www.washingtonpost.com/sf/national/2014/03/22/sinkhole-of-bureaucracy/',
     48         'info_dict': {
     49             'id': 'sinkhole-of-bureaucracy',
     50             'title': 'Sinkhole of bureaucracy',
     51         },
     52         'playlist': [{
     53             'md5': 'b9be794ceb56c7267d410a13f99d801a',
     54             'info_dict': {
     55                 'id': 'fc433c38-b146-11e3-b8b3-44b1d1cd4c1f',
     56                 'ext': 'mp4',
     57                 'title': 'Breaking Points: The Paper Mine',
     58                 'duration': 1290,
     59                 'description': 'Overly complicated paper pushing is nothing new to government bureaucracy. But the way federal retirement applications are filed may be the most outdated. David Fahrenthold explains.',
     60                 'timestamp': 1395440416,
     61                 'upload_date': '20140321',
     62             },
     63         }, {
     64             'md5': '1fff6a689d8770966df78c8cb6c8c17c',
     65             'info_dict': {
     66                 'id': '41255e28-b14a-11e3-b8b3-44b1d1cd4c1f',
     67                 'ext': 'mp4',
     68                 'title': 'The town bureaucracy sustains',
     69                 'description': 'Underneath the friendly town of Boyers is a sea of government paperwork. In a disused limestone mine, hundreds of locals now track, file and process retirement applications for the federal government. We set out to find out what it\'s like to do paperwork 230 feet underground.',
     70                 'duration': 2220,
     71                 'timestamp': 1395441819,
     72                 'upload_date': '20140321',
     73             },
     74         }],
     75     }, {
     76         'url': 'http://www.washingtonpost.com/blogs/wonkblog/wp/2014/12/31/one-airline-figured-out-how-to-make-sure-its-airplanes-never-disappear/',
     77         'info_dict': {
     78             'id': 'one-airline-figured-out-how-to-make-sure-its-airplanes-never-disappear',
     79             'title': 'One airline figured out how to make sure its airplanes never disappear',
     80         },
     81         'playlist': [{
     82             'md5': 'a7c1b5634ba5e57a6a82cdffa5b1e0d0',
     83             'info_dict': {
     84                 'id': '0e4bb54c-9065-11e4-a66f-0ca5037a597d',
     85                 'ext': 'mp4',
     86                 'description': 'Washington Post transportation reporter Ashley Halsey III explains why a plane\'s black box needs to be recovered from a crash site instead of having its information streamed in real time throughout the flight.',
     87                 'upload_date': '20141230',
     88                 'timestamp': 1419972442,
     89                 'title': 'Why black boxes don’t transmit data in real time',
     90             }
     91         }]
     92     }]
     93 
     94     @classmethod
     95     def suitable(cls, url):
     96         return False if WashingtonPostIE.suitable(url) else super(WashingtonPostArticleIE, cls).suitable(url)
     97 
     98     def _real_extract(self, url):
     99         page_id = self._match_id(url)
    100         webpage = self._download_webpage(url, page_id)
    101 
    102         title = self._og_search_title(webpage)
    103 
    104         uuids = re.findall(r'''(?x)
    105             (?:
    106                 <div\s+class="posttv-video-embed[^>]*?data-uuid=|
    107                 data-video-uuid=
    108             )"([^"]+)"''', webpage)
    109         entries = [self.url_result('washingtonpost:%s' % uuid, 'WashingtonPost', uuid) for uuid in uuids]
    110 
    111         return {
    112             '_type': 'playlist',
    113             'entries': entries,
    114             'id': page_id,
    115             'title': title,
    116         }