Skip to content

Commit

Permalink
Fix weird exception handling logic in YoutubeAudioTrack
Browse files Browse the repository at this point in the history
  • Loading branch information
devoxin committed Dec 26, 2024
1 parent ba25e92 commit 4a685e2
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
public class YoutubeAudioTrack extends DelegatedAudioTrack {
private static final Logger log = LoggerFactory.getLogger(YoutubeAudioTrack.class);

// This field is used to determine at what point should a stream be discarded.
// If an error is thrown and the executor's position is larger than this number,
// the stream URL will not be renewed.
public static long BAD_STREAM_POSITION_THRESHOLD_MS = 3000;

private final YoutubeAudioSourceManager sourceManager;

/**
Expand Down Expand Up @@ -90,10 +95,15 @@ public void process(LocalAudioTrackExecutor localExecutor) throws Exception {
if ("Not success status code: 403".equals(message) ||
"Invalid status code for player api response: 400".equals(message) ||
(message != null && message.contains("No supported audio streams available"))) {
continue; // try next client
// As long as the executor position has not surpassed the threshold for which
// a stream is considered unrecoverable, we can try to renew the playback URL with
// another client.
if (localExecutor.getPosition() <= BAD_STREAM_POSITION_THRESHOLD_MS) {
continue;
}
}

throw e; // Unhandled exception, just throw.
throw e; // Unhandled exception, just rethrow.
}
}

Expand Down Expand Up @@ -129,17 +139,6 @@ private void processWithClient(LocalAudioTrackExecutor localExecutor,
}
} catch (StreamExpiredException e) {
processWithClient(localExecutor, httpInterface, client, e.lastStreamPosition);
} catch (RuntimeException e) {
if ("Not success status code: 403".equals(e.getMessage())) {
if (localExecutor.getPosition() < 3000) {
throw e; // bad stream URL, try the next client.
}
}

// contains("No route to host") || contains("Read timed out")
// augmentedFormat.getFallback()

throw e;
}
}

Expand Down

0 comments on commit 4a685e2

Please sign in to comment.