sealedtx / java-youtube-downloader

Simple, almost zero-dependency java parser for retrieving youtube video metadata
Other
426 stars 116 forks source link

Playlist Support #33

Closed mohammadnaushad closed 4 years ago

mohammadnaushad commented 4 years ago

Do you have any plans for playlist support?

sealedtx commented 4 years ago

@mohammadnaushad what exactly do you mean by "playlist support"?

naushad3210 commented 4 years ago

It means .. if someone passes a url which belongs to a playlist like https://youtu.be/HdGp3-R6LEc?list=PLFRPNUj0az6RFv9HH7UgLIAGmXSfQXHxH He should be able to download the video or should be able to fetch all the video details in the playlist. Like all the video links in that playlist so that one can then send the link to download the video

sealedtx commented 4 years ago

@naushad3210 I don't have spare time to implement this feature, probably for next few weeks. But PRs are welcomed

Grodou commented 4 years ago

Hello,

I found 2 options, both use the window["ytInitialData"] JSON section. (Document and JSON sizes from an actual test suggested by @naushad3210)

  1. Use the watch page

    • https://www.youtube.com/watch?v=<video_id>&list=<playlist_id>
    • Document size: 566.12 ko
    • JSON size: 310.8 ko
    • 5 steps hierarchy contents.twoColumnWatchNextResults.playlist.playlist.contents[]
  2. Use the playlist page

    • https://www.youtube.com/playlist?list=<playlist_id>
    • Document size: 161.35 ko
    • JSON size: 71.1 ko
    • 14 steps hierarchy contents.twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer.contents[0].playlistVideoListRenderer.contents[]

Once the final "contents" elements are available, each video data can be retrieved via playlistPanelVideoRenderer:

I think 2. is the best approach for a getPlaylist(String id) method that returns a basic video list and let the user choose. Let me know if it's OK, I'll try to get back with a PR.

sealedtx commented 4 years ago

@Grodou Great, thank you for your research. I believe second approach is more suitable (as it is parsed from playlist page) despite its deep hierarchy. This implementation could be usefull, have a look. Will be glad to see your PR.

Grodou commented 4 years ago

Thanks for the suggestion, I actually made a first version based on this implementation. It works fine (get playlist details, get all videos), but does not have any "download" functionality yet. I'll make a PR (so you can tell if everything's fine or not), and complete it later.