lib/youtube_search.rb in youtube_search-0.1.7 vs lib/youtube_search.rb in youtube_search-0.1.8
- old
+ new
@@ -17,13 +17,17 @@
def search_playlists(query, options={})
search_page("https://gdata.youtube.com/feeds/api/playlists/snippets", query, options.merge(:v => 2))
end
- def playlist_videos(playlist_id)
+ def playlist_videos(playlist_id, options={})
playlist_id = playlist_id.sub(/^PL/, "")
- xml = open("http://gdata.youtube.com/feeds/api/playlists/#{playlist_id}?v=2").read
- parse(xml, :type => :playlist)
+ res = open("http://gdata.youtube.com/feeds/api/playlists/#{playlist_id}?v=2#{'&alt=json' if options[:format] == :json}").read
+ if options[:format] == :json
+ res
+ else
+ parse(res, :type => :playlist)
+ end
end
def parse(xml, options={})
elements_in(xml, 'feed/entry').map do |element|
entry = xml_to_hash(element)