[rh:websockets] Support websockets 14.0+ (#11616)
[yt-dlp3.git] / yt_dlp / extractor / ninecninemedia.py
blob93e28624b78100fc92e1a2c4ad40910e6e6e482c
1 from .common import InfoExtractor
2 from ..utils import (
3 float_or_none,
4 int_or_none,
5 parse_iso8601,
6 str_or_none,
7 try_get,
11 class NineCNineMediaIE(InfoExtractor):
12 IE_NAME = '9c9media'
13 _GEO_COUNTRIES = ['CA']
14 _VALID_URL = r'9c9media:(?P<destination_code>[^:]+):(?P<id>\d+)'
15 _API_BASE_TEMPLATE = 'http://capi.9c9media.com/destinations/%s/platforms/desktop/contents/%s/'
17 def _real_extract(self, url):
18 destination_code, content_id = self._match_valid_url(url).groups()
19 api_base_url = self._API_BASE_TEMPLATE % (destination_code, content_id)
20 content = self._download_json(api_base_url, content_id, query={
21 '$include': '[Media.Name,Season,ContentPackages.Duration,ContentPackages.Id]',
23 title = content['Name']
24 content_package = content['ContentPackages'][0]
25 package_id = content_package['Id']
26 content_package_url = api_base_url + f'contentpackages/{package_id}/'
27 content_package = self._download_json(
28 content_package_url, content_id, query={
29 '$include': '[HasClosedCaptions]',
32 if (not self.get_param('allow_unplayable_formats')
33 and try_get(content_package, lambda x: x['Constraints']['Security']['Type'])):
34 self.report_drm(content_id)
36 manifest_base_url = content_package_url + 'manifest.'
37 formats = []
38 formats.extend(self._extract_m3u8_formats(
39 manifest_base_url + 'm3u8', content_id, 'mp4',
40 'm3u8_native', m3u8_id='hls', fatal=False))
41 formats.extend(self._extract_f4m_formats(
42 manifest_base_url + 'f4m', content_id,
43 f4m_id='hds', fatal=False))
44 formats.extend(self._extract_mpd_formats(
45 manifest_base_url + 'mpd', content_id,
46 mpd_id='dash', fatal=False))
48 thumbnails = []
49 for image in (content.get('Images') or []):
50 image_url = image.get('Url')
51 if not image_url:
52 continue
53 thumbnails.append({
54 'url': image_url,
55 'width': int_or_none(image.get('Width')),
56 'height': int_or_none(image.get('Height')),
59 tags, categories = [], []
60 for source_name, container in (('Tags', tags), ('Genres', categories)):
61 for e in content.get(source_name, []):
62 e_name = e.get('Name')
63 if not e_name:
64 continue
65 container.append(e_name)
67 season = content.get('Season') or {}
69 info = {
70 'id': content_id,
71 'title': title,
72 'description': content.get('Desc') or content.get('ShortDesc'),
73 'timestamp': parse_iso8601(content.get('BroadcastDateTime')),
74 'episode_number': int_or_none(content.get('Episode')),
75 'season': season.get('Name'),
76 'season_number': int_or_none(season.get('Number')),
77 'season_id': str_or_none(season.get('Id')),
78 'series': try_get(content, lambda x: x['Media']['Name']),
79 'tags': tags,
80 'categories': categories,
81 'duration': float_or_none(content_package.get('Duration')),
82 'formats': formats,
83 'thumbnails': thumbnails,
86 if content_package.get('HasClosedCaptions'):
87 info['subtitles'] = {
88 'en': [{
89 'url': manifest_base_url + 'vtt',
90 'ext': 'vtt',
91 }, {
92 'url': manifest_base_url + 'srt',
93 'ext': 'srt',
94 }],
97 return info
100 class CPTwentyFourIE(InfoExtractor):
101 IE_NAME = 'cp24'
102 _GEO_COUNTRIES = ['CA']
103 _VALID_URL = r'https?://(?:www\.)?cp24\.com/news/(?P<id>[^?#]+)'
105 _TESTS = [{
106 'url': 'https://www.cp24.com/news/video-shows-atm-being-ripped-out-of-business-by-pickup-truck-driver-in-mississauga-1.5676877',
107 'info_dict': {
108 'id': '2328005',
109 'ext': 'mp4',
110 'title': 'WATCH: Truck rips ATM from Mississauga business',
111 'description': 'md5:cf7498480885f080a754389a2b2f7073',
112 'timestamp': 1637618377,
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',
121 'params': {'skip_download': True, 'format': 'bv'},
124 def _real_extract(self, url):
125 display_id = self._match_id(url)
126 webpage = self._download_webpage(url, display_id)
127 video_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}:{video_id}', NineCNineMediaIE, video_id)