1 from __future__ import unicode_literals
3 from .common import InfoExtractor
11 class NYTimesIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:(?:www\.)?nytimes\.com/video/(?:[^/]+/)+|graphics8\.nytimes\.com/bcvideo/\d+(?:\.\d+)?/iframe/embed\.html\?videoId=)(?P<id>\d+)'
15 'url': 'http://www.nytimes.com/video/opinion/100000002847155/verbatim-what-is-a-photocopier.html?playlistId=100000001150263',
16 'md5': '18a525a510f942ada2720db5f31644c0',
18 'id': '100000002847155',
20 'title': 'Verbatim: What Is a Photocopier?',
21 'description': 'md5:93603dada88ddbda9395632fdc5da260',
22 'timestamp': 1398631707,
23 'upload_date': '20140427',
24 'uploader': 'Brett Weiner',
29 def _real_extract(self, url):
30 video_id = self._match_id(url)
32 video_data = self._download_json(
33 'http://www.nytimes.com/svc/video/api/v2/video/%s' % video_id,
34 video_id, 'Downloading video JSON')
36 title = video_data['headline']
37 description = video_data.get('summary')
38 duration = float_or_none(video_data.get('duration'), 1000)
40 uploader = video_data['byline']
41 timestamp = parse_iso8601(video_data['publication_date'][:-8])
43 def get_file_size(file_size):
44 if isinstance(file_size, int):
46 elif isinstance(file_size, dict):
47 return int(file_size.get('value', 0))
54 'format_id': video.get('type'),
55 'vcodec': video.get('video_codec'),
56 'width': int_or_none(video.get('width')),
57 'height': int_or_none(video.get('height')),
58 'filesize': get_file_size(video.get('fileSize')),
59 } for video in video_data['renditions']
61 self._sort_formats(formats)
65 'url': 'http://www.nytimes.com/%s' % image['url'],
66 'width': int_or_none(image.get('width')),
67 'height': int_or_none(image.get('height')),
68 } for image in video_data['images']
74 'description': description,
75 'timestamp': timestamp,
79 'thumbnails': thumbnails,