]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/usatoday.py
debian/{compat,control}: Update to debhelper compatibility level 12.
[youtubedl] / youtube_dl / extractor / usatoday.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 get_element_by_attribute,
7 parse_duration,
8 update_url_query,
9 ExtractorError,
10 )
11 from ..compat import compat_str
12
13
14 class USATodayIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?usatoday\.com/(?:[^/]+/)*(?P<id>[^?/#]+)'
16 _TEST = {
17 'url': 'http://www.usatoday.com/media/cinematic/video/81729424/us-france-warn-syrian-regime-ahead-of-new-peace-talks/',
18 'md5': '4d40974481fa3475f8bccfd20c5361f8',
19 'info_dict': {
20 'id': '81729424',
21 'ext': 'mp4',
22 'title': 'US, France warn Syrian regime ahead of new peace talks',
23 'timestamp': 1457891045,
24 'description': 'md5:7e50464fdf2126b0f533748d3c78d58f',
25 'uploader_id': '29906170001',
26 'upload_date': '20160313',
27 }
28 }
29 BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/29906170001/38a9eecc-bdd8-42a3-ba14-95397e48b3f8_default/index.html?videoId=%s'
30
31 def _real_extract(self, url):
32 display_id = self._match_id(url)
33 webpage = self._download_webpage(update_url_query(url, {'ajax': 'true'}), display_id)
34 ui_video_data = get_element_by_attribute('class', 'ui-video-data', webpage)
35 if not ui_video_data:
36 raise ExtractorError('no video on the webpage', expected=True)
37 video_data = self._parse_json(ui_video_data, display_id)
38
39 return {
40 '_type': 'url_transparent',
41 'url': self.BRIGHTCOVE_URL_TEMPLATE % video_data['brightcove_id'],
42 'id': compat_str(video_data['id']),
43 'title': video_data['title'],
44 'thumbnail': video_data.get('thumbnail'),
45 'description': video_data.get('description'),
46 'duration': parse_duration(video_data.get('length')),
47 'ie_key': 'BrightcoveNew',
48 }