Skip to content

Commit

Permalink
skip empty playlist in track mirroring
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Sep 26, 2024
1 parent ae8f3d1 commit c574243
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.topi314.lavasrc.applemusic.AppleMusicSourceManager;
import com.github.topi314.lavasrc.spotify.SpotifySourceManager;
import com.sedmelluq.discord.lavaplayer.track.AudioItem;
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -24,7 +25,6 @@ public DefaultMirroringAudioTrackResolver(String[] providers) {

@Override
public AudioItem apply(MirroringAudioTrack mirroringAudioTrack) {
AudioItem track = AudioReference.NO_TRACK;
for (var provider : providers) {
if (provider.startsWith(SpotifySourceManager.SEARCH_PREFIX)) {
log.warn("Can not use spotify search as search provider!");
Expand All @@ -46,19 +46,22 @@ public AudioItem apply(MirroringAudioTrack mirroringAudioTrack) {
}

provider = provider.replace(MirroringAudioSourceManager.QUERY_PATTERN, getTrackTitle(mirroringAudioTrack));

AudioItem item;
try {
track = mirroringAudioTrack.loadItem(provider);
}
catch (Exception e) {
item = mirroringAudioTrack.loadItem(provider);
} catch (Exception e) {
log.error("Failed to load track from provider \"{}\"!", provider, e);
continue;
}
if (track != AudioReference.NO_TRACK) {
break;
// If the track is an empty playlist, skip the provider
if (item instanceof AudioPlaylist && ((AudioPlaylist) item).getTracks().isEmpty() || item == AudioReference.NO_TRACK) {
continue;
}
return item;
}

return track;
return AudioReference.NO_TRACK;
}

public String getTrackTitle(MirroringAudioTrack mirroringAudioTrack) {
Expand Down

0 comments on commit c574243

Please sign in to comment.