Closed clr1107 closed 3 years ago
You're welcome to add this feature! I suggest to add a func (c *Client) GetPlaylist(url string) (*Playlist, error)
method.
:+1: Yup, I'll finish it in my project I'm working on right now, then fork it and add this feature, I'll leave this issue open I suppose for updates.
I've added a preliminary implementation of playlists, so far I've pretty much mirrored Video
's impl. So you can do
id := "PLqAfPOrmacr963ATEroh67fbvjmTzTEx5"
client := youtube.Client{}
p, err := client.GetPlaylist(id)
if err != nil {
panic(err)
}
header := fmt.Sprintf("Playlist %s by %s", p.Title, p.Author)
println(header)
println(strings.Repeat("=", len(header)) + "\n")
for k, v := range p.Videos {
fmt.Printf("(%d) %s - '%s'\n", k+1, v.Author, v.Title)
}
to simply enumerate the playlist. The only problem is that since the playlist endpoint only has basic information, such as title, author, description, and duration (and more) you cannot download them. So far, the only fix is to just re-fetch the video, using GetVideo
once you have its ID from the Playlist, but I'll work on a better implementation later.
This still has a benefit, even now, as requesting all the videos' data upfront when it won't be needed takes a significant amount of time - you can test it by simply getting all the IDs and then trying to fetch them all to print their titles.
The above example outputs, predictably
Playlist Public (The Band) Songs by jennifer varela
===================================================
(1) PUBLICTHEBAND - '4Her - PUBLIC'
(2) PUBLICTHEBAND - 'On My Mind - PUBLIC'
(3) PUBLICTHEBAND - 'I love U - PUBLIC'
(4) PUBLICTHEBAND - 'Perfect - PUBLIC'
.....
It's a pity that @clr1107 has no time to finish this feature. thank for his contribution. If anyone is interested to continue this feature, please reference to PR #105 and clr1107 's repo, I think he already did some great jobs, clone his repository to do some modification could be a good choice.
Hi, I'm developing a program in which I need to download a playlist of videos; so far I've found a YouTube API link to list all videos in a playlist, and it contains all the videos' Ids. For now, I've taken these ids, and then I can download the videos individually.
Do you have any plans to add this? I can perhaps work on it if you'd like, as it's not too large. Luckily, the API link contains lots of information for each video, so you wouldn't have to call
decodeUrl
, which at the moment I do.https://youtube.com/list_ajax?style=json&action_get_list=1&list={playlist-id}&hl=en
is the API url, I stole it from https://github.com/Tyrrrz/YoutubeExplode/blob/master/YoutubeExplode/ReverseEngineering/Responses/PlaylistResponse.csThe API's return objects are in the form