]>
Commit | Line | Data |
---|---|---|
5d53c327 | 1 | from .common import InfoExtractor |
2 | from ..utils import ( | |
ae18d582 | 3 | ExtractorError, |
5d53c327 | 4 | get_element_by_attribute, |
5 | parse_duration, | |
ae18d582 | 6 | try_get, |
5d53c327 | 7 | update_url_query, |
5d53c327 | 8 | ) |
9 | from ..compat import compat_str | |
10 | ||
11 | ||
12 | class USATodayIE(InfoExtractor): | |
13 | _VALID_URL = r'https?://(?:www\.)?usatoday\.com/(?:[^/]+/)*(?P<id>[^?/#]+)' | |
ae18d582 RA |
14 | _TESTS = [{ |
15 | # Brightcove Partner ID = 29906170001 | |
5d53c327 | 16 | 'url': 'http://www.usatoday.com/media/cinematic/video/81729424/us-france-warn-syrian-regime-ahead-of-new-peace-talks/', |
ae18d582 | 17 | 'md5': '033587d2529dc3411a1ab3644c3b8827', |
5d53c327 | 18 | 'info_dict': { |
ae18d582 | 19 | 'id': '4799374959001', |
5d53c327 | 20 | 'ext': 'mp4', |
21 | 'title': 'US, France warn Syrian regime ahead of new peace talks', | |
22 | 'timestamp': 1457891045, | |
23 | 'description': 'md5:7e50464fdf2126b0f533748d3c78d58f', | |
24 | 'uploader_id': '29906170001', | |
25 | 'upload_date': '20160313', | |
26 | } | |
ae18d582 RA |
27 | }, { |
28 | # ui-video-data[asset_metadata][items][brightcoveaccount] = 28911775001 | |
29 | 'url': 'https://www.usatoday.com/story/tech/science/2018/08/21/yellowstone-supervolcano-eruption-stop-worrying-its-blow/973633002/', | |
30 | 'info_dict': { | |
31 | 'id': '5824495846001', | |
32 | 'ext': 'mp4', | |
33 | 'title': 'Yellowstone more likely to crack rather than explode', | |
34 | 'timestamp': 1534790612, | |
35 | 'description': 'md5:3715e7927639a4f16b474e9391687c62', | |
36 | 'uploader_id': '28911775001', | |
37 | 'upload_date': '20180820', | |
38 | } | |
39 | }] | |
40 | BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s' | |
5d53c327 | 41 | |
42 | def _real_extract(self, url): | |
43 | display_id = self._match_id(url) | |
44 | webpage = self._download_webpage(update_url_query(url, {'ajax': 'true'}), display_id) | |
45 | ui_video_data = get_element_by_attribute('class', 'ui-video-data', webpage) | |
46 | if not ui_video_data: | |
47 | raise ExtractorError('no video on the webpage', expected=True) | |
48 | video_data = self._parse_json(ui_video_data, display_id) | |
ae18d582 | 49 | item = try_get(video_data, lambda x: x['asset_metadata']['items'], dict) or {} |
5d53c327 | 50 | |
51 | return { | |
52 | '_type': 'url_transparent', | |
ae18d582 | 53 | 'url': self.BRIGHTCOVE_URL_TEMPLATE % (item.get('brightcoveaccount', '29906170001'), item.get('brightcoveid') or video_data['brightcove_id']), |
5d53c327 | 54 | 'id': compat_str(video_data['id']), |
55 | 'title': video_data['title'], | |
56 | 'thumbnail': video_data.get('thumbnail'), | |
57 | 'description': video_data.get('description'), | |
58 | 'duration': parse_duration(video_data.get('length')), | |
59 | 'ie_key': 'BrightcoveNew', | |
60 | } |