kylejginavan / youtube_it

An object-oriented Ruby wrapper for the YouTube GData API
http://groups.google.com/group/ruby-youtube-library
595 stars 223 forks source link

How to get more than 25 items in a playlist using youtube_it gem #245

Closed chandraprinovis closed 9 years ago

chandraprinovis commented 9 years ago

Dear Friends,

I'm trying to use the Youtube_it gem to pull in a list of videos and store the urls, but the built in objects are only giving me 25 items max each time. Does anyone know of a way to use this gem to do this? cp = Playlist.first(:reference => p.playlist_id) cp = Playlist.create if cp.nil? cp.reference = p.playlist_id cp.title = p.title cp.summary = p.summary cp.save

Video Import

  videos = client.playlist(p.playlist_id).videos
  current_ids = videos.collect{|v| v.unique_id}

could you tell me how to get maximum videos or all videos from the playlist?

with regards, C

teckliew commented 9 years ago

You can only get maximum of 50 items from the Youtube API. Try: cp = Playlist.first(:reference => p.playlist_id, :max_results => 50)

chandraprinovis commented 9 years ago

Hi Tekkenator, Thank you for replying. I solved it by checking out the other thread in the issues. def self.all_videos_from_playlist(playlist_id) all_videos = [] start_index, page_size = 1, 50

begin @client = YouTubeIt::Client.new(:dev_key => YOUTUBE_DEV_KEY) playlists = @client.playlists(YOUTUBE_SRC_USER) newest_videos = @client.playlist(playlist_id, {'start-index' => start_index, 'max-results' => page_size}).videos all_videos += newest_videos start_index += page_size end while newest_videos && newest_videos.size == page_size

all_videos end

The above code works fine.

With regards, c