From 8d5e24bec324b0cb0c471d0a8d6daa657bd7d661 Mon Sep 17 00:00:00 2001 From: Walkyst <41806921+Walkyst@users.noreply.github.com> Date: Thu, 11 Aug 2022 13:46:28 +0300 Subject: [PATCH] Improve track converting --- .../client/source/ISRCAudioSourceManager.kt | 4 ++-- .../java/lavalink/client/source/ISRCAudioTrack.kt | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/lavalink/client/source/ISRCAudioSourceManager.kt b/src/main/java/lavalink/client/source/ISRCAudioSourceManager.kt index 66fb7c1..a232c09 100644 --- a/src/main/java/lavalink/client/source/ISRCAudioSourceManager.kt +++ b/src/main/java/lavalink/client/source/ISRCAudioSourceManager.kt @@ -14,8 +14,8 @@ abstract class ISRCAudioSourceManager constructor( ) : AudioSourceManager { val providers = arrayOf( - "ytmsearch:$ISRC_PATTERN", - "ytmsearch:$QUERY_PATTERN" + "ytsearch:$ISRC_PATTERN", + "ytsearch:$QUERY_PATTERN" ) override fun loadItem(manager: AudioPlayerManager, reference: AudioReference): AudioItem? { diff --git a/src/main/java/lavalink/client/source/ISRCAudioTrack.kt b/src/main/java/lavalink/client/source/ISRCAudioTrack.kt index eaf2cff..2fb8f2f 100644 --- a/src/main/java/lavalink/client/source/ISRCAudioTrack.kt +++ b/src/main/java/lavalink/client/source/ISRCAudioTrack.kt @@ -29,15 +29,15 @@ class ISRCAudioTrack( track = loadItem(provider) + if (track is AudioPlaylist) { + track = searchValidator(track) + } + if (track != null) { break } } - if (track is AudioPlaylist && searchValidator(track)) { - track = track.tracks[0] - } - when (track) { is InternalAudioTrack -> processDelegate(track, executor) else -> throw FriendlyException("No matching track found", FriendlyException.Severity.COMMON, TrackNotFoundException) @@ -76,9 +76,8 @@ class ISRCAudioTrack( return cf.join() } - private fun searchValidator(searchResult: AudioPlaylist): Boolean { - return trackInfo.length + TRACK_DIFFERENCE > searchResult.tracks[0].info.length - && searchResult.tracks[0].info.length > trackInfo.length - TRACK_DIFFERENCE + private fun searchValidator(playlist: AudioPlaylist): AudioTrack? { + return playlist.tracks.find { trackInfo.length + TRACK_DIFFERENCE > it.info.length && it.info.length > trackInfo.length - TRACK_DIFFERENCE } } companion object {