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