From 4a685e277b3c4dfcf73fe2108a757f9c823cdb07 Mon Sep 17 00:00:00 2001 From: Devoxin Date: Thu, 26 Dec 2024 17:27:54 +0000 Subject: [PATCH] Fix weird exception handling logic in YoutubeAudioTrack --- .../youtube/track/YoutubeAudioTrack.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/dev/lavalink/youtube/track/YoutubeAudioTrack.java b/common/src/main/java/dev/lavalink/youtube/track/YoutubeAudioTrack.java index 0fe4c1d..ed9c6a5 100644 --- a/common/src/main/java/dev/lavalink/youtube/track/YoutubeAudioTrack.java +++ b/common/src/main/java/dev/lavalink/youtube/track/YoutubeAudioTrack.java @@ -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; /** @@ -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. } } @@ -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; } }