From f576c41e5b45295ca282d19cd761d033effc9e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Sola?= Date: Mon, 4 Oct 2021 09:40:14 +0200 Subject: [PATCH] [atresplayer] fix extraction --- yt_dlp/extractor/atresplayer.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/yt_dlp/extractor/atresplayer.py b/yt_dlp/extractor/atresplayer.py index 4d0cb4f85..4dc4b405d 100644 --- a/yt_dlp/extractor/atresplayer.py +++ b/yt_dlp/extractor/atresplayer.py @@ -70,9 +70,19 @@ def _login(self): def _real_extract(self, url): display_id, video_id = self._match_valid_url(url).groups() + page = self._download_webpage(url, video_id, 'Downloading video page') + preloaded_state_regex = r'window\.__PRELOADED_STATE__\s*=\s*(\{(.*?)\});' + preloaded_state_text = self._html_search_regex(preloaded_state_regex, page, 'preloaded state') + preloaded_state = self._parse_json(preloaded_state_text, video_id) + link_info = next(iter(preloaded_state['links'].values())) + try: - episode = self._download_json( - self._API_BASE + 'client/v1/player/episode/' + video_id, video_id) + metadata = self._download_json(link_info['href'], video_id) + except ExtractorError as e: + self._handle_error(e, 403) + + try: + episode = self._download_json(metadata['urlVideo'], video_id) except ExtractorError as e: self._handle_error(e, 403)