RobbieClarken / youtube-channel-to-playlist

Add all videos from a YouTube channel to a playlist
MIT License
30 stars 3 forks source link

Handle videos which are already in playlist #1

Closed thomasgassmann closed 6 years ago

thomasgassmann commented 6 years ago

Adds a switch to the command line, to skip videos, which already exist in the playlist.

RobbieClarken commented 6 years ago

Hi @ThomasGassmann, thanks for the contribution!

I'm happy to include this feature but it doesn't seem to be working for me. I've tried the following:

  1. Create a new playlist
  2. Populate it with channel_to_playlist
  3. Delete the *-added-videos file
  4. Run channel_to_playlist with --skip_existing True

I find that the videos are just added a second time to the playlist. Could there be some setting you have turned on for your playlist to reject duplicates?

thomasgassmann commented 6 years ago

Hi @RobbieClarken, I've just tried to reproduce your error. And according to my investigation, it seems as if YouTube treats the watch later playlist (ID being "WL") differently than all the other playlists. While it is adding the videos twice on a regular playlist, it is throwing the 409 conflict error in the WL playlist. Can you reproduce this behaviour in your WL playlist?

Right now I am even getting the following response from my WL playlist, which seems kind of weird: <HttpError 500 when requesting https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&alt=json returned "Backend Error"> I will try to investigate that a little further this weekend and will follow up on this PR.

RobbieClarken commented 6 years ago

Can you reproduce this behaviour in your WL playlist?

Aha! I do get 409 when adding to my Watch Later playlist and your --skip-existing flag then works as expected.

If we are to add a --skip-existing flag it should work for both Watch Later and regular playlists. So the options are:

  1. Remove the --skip-existing option but retain the exception handling of 409's. Perhaps just log the exception as it contains the helpful explanation "Video already in playlist.".
  2. Keep the --skip-existing option and query youtube for which videos are already in the playlist and skip adding them for all types of playlists. If we go down this route I think the default for --skip-existing should be True.

I'm happy with either approach. What do you think?

thomasgassmann commented 6 years ago

I've decided to implement approach 2, because it avoids a 409 response and seems like a cleaner solution to me. See 2dcb31a for these changes.

RobbieClarken commented 6 years ago

Thanks @ThomasGassmann! I made a few changes before merging (hope you don't mind):