youtube_search 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/Rakefile +3 -3
- data/Readme.md +4 -0
- data/lib/youtube_search.rb +59 -49
- data/lib/youtube_search/version.rb +1 -1
- data/spec/fixtures/playlist_search_google_developers.xml +1 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/youtube_search_spec.rb +24 -0
- metadata +6 -5
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require "bundler"
|
2
|
-
|
1
|
+
require "bundler/setup"
|
2
|
+
require "bundler/gem_tasks"
|
3
3
|
|
4
4
|
task :default do
|
5
5
|
sh "rspec spec/"
|
@@ -32,4 +32,4 @@ task :update_fixtures do
|
|
32
32
|
id = "5F23DAF4BFE3D14C"
|
33
33
|
xml = open("http://gdata.youtube.com/feeds/api/playlists/#{id}?v=2").read
|
34
34
|
File.open("spec/fixtures/playlist_#{id}.xml","w"){|f| f.write xml }
|
35
|
-
end
|
35
|
+
end
|
data/Readme.md
CHANGED
@@ -22,6 +22,7 @@ Usage
|
|
22
22
|
"content"=>"Top YouTube Videos on ...",
|
23
23
|
"updated"=>"2011-10-13T20:20:54.000Z",
|
24
24
|
"raw" => <REXML::Element ... >,
|
25
|
+
"embeddable" => true,
|
25
26
|
...
|
26
27
|
}
|
27
28
|
|
@@ -39,6 +40,9 @@ and [standard youtube options](http://code.google.com/apis/youtube/2.0/developer
|
|
39
40
|
id = YoutubeSearch.search('lolcats').first['video_id']
|
40
41
|
%{<iframe src="http://www.youtube.com/embed/#{id}" width=640 height=480 frameborder=0></iframe>}
|
41
42
|
|
43
|
+
### Searching playlists
|
44
|
+
YoutubeSearch.search_playlists('cats').first
|
45
|
+
|
42
46
|
### Retrieve videos by playlist ID
|
43
47
|
|
44
48
|
videos = YoutubeSearch.playlist_videos('5F23DAF4BFE3D14C')
|
data/lib/youtube_search.rb
CHANGED
@@ -3,69 +3,79 @@ require 'cgi'
|
|
3
3
|
require 'open-uri'
|
4
4
|
|
5
5
|
module YoutubeSearch
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
class << self
|
7
|
+
def search_page(page, query, options={})
|
8
|
+
options = options_with_per_page_and_page(options)
|
9
|
+
query = options.merge(:q => query).map{|k,v| "#{CGI.escape k.to_s}=#{CGI.escape v.to_s}" }.join('&')
|
10
|
+
xml = open("#{page}?#{query}").read
|
11
|
+
parse(xml)
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
parse(xml, :type => :playlist)
|
17
|
-
end
|
14
|
+
def search(query, options={})
|
15
|
+
search_page("http://gdata.youtube.com/feeds/api/videos", query, options)
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
entry['video_id'] = if options[:type] == :playlist
|
23
|
-
element.elements['*/yt:videoid'].text
|
24
|
-
else
|
25
|
-
entry['id'].split('/').last
|
26
|
-
end
|
18
|
+
def search_playlists(query, options={})
|
19
|
+
search_page("https://gdata.youtube.com/feeds/api/playlists/snippets", query, options.merge(:v => 2))
|
20
|
+
end
|
27
21
|
|
28
|
-
|
29
|
-
|
22
|
+
def playlist_videos(playlist_id)
|
23
|
+
playlist_id = playlist_id.sub(/^PL/, "")
|
24
|
+
xml = open("http://gdata.youtube.com/feeds/api/playlists/#{playlist_id}?v=2").read
|
25
|
+
parse(xml, :type => :playlist)
|
26
|
+
end
|
30
27
|
|
31
|
-
|
32
|
-
entry
|
28
|
+
def parse(xml, options={})
|
29
|
+
elements_in(xml, 'feed/entry').map do |element|
|
30
|
+
entry = xml_to_hash(element)
|
31
|
+
entry['video_id'] = if options[:type] == :playlist
|
32
|
+
element.elements['*/yt:videoid'].text
|
33
|
+
else
|
34
|
+
entry['id'].split('/').last
|
35
|
+
end
|
33
36
|
|
34
|
-
|
37
|
+
duration = element.elements['*/yt:duration']
|
38
|
+
entry['duration'] = duration.attributes['seconds'] if duration
|
35
39
|
|
36
|
-
|
37
|
-
|
38
|
-
end
|
40
|
+
no_embed = element.elements['yt:noembed'] || element.elements['yt:private']
|
41
|
+
entry['embeddable'] = !(no_embed)
|
39
42
|
|
40
|
-
|
43
|
+
entry['raw'] = element
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
doc = REXML::Document.new(xml)
|
45
|
-
doc.elements.each(selector) do |element|
|
46
|
-
entries << element
|
45
|
+
entry
|
46
|
+
end
|
47
47
|
end
|
48
|
-
entries
|
49
|
-
end
|
50
48
|
|
51
|
-
|
52
|
-
Hash[element.children.map do |child|
|
53
|
-
[child.name, child.text]
|
54
|
-
end]
|
55
|
-
end
|
49
|
+
private
|
56
50
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
51
|
+
def elements_in(xml, selector)
|
52
|
+
entries = []
|
53
|
+
doc = REXML::Document.new(xml)
|
54
|
+
doc.elements.each(selector) do |element|
|
55
|
+
entries << element
|
56
|
+
end
|
57
|
+
entries
|
63
58
|
end
|
64
59
|
|
65
|
-
|
66
|
-
|
60
|
+
def xml_to_hash(element)
|
61
|
+
Hash[element.children.map do |child|
|
62
|
+
[child.name, child.text]
|
63
|
+
end]
|
67
64
|
end
|
68
65
|
|
69
|
-
options
|
66
|
+
def options_with_per_page_and_page(options)
|
67
|
+
options = options.dup
|
68
|
+
if per_page = options.delete(:per_page)
|
69
|
+
options['max-results'] = per_page
|
70
|
+
else
|
71
|
+
per_page = options['max-results']
|
72
|
+
end
|
73
|
+
|
74
|
+
if per_page and page = options.delete(:page)
|
75
|
+
options['start-index'] = per_page.to_i * ([page.to_i, 1].max - 1)
|
76
|
+
end
|
77
|
+
|
78
|
+
options
|
79
|
+
end
|
70
80
|
end
|
71
81
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007' gd:etag='W/"CEIDR3c6fip7I2A9WhNTGUk."'><id>tag:youtube.com,2008:playlists:snippets</id><updated>2012-10-22T21:49:36.916Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#playlistLink'/><title>YouTube Playlists matching query: GoogleDevelopers</title><logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets?v=2'/><link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets/batch?v=2'/><link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets?q=GoogleDevelopers&start-index=11&max-results=10&v=2'/><link rel='service' type='application/atomsvc+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets?alt=atom-service&v=2'/><link rel='previous' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets?q=GoogleDevelopers&start-index=1&max-results=10&v=2'/><link rel='next' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets?q=GoogleDevelopers&start-index=21&max-results=10&v=2'/><author><name>YouTube</name><uri>http://www.youtube.com/</uri></author><generator version='2.1' uri='http://gdata.youtube.com'>YouTube data API</generator><openSearch:totalResults>6416</openSearch:totalResults><openSearch:startIndex>11</openSearch:startIndex><openSearch:itemsPerPage>10</openSearch:itemsPerPage><entry gd:etag='W/"D0UHRn47eCp7I2A9WhJWF08."'><id>tag:youtube.com,2008:playlist:snippet:PLB09682344C2F233B</id><published>2010-05-21T05:05:09.000Z</published><updated>2012-08-23T12:33:57.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#playlistLink'/><title>Google I/O 2010: Google TV Keynote, Day 2</title><summary/><content type='application/atom+xml;type=feed' src='https://gdata.youtube.com/feeds/api/playlists/PLB09682344C2F233B?v=2'/><link rel='related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/googledevelopers?v=2'/><link rel='alternate' type='text/html' href='https://www.youtube.com/playlist?list=PLB09682344C2F233B'/><link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets/PLB09682344C2F233B?v=2'/><author><name>GoogleDevelopers</name><uri>https://gdata.youtube.com/feeds/api/users/GoogleDevelopers</uri><yt:userId>_x5XG1OV2P6uZZ5FSM9Ttw</yt:userId></author><yt:countHint>10</yt:countHint><media:group><media:thumbnail url='http://i.ytimg.com/vi/ASZbArr7vdI/default.jpg' height='90' width='120' yt:name='default'/><media:thumbnail url='http://i.ytimg.com/vi/ASZbArr7vdI/mqdefault.jpg' height='180' width='320' yt:name='mqdefault'/><media:thumbnail url='http://i.ytimg.com/vi/ASZbArr7vdI/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/></media:group><yt:playlistId>PLB09682344C2F233B</yt:playlistId></entry><entry gd:etag='W/"CkMNRX47eCp7I2A9WhNTFEw."'><id>tag:youtube.com,2008:playlist:snippet:PL25BD62C6275E88F6</id><published>2012-08-23T16:36:50.000Z</published><updated>2012-10-16T18:01:34.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#playlistLink'/><title>Google Maps Developers Office Hours</title><summary/><content type='application/atom+xml;type=feed' src='https://gdata.youtube.com/feeds/api/playlists/PL25BD62C6275E88F6?v=2'/><link rel='related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/googledevelopers?v=2'/><link rel='alternate' type='text/html' href='https://www.youtube.com/playlist?list=PL25BD62C6275E88F6'/><link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets/PL25BD62C6275E88F6?v=2'/><author><name>GoogleDevelopers</name><uri>https://gdata.youtube.com/feeds/api/users/GoogleDevelopers</uri><yt:userId>_x5XG1OV2P6uZZ5FSM9Ttw</yt:userId></author><yt:countHint>19</yt:countHint><media:group><media:thumbnail url='http://i.ytimg.com/vi/ufOXzbUaUqM/default.jpg' height='90' width='120' yt:name='default'/><media:thumbnail url='http://i.ytimg.com/vi/ufOXzbUaUqM/mqdefault.jpg' height='180' width='320' yt:name='mqdefault'/><media:thumbnail url='http://i.ytimg.com/vi/ufOXzbUaUqM/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/></media:group><yt:playlistId>PL25BD62C6275E88F6</yt:playlistId></entry><entry gd:etag='W/"D0UHRn47eCp7I2A9WhJWF08."'><id>tag:youtube.com,2008:playlist:snippet:PL984E049E7F182FCF</id><published>2008-12-09T21:46:18.000Z</published><updated>2012-08-23T12:33:57.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#playlistLink'/><category scheme='http://gdata.youtube.com/schemas/2007/tags.cat' term='google'/><category scheme='http://gdata.youtube.com/schemas/2007/tags.cat' term='web'/><category scheme='http://gdata.youtube.com/schemas/2007/tags.cat' term='toolkit'/><category scheme='http://gdata.youtube.com/schemas/2007/tags.cat' term='developers'/><category scheme='http://gdata.youtube.com/schemas/2007/tags.cat' term='gwt'/><category scheme='http://gdata.youtube.com/schemas/2007/tags.cat' term='scenechronize'/><title>Google Web Toolkit Developers - Scenechronize</title><summary/><content type='application/atom+xml;type=feed' src='https://gdata.youtube.com/feeds/api/playlists/PL984E049E7F182FCF?v=2'/><link rel='related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/googledevelopers?v=2'/><link rel='alternate' type='text/html' href='https://www.youtube.com/playlist?list=PL984E049E7F182FCF'/><link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets/PL984E049E7F182FCF?v=2'/><author><name>GoogleDevelopers</name><uri>https://gdata.youtube.com/feeds/api/users/GoogleDevelopers</uri><yt:userId>_x5XG1OV2P6uZZ5FSM9Ttw</yt:userId></author><yt:countHint>3</yt:countHint><media:group><media:thumbnail url='http://i.ytimg.com/vi/2gqDsi8zRt4/default.jpg' height='90' width='120' yt:name='default'/><media:thumbnail url='http://i.ytimg.com/vi/2gqDsi8zRt4/mqdefault.jpg' height='180' width='320' yt:name='mqdefault'/><media:thumbnail url='http://i.ytimg.com/vi/2gqDsi8zRt4/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/></media:group><yt:playlistId>PL984E049E7F182FCF</yt:playlistId></entry><entry gd:etag='W/"CkAMRX47eCp7I2A9Wx9SFk0."'><id>tag:youtube.com,2008:playlist:snippet:PL8DEF2598B15EFB77</id><published>2007-09-14T20:57:44.000Z</published><updated>2010-12-06T01:59:44.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#playlistLink'/><category scheme='http://gdata.youtube.com/schemas/2007/tags.cat' term='google'/><category scheme='http://gdata.youtube.com/schemas/2007/tags.cat' term='developer'/><title>Google Developers' Day</title><summary>Presentations from Googles' Developers Days</summary><content type='application/atom+xml;type=feed' src='https://gdata.youtube.com/feeds/api/playlists/PL8DEF2598B15EFB77?v=2'/><link rel='related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/bragadocchio?v=2'/><link rel='alternate' type='text/html' href='https://www.youtube.com/playlist?list=PL8DEF2598B15EFB77'/><link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets/PL8DEF2598B15EFB77?v=2'/><author><name>Bill Slawski</name><uri>https://gdata.youtube.com/feeds/api/users/bragadocchio</uri><yt:userId>2yHp3FdmEhUk_FgbpNnfvw</yt:userId></author><yt:countHint>13</yt:countHint><media:group><media:thumbnail url='http://i.ytimg.com/vi/nU8DcBF-qo4/default.jpg' height='90' width='120' yt:name='default'/><media:thumbnail url='http://i.ytimg.com/vi/nU8DcBF-qo4/mqdefault.jpg' height='180' width='320' yt:name='mqdefault'/><media:thumbnail url='http://i.ytimg.com/vi/nU8DcBF-qo4/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/></media:group><yt:playlistId>PL8DEF2598B15EFB77</yt:playlistId></entry><entry gd:etag='W/"Dk4NSH47eCp7I2A9WhJSGU0."'><id>tag:youtube.com,2008:playlist:snippet:PLA48C6EB915B66F8D</id><published>2012-07-10T07:23:16.000Z</published><updated>2012-07-10T07:23:19.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#playlistLink'/><title>Google Developers</title><summary>All About Google in the Future</summary><content type='application/atom+xml;type=feed' src='https://gdata.youtube.com/feeds/api/playlists/PLA48C6EB915B66F8D?v=2'/><link rel='related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/stylishhughes?v=2'/><link rel='alternate' type='text/html' href='https://www.youtube.com/playlist?list=PLA48C6EB915B66F8D'/><link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets/PLA48C6EB915B66F8D?v=2'/><author><name>Samuel Hughes Mensah</name><uri>https://gdata.youtube.com/feeds/api/users/stylishhughes</uri><yt:userId>vMYdnplOpcXhN5MA4ob40A</yt:userId></author><yt:countHint>94</yt:countHint><media:group><media:thumbnail url='http://i.ytimg.com/vi/lz0o-y-2wT0/default.jpg' height='90' width='120' yt:name='default'/><media:thumbnail url='http://i.ytimg.com/vi/lz0o-y-2wT0/mqdefault.jpg' height='180' width='320' yt:name='mqdefault'/><media:thumbnail url='http://i.ytimg.com/vi/lz0o-y-2wT0/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/></media:group><yt:playlistId>PLA48C6EB915B66F8D</yt:playlistId></entry><entry gd:etag='W/"CkQGQX47eCp7I2A9WhJTEkk."'><id>tag:youtube.com,2008:playlist:snippet:PL9B5858F8394F07D0</id><published>2012-05-05T09:33:35.000Z</published><updated>2012-06-21T00:58:40.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#playlistLink'/><title>Google Developers</title><summary/><content type='application/atom+xml;type=feed' src='https://gdata.youtube.com/feeds/api/playlists/PL9B5858F8394F07D0?v=2'/><link rel='related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/ice0812?v=2'/><link rel='alternate' type='text/html' href='https://www.youtube.com/playlist?list=PL9B5858F8394F07D0'/><link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets/PL9B5858F8394F07D0?v=2'/><author><name>joe newlon</name><uri>https://gdata.youtube.com/feeds/api/users/ice0812</uri><yt:userId>9D19bJ-0Xx9_X5uWbMU-mw</yt:userId></author><yt:countHint>72</yt:countHint><media:group><media:thumbnail url='http://i.ytimg.com/vi/BV1fVSR5J4M/default.jpg' height='90' width='120' yt:name='default'/><media:thumbnail url='http://i.ytimg.com/vi/BV1fVSR5J4M/mqdefault.jpg' height='180' width='320' yt:name='mqdefault'/><media:thumbnail url='http://i.ytimg.com/vi/BV1fVSR5J4M/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/></media:group><yt:playlistId>PL9B5858F8394F07D0</yt:playlistId></entry><entry gd:etag='W/"AkAHRn47eCp7I2A9WhJbFEQ."'><id>tag:youtube.com,2008:playlist:snippet:PLs7WEeL7y8wf1W10Im5luCnp64adzM3u-</id><published>2012-09-24T14:58:57.000Z</published><updated>2012-09-24T14:58:57.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#playlistLink'/><title>YouTube from GoogleDevelopers</title><summary/><content type='application/atom+xml;type=feed' src='https://gdata.youtube.com/feeds/api/playlists/PLs7WEeL7y8wf1W10Im5luCnp64adzM3u-?v=2'/><link rel='related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/theblasfable?v=2'/><link rel='alternate' type='text/html' href='https://www.youtube.com/playlist?list=PLs7WEeL7y8wf1W10Im5luCnp64adzM3u-'/><link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets/PLs7WEeL7y8wf1W10Im5luCnp64adzM3u-?v=2'/><author><name>theblasfable</name><uri>https://gdata.youtube.com/feeds/api/users/theblasfable</uri><yt:userId>76IuAeFfArYFZB-nPy92KA</yt:userId></author><yt:countHint>31</yt:countHint><media:group><media:thumbnail url='http://i.ytimg.com/vi/_UNgokP71tw/default.jpg' height='90' width='120' yt:name='default'/><media:thumbnail url='http://i.ytimg.com/vi/_UNgokP71tw/mqdefault.jpg' height='180' width='320' yt:name='mqdefault'/><media:thumbnail url='http://i.ytimg.com/vi/_UNgokP71tw/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/></media:group><yt:playlistId>PLs7WEeL7y8wf1W10Im5luCnp64adzM3u-</yt:playlistId></entry><entry gd:etag='W/"A0QCSX47eCp7I2A9WhZXGUo."'><id>tag:youtube.com,2008:playlist:snippet:PL786D56F1537CB52D</id><published>2007-06-06T21:06:04.000Z</published><updated>2011-05-09T22:16:08.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#playlistLink'/><category scheme='http://gdata.youtube.com/schemas/2007/tags.cat' term='Google'/><category scheme='http://gdata.youtube.com/schemas/2007/tags.cat' term='Developer'/><category scheme='http://gdata.youtube.com/schemas/2007/tags.cat' term='Day'/><category scheme='http://gdata.youtube.com/schemas/2007/tags.cat' term='US'/><title>Mountain View, California</title><summary>Videos from Google Developer Day US</summary><content type='application/atom+xml;type=feed' src='https://gdata.youtube.com/feeds/api/playlists/PL786D56F1537CB52D?v=2'/><link rel='related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/googledeveloperday?v=2'/><link rel='alternate' type='text/html' href='https://www.youtube.com/playlist?list=PL786D56F1537CB52D'/><link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets/PL786D56F1537CB52D?v=2'/><author><name>GoogleDeveloperDay</name><uri>https://gdata.youtube.com/feeds/api/users/GoogleDeveloperDay</uri><yt:userId>wPuf8AroS2fpl83oqsfC6A</yt:userId></author><yt:countHint>25</yt:countHint><media:group><media:thumbnail url='http://i.ytimg.com/vi/the0KZLEacs/default.jpg' height='90' width='120' yt:name='default'/><media:thumbnail url='http://i.ytimg.com/vi/the0KZLEacs/mqdefault.jpg' height='180' width='320' yt:name='mqdefault'/><media:thumbnail url='http://i.ytimg.com/vi/the0KZLEacs/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/></media:group><yt:playlistId>PL786D56F1537CB52D</yt:playlistId></entry><entry gd:etag='W/"C0YNR347eCp7I2A9Wx5WFUg."'><id>tag:youtube.com,2008:playlist:snippet:PL50614930B7092B22</id><published>2009-04-10T13:50:48.000Z</published><updated>2010-09-27T01:33:16.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#playlistLink'/><title>Google Developers</title><summary>Interesting videos from the Google developers</summary><content type='application/atom+xml;type=feed' src='https://gdata.youtube.com/feeds/api/playlists/PL50614930B7092B22?v=2'/><link rel='related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/thepoint75?v=2'/><link rel='alternate' type='text/html' href='https://www.youtube.com/playlist?list=PL50614930B7092B22'/><link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets/PL50614930B7092B22?v=2'/><author><name>thepoint75</name><uri>https://gdata.youtube.com/feeds/api/users/thepoint75</uri><yt:userId>OpHdyIJQNyaaKeQ3N8p3Kg</yt:userId></author><yt:countHint>14</yt:countHint><media:group><media:thumbnail url='http://i.ytimg.com/vi/ZeO_J2OcHYM/default.jpg' height='90' width='120' yt:name='default'/><media:thumbnail url='http://i.ytimg.com/vi/ZeO_J2OcHYM/mqdefault.jpg' height='180' width='320' yt:name='mqdefault'/><media:thumbnail url='http://i.ytimg.com/vi/ZeO_J2OcHYM/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/></media:group><yt:playlistId>PL50614930B7092B22</yt:playlistId></entry><entry gd:etag='W/"CEIFQ347eCp7I2A9WxJTEks."'><id>tag:youtube.com,2008:playlist:snippet:PL313DE5487FECDE4C</id><published>2008-03-31T21:54:19.000Z</published><updated>2009-04-20T21:21:52.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#playlistLink'/><title>Google Developers</title><summary>Google Developers</summary><content type='application/atom+xml;type=feed' src='https://gdata.youtube.com/feeds/api/playlists/PL313DE5487FECDE4C?v=2'/><link rel='related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/marianarcissa?v=2'/><link rel='alternate' type='text/html' href='https://www.youtube.com/playlist?list=PL313DE5487FECDE4C'/><link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/playlists/snippets/PL313DE5487FECDE4C?v=2'/><author><name>marianarcissa</name><uri>https://gdata.youtube.com/feeds/api/users/marianarcissa</uri><yt:userId>HOnhiK1dj8TQoFIfR1azGQ</yt:userId></author><yt:countHint>3</yt:countHint><media:group><media:thumbnail url='http://i.ytimg.com/vi/kNXdfjUYGAo/default.jpg' height='90' width='120' yt:name='default'/><media:thumbnail url='http://i.ytimg.com/vi/kNXdfjUYGAo/mqdefault.jpg' height='180' width='320' yt:name='mqdefault'/><media:thumbnail url='http://i.ytimg.com/vi/kNXdfjUYGAo/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/></media:group><yt:playlistId>PL313DE5487FECDE4C</yt:playlistId></entry></feed>
|
data/spec/spec_helper.rb
CHANGED
data/spec/youtube_search_spec.rb
CHANGED
@@ -51,6 +51,16 @@ describe YoutubeSearch do
|
|
51
51
|
video["video_id"].should == "5wU-yHnq7Hs"
|
52
52
|
video["raw"].elements.should_not == nil
|
53
53
|
end
|
54
|
+
|
55
|
+
it "can parse xml from playlists search" do
|
56
|
+
playlists = YoutubeSearch.parse(File.read('spec/fixtures/playlist_search_google_developers.xml'))
|
57
|
+
playlists.size.should == 10
|
58
|
+
playlists[0]["id"].should == "tag:youtube.com,2008:playlist:snippet:PLB09682344C2F233B"
|
59
|
+
playlists[0]["published"].should == "2010-05-21T05:05:09.000Z"
|
60
|
+
playlists[0]["updated"].should == "2012-08-23T12:33:57.000Z"
|
61
|
+
playlists[0]["title"].should == "Google I/O 2010: Google TV Keynote, Day 2"
|
62
|
+
playlists[0]["playlistId"].should == "PLB09682344C2F233B"
|
63
|
+
end
|
54
64
|
end
|
55
65
|
|
56
66
|
describe 'search' do
|
@@ -71,6 +81,20 @@ describe YoutubeSearch do
|
|
71
81
|
end
|
72
82
|
end
|
73
83
|
|
84
|
+
describe 'search_playlists' do
|
85
|
+
it "can search playlists" do
|
86
|
+
YoutubeSearch.search_playlists('GoogleDevelopers').size.should == 25
|
87
|
+
end
|
88
|
+
|
89
|
+
it "can search with options" do
|
90
|
+
YoutubeSearch.search_playlists('GoogleDevelopers', 'max-results' => 2).size.should == 2
|
91
|
+
end
|
92
|
+
|
93
|
+
it "can search with :per_page" do
|
94
|
+
YoutubeSearch.search('GoogleDevelopers', :per_page => 2).size.should == 2
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
74
98
|
describe 'playlist_videos' do
|
75
99
|
it "can retrieve videos from a playlist" do
|
76
100
|
YoutubeSearch.playlist_videos('5F23DAF4BFE3D14C').size.should == 6
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: youtube_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-10-23 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: michael@grosser.it
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- lib/youtube_search.rb
|
26
26
|
- lib/youtube_search/version.rb
|
27
27
|
- spec/fixtures/playlist_5F23DAF4BFE3D14C.xml
|
28
|
+
- spec/fixtures/playlist_search_google_developers.xml
|
28
29
|
- spec/fixtures/search_boat.xml
|
29
30
|
- spec/spec_helper.rb
|
30
31
|
- spec/youtube_search_spec.rb
|
@@ -43,7 +44,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
44
|
version: '0'
|
44
45
|
segments:
|
45
46
|
- 0
|
46
|
-
hash:
|
47
|
+
hash: 3459774421514102867
|
47
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
49
|
none: false
|
49
50
|
requirements:
|
@@ -52,10 +53,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
53
|
version: '0'
|
53
54
|
segments:
|
54
55
|
- 0
|
55
|
-
hash:
|
56
|
+
hash: 3459774421514102867
|
56
57
|
requirements: []
|
57
58
|
rubyforge_project:
|
58
|
-
rubygems_version: 1.8.
|
59
|
+
rubygems_version: 1.8.24
|
59
60
|
signing_key:
|
60
61
|
specification_version: 3
|
61
62
|
summary: Search youtube via this simple ruby api
|