]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/washingtonpost.py
debian/upstream-signing-key.asc: Add keys from upstream.
[youtubedl] / youtube_dl / extractor / washingtonpost.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 int_or_none,
8 strip_jsonp,
9 )
10
11
12 class WashingtonPostIE(InfoExtractor):
13 _VALID_URL = r'^https?://(?:www\.)?washingtonpost\.com/.*?/(?P<id>[^/]+)/(?:$|[?#])'
14 _TEST = {
15 'url': 'http://www.washingtonpost.com/sf/national/2014/03/22/sinkhole-of-bureaucracy/',
16 'playlist': [{
17 'md5': 'c3f4b4922ffa259243f68e928db2db8c',
18 'info_dict': {
19 'id': 'fc433c38-b146-11e3-b8b3-44b1d1cd4c1f',
20 'ext': 'mp4',
21 'title': 'Breaking Points: The Paper Mine',
22 'duration': 1287,
23 '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.',
24 'uploader': 'The Washington Post',
25 'timestamp': 1395527908,
26 'upload_date': '20140322',
27 },
28 }, {
29 'md5': 'f645a07652c2950cd9134bb852c5f5eb',
30 'info_dict': {
31 'id': '41255e28-b14a-11e3-b8b3-44b1d1cd4c1f',
32 'ext': 'mp4',
33 'title': 'The town bureaucracy sustains',
34 '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.',
35 'duration': 2217,
36 'timestamp': 1395528005,
37 'upload_date': '20140322',
38 'uploader': 'The Washington Post',
39 },
40 }]
41 }
42
43 def _real_extract(self, url):
44 mobj = re.match(self._VALID_URL, url)
45 page_id = mobj.group('id')
46
47 webpage = self._download_webpage(url, page_id)
48 title = self._og_search_title(webpage)
49 uuids = re.findall(r'data-video-uuid="([^"]+)"', webpage)
50 entries = []
51 for i, uuid in enumerate(uuids, start=1):
52 vinfo_all = self._download_json(
53 'http://www.washingtonpost.com/posttv/c/videojson/%s?resType=jsonp' % uuid,
54 page_id,
55 transform_source=strip_jsonp,
56 note='Downloading information of video %d/%d' % (i, len(uuids))
57 )
58 vinfo = vinfo_all[0]['contentConfig']
59 uploader = vinfo.get('credits', {}).get('source')
60 timestamp = int_or_none(
61 vinfo.get('dateConfig', {}).get('dateFirstPublished'), 1000)
62
63 formats = [{
64 'format_id': (
65 '%s-%s-%s' % (s.get('type'), s.get('width'), s.get('bitrate'))
66 if s.get('width')
67 else s.get('type')),
68 'vbr': s.get('bitrate') if s.get('width') != 0 else None,
69 'width': s.get('width'),
70 'height': s.get('height'),
71 'acodec': s.get('audioCodec'),
72 'vcodec': s.get('videoCodec') if s.get('width') != 0 else 'none',
73 'filesize': s.get('fileSize'),
74 'url': s.get('url'),
75 'ext': 'mp4',
76 'protocol': {
77 'MP4': 'http',
78 'F4F': 'f4m',
79 }.get(s.get('type'))
80 } for s in vinfo.get('streams', [])]
81 source_media_url = vinfo.get('sourceMediaURL')
82 if source_media_url:
83 formats.append({
84 'format_id': 'source_media',
85 'url': source_media_url,
86 })
87 self._sort_formats(formats)
88 entries.append({
89 'id': uuid,
90 'title': vinfo['title'],
91 'description': vinfo.get('blurb'),
92 'uploader': uploader,
93 'formats': formats,
94 'duration': int_or_none(vinfo.get('videoDuration'), 100),
95 'timestamp': timestamp,
96 })
97
98 return {
99 '_type': 'playlist',
100 'entries': entries,
101 'id': page_id,
102 'title': title,
103 }