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',
28 'url': 'http://www.nytimes.com/video/travel/100000003550828/36-hours-in-dubai.html',
29 'only_matching': True,
32 def _real_extract(self, url):
33 video_id = self._match_id(url)
35 video_data = self._download_json(
36 'http://www.nytimes.com/svc/video/api/v2/video/%s' % video_id,
37 video_id, 'Downloading video JSON')
39 title = video_data['headline']
40 description = video_data.get('summary')
41 duration = float_or_none(video_data.get('duration'), 1000)
43 uploader = video_data['byline']
44 timestamp = parse_iso8601(video_data['publication_date'][:-8])
46 def get_file_size(file_size):
47 if isinstance(file_size, int):
49 elif isinstance(file_size, dict):
50 return int(file_size.get('value', 0))
57 'format_id': video.get('type'),
58 'vcodec': video.get('video_codec'),
59 'width': int_or_none(video.get('width')),
60 'height': int_or_none(video.get('height')),
61 'filesize': get_file_size(video.get('fileSize')),
62 } for video in video_data['renditions']
64 self._sort_formats(formats)
68 'url': 'http://www.nytimes.com/%s' % image['url'],
69 'width': int_or_none(image.get('width')),
70 'height': int_or_none(image.get('height')),
71 } for image in video_data['images']
77 'description': description,
78 'timestamp': timestamp,
82 'thumbnails': thumbnails,