Skip to content

Commit 5d5796c

Browse files
committed
Issue #408 fix " ERRORE PREMIUM"
1 parent 5d91277 commit 5d5796c

File tree

3 files changed

+52
-14
lines changed

3 files changed

+52
-14
lines changed

StreamingCommunity/Api/Site/crunchyroll/film.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,21 @@ def download_film(select_title: MediaItem) -> str:
5454

5555
# Generate mpd and license URLs
5656
url_id = select_title.get('url').split('/')[-1]
57-
mpd_url, mpd_headers, mpd_list_sub, token, audio_locale = get_playback_session(client, url_id)
57+
58+
# Get playback session
59+
try:
60+
playback_result = get_playback_session(client, url_id)
61+
62+
# Check if access was denied (403)
63+
if playback_result is None:
64+
console.print("[bold red]✗ Access denied:[/bold red] This content requires a premium subscription")
65+
return None, False
66+
67+
mpd_url, mpd_headers, mpd_list_sub, token, audio_locale = playback_result
68+
69+
except Exception as e:
70+
console.print(f"[bold red]✗ Error getting playback session:[/bold red] {str(e)}")
71+
return None, False
5872

5973
# Parse playback token from mpd_url
6074
parsed_url = urlparse(mpd_url)

StreamingCommunity/Api/Site/crunchyroll/series.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,22 @@ def download_video(index_season_selected: int, index_episode_selected: int, scra
6868
# Generate mpd and license URLs
6969
url_id = obj_episode.get('url').split('/')[-1]
7070

71-
# Get playback session with token for cleanup
72-
mpd_url, mpd_headers, mpd_list_sub, token, audio_locale = get_playback_session(client, url_id)
71+
# Get playback session
72+
try:
73+
# Get playback session with token for cleanup
74+
playback_result = get_playback_session(client, url_id)
75+
76+
# Check if access was denied (403)
77+
if playback_result is None:
78+
console.print("[bold red]✗ Access denied:[/bold red] This episode requires a premium subscription")
79+
return None, False
80+
81+
mpd_url, mpd_headers, mpd_list_sub, token, audio_locale = playback_result
82+
83+
except Exception as e:
84+
console.print(f"[bold red]✗ Error getting playback session:[/bold red] {str(e)}")
85+
return None, False
86+
7387
parsed_url = urlparse(mpd_url)
7488
query_params = parse_qs(parsed_url.query)
7589

StreamingCommunity/Api/Site/crunchyroll/util/get_license.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
DEFAULT_SLOWDOWN_AFTER = 50 # Number of requests before introducing slowdown
2121

2222

23+
class PlaybackError(Exception):
24+
"""Custom exception for playback-related errors that shouldn't crash the program"""
25+
pass
26+
27+
2328
class RateLimiter:
2429
"""Simple token-bucket rate limiter to avoid server-side throttling."""
2530
def __init__(self, qps: float):
@@ -209,26 +214,30 @@ def _request_with_retry(self, method: str, url: str, **kwargs):
209214

210215
return response
211216

212-
def get_streams(self, media_id: str) -> Dict:
213-
"""Get available streams for media_id."""
217+
def get_streams(self, media_id: str) -> Optional[Dict]:
218+
"""
219+
Get available streams for media_id.
220+
"""
214221
response = self._request_with_retry(
215222
'GET',
216223
f'{BASE_URL}/playback/v3/{media_id}/web/chrome/play',
217224
params={'locale': self.locale}
218225
)
219226

220227
if response.status_code == 403:
221-
raise Exception("Playback Rejected: Subscription does not have access to this content")
228+
logging.warning(f"Access denied for media {media_id}: Subscription required")
229+
return None
222230

223231
if response.status_code == 420:
224-
raise Exception("TOO_MANY_ACTIVE_STREAMS. Wait a few minutes and try again.")
232+
raise PlaybackError("TOO_MANY_ACTIVE_STREAMS. Wait a few minutes and try again.")
225233

226234
response.raise_for_status()
227235

228236
data = response.json()
229237

230238
if data.get('error') == 'Playback is Rejected':
231-
raise Exception("Playback Rejected: Premium required")
239+
logging.warning(f"Playback rejected for media {media_id}: Premium required")
240+
return None
232241

233242
return data
234243

@@ -270,18 +279,19 @@ def _find_token_anywhere(obj) -> Optional[str]:
270279
return None
271280

272281

273-
def get_playback_session(client: CrunchyrollClient, url_id: str) -> Tuple[str, Dict, List[Dict], Optional[str], Optional[str]]:
282+
def get_playback_session(client: CrunchyrollClient, url_id: str) -> Optional[Tuple[str, Dict, List[Dict], Optional[str], Optional[str]]]:
274283
"""
275284
Return the playback session details.
276285
277286
Returns:
278-
- mpd_url: str
279-
- headers: Dict
280-
- subtitles: List[Dict] with metadata (kind, closed_caption, etc.)
281-
- token: Optional[str] for cleanup
282-
- audio_locale: Optional[str] current audio language
287+
Tuple with (mpd_url, headers, subtitles, token, audio_locale) or None if access denied
283288
"""
284289
data = client.get_streams(url_id)
290+
291+
# If get_streams returns None, it means access was denied (403)
292+
if data is None:
293+
return None
294+
285295
url = data.get('url')
286296
audio_locale_current = data.get('audio_locale') or data.get('audio', {}).get('locale')
287297

0 commit comments

Comments
 (0)