]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..utils import ( | |
3 | float_or_none, | |
4 | int_or_none, | |
5 | parse_iso8601, | |
6 | try_get, | |
7 | ) | |
8 | ||
9 | ||
10 | class NineCNineMediaIE(InfoExtractor): | |
11 | IE_NAME = '9c9media' | |
12 | _GEO_COUNTRIES = ['CA'] | |
13 | _VALID_URL = r'9c9media:(?P<destination_code>[^:]+):(?P<id>\d+)' | |
14 | _API_BASE_TEMPLATE = 'http://capi.9c9media.com/destinations/%s/platforms/desktop/contents/%s/' | |
15 | ||
16 | def _real_extract(self, url): | |
17 | destination_code, content_id = self._match_valid_url(url).groups() | |
18 | api_base_url = self._API_BASE_TEMPLATE % (destination_code, content_id) | |
19 | content = self._download_json(api_base_url, content_id, query={ | |
20 | '$include': '[Media.Name,Season,ContentPackages.Duration,ContentPackages.Id]', | |
21 | }) | |
22 | title = content['Name'] | |
23 | content_package = content['ContentPackages'][0] | |
24 | package_id = content_package['Id'] | |
25 | content_package_url = api_base_url + 'contentpackages/%s/' % package_id | |
26 | content_package = self._download_json( | |
27 | content_package_url, content_id, query={ | |
28 | '$include': '[HasClosedCaptions]', | |
29 | }) | |
30 | ||
31 | if (not self.get_param('allow_unplayable_formats') | |
32 | and try_get(content_package, lambda x: x['Constraints']['Security']['Type'])): | |
33 | self.report_drm(content_id) | |
34 | ||
35 | manifest_base_url = content_package_url + 'manifest.' | |
36 | formats = [] | |
37 | formats.extend(self._extract_m3u8_formats( | |
38 | manifest_base_url + 'm3u8', content_id, 'mp4', | |
39 | 'm3u8_native', m3u8_id='hls', fatal=False)) | |
40 | formats.extend(self._extract_f4m_formats( | |
41 | manifest_base_url + 'f4m', content_id, | |
42 | f4m_id='hds', fatal=False)) | |
43 | formats.extend(self._extract_mpd_formats( | |
44 | manifest_base_url + 'mpd', content_id, | |
45 | mpd_id='dash', fatal=False)) | |
46 | ||
47 | thumbnails = [] | |
48 | for image in (content.get('Images') or []): | |
49 | image_url = image.get('Url') | |
50 | if not image_url: | |
51 | continue | |
52 | thumbnails.append({ | |
53 | 'url': image_url, | |
54 | 'width': int_or_none(image.get('Width')), | |
55 | 'height': int_or_none(image.get('Height')), | |
56 | }) | |
57 | ||
58 | tags, categories = [], [] | |
59 | for source_name, container in (('Tags', tags), ('Genres', categories)): | |
60 | for e in content.get(source_name, []): | |
61 | e_name = e.get('Name') | |
62 | if not e_name: | |
63 | continue | |
64 | container.append(e_name) | |
65 | ||
66 | season = content.get('Season') or {} | |
67 | ||
68 | info = { | |
69 | 'id': content_id, | |
70 | 'title': title, | |
71 | 'description': content.get('Desc') or content.get('ShortDesc'), | |
72 | 'timestamp': parse_iso8601(content.get('BroadcastDateTime')), | |
73 | 'episode_number': int_or_none(content.get('Episode')), | |
74 | 'season': season.get('Name'), | |
75 | 'season_number': int_or_none(season.get('Number')), | |
76 | 'season_id': season.get('Id'), | |
77 | 'series': try_get(content, lambda x: x['Media']['Name']), | |
78 | 'tags': tags, | |
79 | 'categories': categories, | |
80 | 'duration': float_or_none(content_package.get('Duration')), | |
81 | 'formats': formats, | |
82 | 'thumbnails': thumbnails, | |
83 | } | |
84 | ||
85 | if content_package.get('HasClosedCaptions'): | |
86 | info['subtitles'] = { | |
87 | 'en': [{ | |
88 | 'url': manifest_base_url + 'vtt', | |
89 | 'ext': 'vtt', | |
90 | }, { | |
91 | 'url': manifest_base_url + 'srt', | |
92 | 'ext': 'srt', | |
93 | }] | |
94 | } | |
95 | ||
96 | return info | |
97 | ||
98 | ||
99 | class CPTwentyFourIE(InfoExtractor): | |
100 | IE_NAME = 'cp24' | |
101 | _GEO_COUNTRIES = ['CA'] | |
102 | _VALID_URL = r'https?://(?:www\.)?cp24\.com/news/(?P<id>[^?#]+)' | |
103 | ||
104 | _TESTS = [{ | |
105 | 'url': 'https://www.cp24.com/news/video-shows-atm-being-ripped-out-of-business-by-pickup-truck-driver-in-mississauga-1.5676877', | |
106 | 'info_dict': { | |
107 | 'id': '2328005', | |
108 | 'ext': 'mp4', | |
109 | 'title': 'WATCH: Truck rips ATM from Mississauga business', | |
110 | 'description': 'md5:cf7498480885f080a754389a2b2f7073', | |
111 | 'timestamp': 1637618377, | |
112 | 'episode_number': None, | |
113 | 'season': 'Season 0', | |
114 | 'season_number': 0, | |
115 | 'season_id': 57974, | |
116 | 'series': 'CTV News Toronto', | |
117 | 'duration': 26.86, | |
118 | 'thumbnail': 'http://images2.9c9media.com/image_asset/2014_11_5_2eb609a0-475b-0132-fbd6-34b52f6f1279_jpg_2000x1125.jpg', | |
119 | 'upload_date': '20211122', | |
120 | }, | |
121 | 'params': {'skip_download': True, 'format': 'bv'} | |
122 | }] | |
123 | ||
124 | def _real_extract(self, url): | |
125 | display_id = self._match_id(url) | |
126 | webpage = self._download_webpage(url, display_id) | |
127 | id, destination = self._search_regex( | |
128 | r'getAuthStates\("(?P<id>[^"]+)",\s?"(?P<destination>[^"]+)"\);', | |
129 | webpage, 'video id and destination', group=('id', 'destination')) | |
130 | return self.url_result(f'9c9media:{destination}:{id}', ie=NineCNineMediaIE.ie_key(), video_id=id) |