lib/youtube_search.rb in youtube_search-0.1.10 vs lib/youtube_search.rb in youtube_search-0.2.0

- old
+ new

@@ -29,12 +29,19 @@ def user_channel_videos(channel_id, options={}) channel_id = channel_id.sub(/^UC/, "") videos "#{API_URL}/users/#{channel_id}/uploads?v=2", options[:format] end + def single(video_id, options={}) + options = options.merge(:key => 'entry') + videos "#{API_URL}/videos/#{video_id}", :xml, options + end + def parse(xml, options={}) - elements_in(xml, 'feed/entry').map do |element| + key = options[:key] || 'feed/entry' + + elements_in(xml, key).map do |element| entry = xml_to_hash(element) entry['video_id'] = if options[:type] == :playlist element.elements['*/yt:videoid'].text else entry['id'].split('/').last @@ -52,16 +59,16 @@ end end private - def videos(url, format) + def videos(url, format, options = {}) url += '&alt=json' if format == :json res = open(url).read if format == :json res else - parse res + parse res, options end end def elements_in(xml, selector) entries = []