2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
13 class NineCNineMediaIE(InfoExtractor
):
15 _GEO_COUNTRIES
= ['CA']
16 _VALID_URL
= r
'9c9media:(?P<destination_code>[^:]+):(?P<id>\d+)'
17 _API_BASE_TEMPLATE
= 'http://capi.9c9media.com/destinations/%s/platforms/desktop/contents/%s/'
19 def _real_extract(self
, url
):
20 destination_code
, content_id
= self
._match
_valid
_url
(url
).groups()
21 api_base_url
= self
._API
_BASE
_TEMPLATE
% (destination_code
, content_id
)
22 content
= self
._download
_json
(api_base_url
, content_id
, query
={
23 '$include': '[Media.Name,Season,ContentPackages.Duration,ContentPackages.Id]',
25 title
= content
['Name']
26 content_package
= content
['ContentPackages'][0]
27 package_id
= content_package
['Id']
28 content_package_url
= api_base_url
+ 'contentpackages/%s/' % package_id
29 content_package
= self
._download
_json
(
30 content_package_url
, content_id
, query
={
31 '$include': '[HasClosedCaptions]',
34 if (not self
.get_param('allow_unplayable_formats')
35 and try_get(content_package
, lambda x
: x
['Constraints']['Security']['Type'])):
36 self
.report_drm(content_id
)
38 manifest_base_url
= content_package_url
+ 'manifest.'
40 formats
.extend(self
._extract
_m
3u8_formats
(
41 manifest_base_url
+ 'm3u8', content_id
, 'mp4',
42 'm3u8_native', m3u8_id
='hls', fatal
=False))
43 formats
.extend(self
._extract
_f
4m
_formats
(
44 manifest_base_url
+ 'f4m', content_id
,
45 f4m_id
='hds', fatal
=False))
46 formats
.extend(self
._extract
_mpd
_formats
(
47 manifest_base_url
+ 'mpd', content_id
,
48 mpd_id
='dash', fatal
=False))
49 self
._sort
_formats
(formats
)
52 for image
in (content
.get('Images') or []):
53 image_url
= image
.get('Url')
58 'width': int_or_none(image
.get('Width')),
59 'height': int_or_none(image
.get('Height')),
62 tags
, categories
= [], []
63 for source_name
, container
in (('Tags', tags
), ('Genres', categories
)):
64 for e
in content
.get(source_name
, []):
65 e_name
= e
.get('Name')
68 container
.append(e_name
)
70 season
= content
.get('Season') or {}
75 'description': content
.get('Desc') or content
.get('ShortDesc'),
76 'timestamp': parse_iso8601(content
.get('BroadcastDateTime')),
77 'episode_number': int_or_none(content
.get('Episode')),
78 'season': season
.get('Name'),
79 'season_number': int_or_none(season
.get('Number')),
80 'season_id': season
.get('Id'),
81 'series': try_get(content
, lambda x
: x
['Media']['Name']),
83 'categories': categories
,
84 'duration': float_or_none(content_package
.get('Duration')),
86 'thumbnails': thumbnails
,
89 if content_package
.get('HasClosedCaptions'):
92 'url': manifest_base_url
+ 'vtt',
95 'url': manifest_base_url
+ 'srt',
103 class CPTwentyFourIE(InfoExtractor
):
105 _GEO_COUNTRIES
= ['CA']
106 _VALID_URL
= r
'https?://(?:www\.)?cp24\.com/news/(?P<id>[^?#]+)'
109 'url': 'https://www.cp24.com/news/video-shows-atm-being-ripped-out-of-business-by-pickup-truck-driver-in-mississauga-1.5676877',
113 'title': 'WATCH: Truck rips ATM from Mississauga business',
114 'description': 'md5:cf7498480885f080a754389a2b2f7073',
115 'timestamp': 1637618377,
116 'episode_number': None,
117 'season': 'Season 0',
120 'series': 'CTV News Toronto',
122 'thumbnail': 'http://images2.9c9media.com/image_asset/2014_11_5_2eb609a0-475b-0132-fbd6-34b52f6f1279_jpg_2000x1125.jpg',
123 'upload_date': '20211122',
125 'params': {'skip_download': True, 'format': 'bv'}
128 def _real_extract(self
, url
):
129 display_id
= self
._match
_id
(url
)
130 webpage
= self
._download
_webpage
(url
, display_id
)
131 id, destination
= self
._search
_regex
(
132 r
'getAuthStates\("(?P<id>[^"]+)",\s?"(?P<destination>[^"]+)"\);',
133 webpage
, 'video id and destination', group
=('id', 'destination'))
134 return self
.url_result(f
'9c9media:{destination}:{id}', ie
=NineCNineMediaIE
.ie_key(), video_id
=id)