aquelemiguel / parrot

šŸ¦œ A hassle-free, highly performant, self-hosted Discord music bot with YouTube and Spotify support. Powered by yt-dlp.
MIT License
136 stars 44 forks source link

Infinitely adding items to queue, even after bot is stopped. #250

Closed SimonStjernholm closed 4 months ago

SimonStjernholm commented 6 months ago

šŸ“ Description

I have decided to include two similar issues in the same gh-issue here.

When adding a playlist to the bot and the bot then leaves (using e.g. /leave), the bot continuously adds the requested playlist songs. Another issue here is that any YouTube mix-playlist breaks the bot, since it is a infinite generating playlist. Therefore it adds infinite amount of songs.

šŸŖœ Reproduction Steps

Issue 1 (bot continuously adds items to the queue even after leaving):

  1. use /play <YouTube playlist link>.
  2. use /leave
  3. Bot continues to add the playlist to the queue.

Issue 2 (Infinite YouTube mix-playlist):

  1. use /play <YouTube mix-playlist link>. (Only shows 25 videos in the YouTube sidebar - Take a look at the notes below)
  2. Queue gets filled infinitely by the above playlist.

Notes:

YouTube playlists use list=PLxxxxxxxxxx as an parameter. YouTube mix-playlists use list=RDxxxxxxxxxx as an parameter. YouTube mix playlists will be different from person to person after the first song. Due to every mix being different for each user. Typically mixes are recommended on the homepage and contains 25 songs, after a song has been played/skipped one new song will be added to the end of the queue. Mix-playlists can't be played itself, without having watch?v=xxxx defined aswell. Therefore there should always be an initial video.

ā„¹ Environment / Computer Info

šŸ“ø Screenshots

No response

SimonStjernholm commented 6 months ago

Fixes I have thought of myself, however this seems like some hacky ways and could properly be implemented in a better way. I could create a PR if this somehow is the solution you guys would like to go with.

Issue 1:

In play.rs, all QueryType::PlaylistLink handlers could be updated to check if an existing channel connection is established on the urls.iter():

for url in urls.iter() {
    let handler = call.lock().await;
    let cancel_playlist_addition = handler.current_connection().is_none();
    drop(handler);

    if cancel_playlist_addition {
        // End command execution when no more songs should be added.
        return Ok(());
    }
...
}

Issue 2:

in youtube.rs, the function ytdl_playlist() we could the check the url for the mix list parameter list=RDxxxxxxxxxx in that case, we could add the arg "--no-playlist" to the yt-dlp command to discard the playlist and only query for the song specificed. As stated in notes above mix-playlists can't be played itself, without having watch?v=xxxx defined aswell. Therefore there should always be an initial video.

Note: The above solution completely disallows the option to play youtube playlist mixes. However, if played anyways, unlimited numbers of songs would be added to the queue, and I guess the bot would crash at some point. Since you currently can't cancel playlist queue addition, I guess some kind of avoidance/limiting should be implemented.