yt
yt copied to clipboard
Remove video from playlists once it's deleted
I have a reference to a video that I delete. That works well.
myvideo = Yt::Video.new id: "abc123", auth: yt_account
myvideo.delete
Is there a way to find out what playlists (in my own account) that video belongs to, so I can delete the corresponding PlaylistItem 's? The YouTube web interface seems to allow this just looking at the video and un-checking the checkboxes for each playlist the video belongs to, but I'm not sure what the best practices are for viding those associated PlaylistItem's.
It looks like there's a way to fetch playlist items for a given video with the YouTube Data API, but at a glance Yt doesn't support this:
https://developers.google.com/youtube/v3/docs/playlistItems/list (see videoId
).
You could go in the other direction and for each item in each playlist, attempt to load the associated video, and if it's not found, delete that playlist item.
channel.playlist_items.each do |item|
item.delete if item.video_id == deleted_video_id
end
You could also delete playlist item whenever delete a video, I think it doesn't have to be supported as internal feature of Yt.