YT playlist how can i get all the videos from a playlist in Ruby

771 views Asked by At

i want to get all the videos that belongs to a youtube playlist. I'm trying the YT Gem http://fullscreen.github.io/yt/ but i can find a way to get all the videos from a playlist.

For instance i created a new object playlisitem :

item = Yt::PlaylistItem.new id: 'PLC02CFDE5690E4010'

    puts item.title
    puts item.description
    puts item.published_at  

This give me the following error

Yt::Errors::NoItems: A request to YouTube API returned no items but some were expected:

Maybe i need to create video "collections", but i don't know how.

http://www.rubydoc.info/gems/yt/Yt/Collections/Videos

Any help will be apreciated.

1

There are 1 answers

0
servatj On BEST ANSWER

The solution i found that works! (sorry)

playlist = Yt::Playlist.new id: 'PLC02CFDE5690E4010'
    puts playlist.id
    puts playlist.title
    puts playlist.description
    puts playlist.published_at  


    playlist.playlist_items.each do |item|
        puts item.video_id 
    end

I don really understand how the relations works magically in rails. I have to study the YT Gem source and improve my knowledge of ruby. :)