Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry system for expired Youtube ciphers (403) #631

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix ClassCastException if not using default Youtube track details loader
  • Loading branch information
Demeng7215 authored and Demeng7215 committed May 31, 2021
commit 29eecb1387be8327855cab201397270b62d1bb81
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,26 @@ private void attemptProcess(TrackStateListener listener) {
if (e.getMessage().contains("Not success status code: 403")
&& (lastRetry == -1 || lastRetry + RETRY_COOLDOWN <= System.currentTimeMillis())
&& audioTrack.getSourceManager() instanceof YoutubeAudioSourceManager) {
lastRetry = System.currentTimeMillis();

log.debug("Detected 403, clearing cipher cache and retrying.");

YoutubeAudioSourceManager sourceManager = (YoutubeAudioSourceManager) audioTrack.getSourceManager();
DefaultYoutubeTrackDetailsLoader trackDetailsLoader = (DefaultYoutubeTrackDetailsLoader) sourceManager.getTrackDetailsLoader();
DefaultYoutubeTrackDetailsLoader.CachedPlayerScript cachedScript = trackDetailsLoader.getCachedPlayerScript();

// Clear cached scripts and ciphers.
if (cachedScript != null) {
((YoutubeSignatureCipherManager) sourceManager.getSignatureResolver()).clearCache(cachedScript.getPlayerScriptUrl());
trackDetailsLoader.clearCache();
}
if (sourceManager.getTrackDetailsLoader() instanceof DefaultYoutubeTrackDetailsLoader) {
log.debug("Detected 403, clearing cipher cache and retrying.");
lastRetry = System.currentTimeMillis();

DefaultYoutubeTrackDetailsLoader trackDetailsLoader = (DefaultYoutubeTrackDetailsLoader) sourceManager.getTrackDetailsLoader();
DefaultYoutubeTrackDetailsLoader.CachedPlayerScript cachedScript = trackDetailsLoader.getCachedPlayerScript();

// Attempt to process again.
attemptProcess(listener);
return;
// Clear cached scripts and ciphers.
if (cachedScript != null) {
((YoutubeSignatureCipherManager) sourceManager.getSignatureResolver()).clearCache(cachedScript.getPlayerScriptUrl());
trackDetailsLoader.clearCache();
}

// Attempt to process again.
attemptProcess(listener);
return;
}
}

// Temporarily clear the interrupted status so it would not disrupt listener methods.
Expand Down