5 from .common
import InfoExtractor
14 class CaracolTvPlayIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://play\.caracoltv\.com/videoDetails/(?P<id>[^/?#]+)'
16 _NETRC_MACHINE
= 'caracoltv-play'
19 'url': 'https://play.caracoltv.com/videoDetails/OTo4NGFmNjUwOWQ2ZmM0NTg2YWRiOWU0MGNhOWViOWJkYQ==',
21 'id': 'OTo4NGFmNjUwOWQ2ZmM0NTg2YWRiOWU0MGNhOWViOWJkYQ==',
22 'title': 'La teorĂa del promedio',
23 'description': 'md5:1cdd6d2c13f19ef0d9649ab81a023ac3',
27 'url': 'https://play.caracoltv.com/videoDetails/OTo3OWM4ZTliYzQxMmM0MTMxYTk4Mjk2YjdjNGQ4NGRkOQ==/ella?season=0',
29 'id': 'OTo3OWM4ZTliYzQxMmM0MTMxYTk4Mjk2YjdjNGQ4NGRkOQ==',
31 'description': 'md5:a639b1feb5ddcc0cff92a489b4e544b8',
35 'url': 'https://play.caracoltv.com/videoDetails/OTpiYTY1YTVmOTI5MzI0ZWJhOGZiY2Y3MmRlOWZlYmJkOA==/la-vuelta-al-mundo-en-80-risas-2022?season=0',
37 'id': 'OTpiYTY1YTVmOTI5MzI0ZWJhOGZiY2Y3MmRlOWZlYmJkOA==',
38 'title': 'La vuelta al mundo en 80 risas 2022',
39 'description': 'md5:e97aac36106e5c37ebf947b3350106a4',
43 'url': 'https://play.caracoltv.com/videoDetails/MzoxX3BwbjRmNjB1',
44 'only_matching': True,
49 def _extract_app_token(self
, webpage
):
50 config_js_path
= self
._search
_regex
(
51 r
'<script[^>]+src\s*=\s*"([^"]+coreConfig.js[^"]+)', webpage
, 'config js url', fatal
=False)
53 mediation_config
= {} if not config_js_path
else self
._search
_json
(
54 r
'mediation\s*:', self
._download
_webpage
(
55 urljoin('https://play.caracoltv.com/', config_js_path
), None, fatal
=False, note
='Extracting JS config'),
56 'mediation_config', None, transform_source
=js_to_json
, fatal
=False)
59 mediation_config
, ('live', 'key')) or '795cd9c089a1fc48094524a5eba85a3fca1331817c802f601735907c8bbb4f50'
60 secret
= traverse_obj(
61 mediation_config
, ('live', 'secret')) or '64dec00a6989ba83d087621465b5e5d38bdac22033b0613b659c442c78976fa0'
63 return base64
.b64encode(f
'{key}:{secret}'.encode()).decode()
65 def _perform_login(self
, email
, password
):
66 webpage
= self
._download
_webpage
('https://play.caracoltv.com/', None, fatal
=False)
67 app_token
= self
._extract
_app
_token
(webpage
)
69 bearer_token
= self
._download
_json
(
70 'https://eu-gateway.inmobly.com/applications/oauth', None, data
=b
'', note
='Retrieving bearer token',
71 headers
={'Authorization': f
'Basic {app_token}'})['token']
73 self
._USER
_TOKEN
= self
._download
_json
(
74 'https://eu-gateway.inmobly.com/user/login', None, note
='Performing login', headers
={
75 'Content-Type': 'application/json',
76 'Authorization': f
'Bearer {bearer_token}',
79 'device_id': str(uuid
.uuid4()),
88 }).encode())['user_token']
90 def _extract_video(self
, video_data
, series_id
=None, season_id
=None, season_number
=None):
91 formats
, subtitles
= self
._extract
_m
3u8_formats
_and
_subtitles
(video_data
['stream_url'], series_id
, 'mp4')
94 'id': video_data
['id'],
95 'title': video_data
.get('name'),
96 'description': video_data
.get('description'),
98 'subtitles': subtitles
,
99 'thumbnails': traverse_obj(
100 video_data
, ('extra_thumbs', ..., {'url': 'thumb_url', 'height': 'height', 'width': 'width'})),
101 'series_id': series_id
,
102 'season_id': season_id
,
103 'season_number': int_or_none(season_number
),
104 'episode_number': int_or_none(video_data
.get('item_order')),
105 'is_live': video_data
.get('entry_type') == 3,
108 def _extract_series_seasons(self
, seasons
, series_id
):
109 for season
in seasons
:
110 api_response
= self
._download
_json
(
111 'https://eu-gateway.inmobly.com/feed', series_id
, query
={'season_id': season
['id']},
112 headers
={'Authorization': f
'Bearer {self._USER_TOKEN}'})
114 season_number
= season
.get('order')
115 for episode
in api_response
['items']:
116 yield self
._extract
_video
(episode
, series_id
, season
['id'], season_number
)
118 def _real_extract(self
, url
):
119 series_id
= self
._match
_id
(url
)
121 if self
._USER
_TOKEN
is None:
122 self
._perform
_login
('guest@inmobly.com', 'Test@gus1')
124 api_response
= self
._download
_json
(
125 'https://eu-gateway.inmobly.com/feed', series_id
, query
={'include_ids': series_id
},
126 headers
={'Authorization': f
'Bearer {self._USER_TOKEN}'})['items'][0]
128 if not api_response
.get('seasons'):
129 return self
._extract
_video
(api_response
)
131 return self
.playlist_result(
132 self
._extract
_series
_seasons
(api_response
['seasons'], series_id
),
133 series_id
, **traverse_obj(api_response
, {
135 'description': 'description',