ParticleCore / Particle

Home of the extension YouTube Plus that allows you to experience more on YouTube
Other
1.06k stars 228 forks source link

[feature] Add To Playlist button on video thumbnails #534

Closed MattSturgeon closed 7 years ago

MattSturgeon commented 7 years ago

Summary

It would be really useful to be able to add videos to playlists without first opening/playing the video. I briefly investigated this in YePpHa/YouTubeCenter/issues/1865 before discovering this project (see discussion there for further explanation and images).

Personally I would like to replace the WatchLater button with the old Add button. It would also be ok to create an Add To Playlist button in the triple-dot menu, but IMO that is an extra unnecessary click.

The WatchLater button still has styles to render a + icon if you simply strip it of the addto-watch-later-button class (although the sizing might need adjusting):

image


Investigation

Below I detail some of the useful ajax requests for adding a video to a playlist. Hopefully it is helpful.

For all requests youtube send a session_token, which appears to be unnecessary (I assume because auth headers are included by XHR anyway).

Getting the dropdown menu source code

To get the html send a POST request to https://www.youtube.com/addto_ajax?action_get_dropdown=1&hide_watch_later=false with url-encoded form data video_ids (the video id).

The response will be XML which has a node containing the HTML text to use in the menu.

Adding the video to a clicked playlist

To add the video to one of the playlists, send a POST request to https://www.youtube.com/playlist_video_ajax?action_add_to_playlist=1 with url encoded form data video_ids (same as action_get_dropdown) and full_list_id (the playlist full-id). Youtube also send plid which appears to be a short form of the playlist id, not sure if this is needed.

The response will be json either {"code":"SUCCESS"} or some error.

Removing the video from a clicked playlist

To remove the video from one of the playlists, send a POST request to https://www.youtube.com/playlist_video_ajax?action_delete_from_playlist=1 with everything the same as action_add_to_playlist above.

MattSturgeon commented 7 years ago

Closing in favour of ParticleCore/Iridium/issues/76