From 44699d10dc8de9c6a338f4a8e5c63506ec4d2118 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Tue, 14 Feb 2023 01:06:38 +0530 Subject: [PATCH] [extractor/crunchyroll] Better message for premium videos Closes #6227 --- yt_dlp/extractor/crunchyroll.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/yt_dlp/extractor/crunchyroll.py b/yt_dlp/extractor/crunchyroll.py index 3c9f8bbf0e..7d356d673d 100644 --- a/yt_dlp/extractor/crunchyroll.py +++ b/yt_dlp/extractor/crunchyroll.py @@ -20,8 +20,12 @@ class CrunchyrollBaseIE(InfoExtractor): _NETRC_MACHINE = 'crunchyroll' params = None + @property + def is_logged_in(self): + return self._get_cookies(self._LOGIN_URL).get('etp_rt') + def _perform_login(self, username, password): - if self._get_cookies(self._LOGIN_URL).get('etp_rt'): + if self.is_logged_in: return upsell_response = self._download_json( @@ -46,7 +50,7 @@ class CrunchyrollBaseIE(InfoExtractor): }).encode('ascii')) if login_response['code'] != 'ok': raise ExtractorError('Login failed. Server message: %s' % login_response['message'], expected=True) - if not self._get_cookies(self._LOGIN_URL).get('etp_rt'): + if not self.is_logged_in: raise ExtractorError('Login succeeded but did not set etp_rt cookie') def _get_embedded_json(self, webpage, display_id): @@ -157,7 +161,10 @@ class CrunchyrollBetaIE(CrunchyrollBaseIE): f'{api_domain}/cms/v2{bucket}/episodes/{internal_id}', display_id, note='Retrieving episode metadata', query=params) if episode_response.get('is_premium_only') and not episode_response.get('playback'): - raise ExtractorError('This video is for premium members only.', expected=True) + if self.is_logged_in: + raise ExtractorError('This video is for premium members only', expected=True) + else: + self.raise_login_required('This video is for premium members only') stream_response = self._download_json( f'{api_domain}{episode_response["__links__"]["streams"]["href"]}', display_id,