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