Skip to content

Commit

Permalink
Improve track converting
Browse files Browse the repository at this point in the history
  • Loading branch information
Walkyst committed Aug 11, 2022
1 parent be44f4a commit 8d5e24b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/lavalink/client/source/ISRCAudioTrack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8d5e24b

Please sign in to comment.