youtube_it 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,198 @@
1
+ == DESCRIPTION
2
+
3
+ youtube_it is the most complete Ruby client for the YouTube GData API. It provides an easy
4
+ way to access the latest and most complete access to YouTube's video API.
5
+ In comparison with the earlier Youtube interfaces, this new API and
6
+ library offers much-improved flexibility around executing complex search
7
+ queries to obtain well-targeted video search results. In addition, standard video management
8
+ including but not limited to uploading, deleting, updating, like, dislike, ratings and
9
+ comments.
10
+
11
+ == INSTALLATION & SETUP:
12
+ * Create a youtube account.
13
+ * Create a developer key here http://code.google.com/apis/youtube/dashboard.
14
+ * sudo gem install youtube_it
15
+
16
+ == ESTABLISHING A CLIENT
17
+
18
+ Creating a client:
19
+ $ require 'youtube_it'
20
+ $ client = YouTubeIt::Client.new
21
+
22
+ Client with developer key:
23
+ $ client = YouTubeIt::Client.new(:dev_key => "developer_key")
24
+
25
+ Client with youtube account and developer key:
26
+ $ client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
27
+
28
+ Client with OAuth:
29
+ $ client = YouTubeIt::OAuthClient.new("consumer_key", "consumer_secret", "youtube_username", "developer_key")
30
+ $ client.authorize_from_access("access_token", "access_secret")
31
+
32
+ == VIDEO QUERIES
33
+
34
+ Note: Each type of client enables searching capabilities.
35
+
36
+ Basic Queries:
37
+ $ client.videos_by(:query => "penguin")
38
+ $ client.videos_by(:query => "penguin", :page => 2, :per_page => 15)
39
+ $ client.videos_by(:tags => ['tiger', 'leopard'])
40
+ $ client.videos_by(:categories => [:news, :sports])
41
+ $ client.videos_by(:categories => [:news, :sports], :tags => ['soccer', 'football'])
42
+ $ client.videos_by(:user => 'liz')
43
+ $ client.videos_by(:favorites, :user => 'liz')
44
+ $ client.video_by("FQK1URcxmb4")
45
+ $ client.video_by_user("chebyte","FQK1URcxmb4")
46
+
47
+ Standard Queries:
48
+ $ client.videos_by(:most_viewed)
49
+ $ client.videos_by(:most_linked, :page => 3)
50
+ $ client.videos_by(:top_rated, :time => :today)
51
+
52
+ Advanced Queries (with boolean operators OR (either), AND (include), NOT (exclude)):
53
+ $ client.videos_by(:categories => { :either => [:news, :sports], :exclude => [:comedy] }, :tags => { :include => ['football'], :exclude => ['soccer'] })
54
+
55
+ == VIDEO MANAGEMENT
56
+
57
+ Note: YouTube account or OAuth enables video management.
58
+
59
+ Upload Video:
60
+ $ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test])
61
+
62
+ Upload Video With A Developer Tag (Note the tags are not immediately available):
63
+ $ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :dev_tag => 'tagdev')
64
+
65
+ Update Video:
66
+ $ client.video_update("FQK1URcxmb4", :title => "new test",:description => 'new description', :category => 'People',:keywords => %w[cool blah test])
67
+
68
+ Delete Video:
69
+ $ client.video_delete("FQK1URcxmb4")
70
+
71
+ Profile Details:
72
+ $ client.profile(user_id)
73
+
74
+ List Comments:
75
+ $ client.comments(video_id)
76
+
77
+ Add A Comment:
78
+ $ client.add_comment(video_id, "test comment!")
79
+
80
+ List Favorites:
81
+ $ client.favorites
82
+
83
+ Add Favorite:
84
+ $ client.add_favorite(video_id)
85
+
86
+ Delete Favorite:
87
+ $ client.delete_favorite(video_id)
88
+
89
+ List Playlists:
90
+ $ client.playlists
91
+
92
+ Select Playlist:
93
+ $ client.playlist(playlist_id)
94
+
95
+ Select All Videos From A Playlist:
96
+ $ playlist = client.playlist(playlist_id)
97
+ $ playlist.videos
98
+
99
+ Create Playlist:
100
+ $ playlist = client.add_playlist(:title => "new playlist", :description => "playlist description")
101
+
102
+ Delete Playlist:
103
+ $ client.delete_playlist(playlist_id)
104
+
105
+ Add Video To Playlist:
106
+ $ client.add_video_to_playlist(playlist_id, video_id)
107
+
108
+ Remove Video From Playlist:
109
+ $ client.remove_video_from_playlist(playlist_id, playlist_entry_id)
110
+
111
+ Select Playlists From User:
112
+ $ client.playlists_for(user)
113
+
114
+ == ACCESS CONTROL LIST
115
+
116
+ You can give permissions in your videos, for example denied comments, rate, etc...
117
+ you can read more there http://code.google.com/apis/youtube/2.0/reference.html#youtube_data_api_tag_yt:accessControl
118
+ you have available the followings options:
119
+
120
+ * :rate, :comment, :commentVote, :videoRespond, :list, :embed, :syndicate
121
+
122
+ with just two values:
123
+ * allowed or denied
124
+
125
+ Example
126
+
127
+ client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
128
+
129
+ * upload video with denied comments
130
+
131
+ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :comment => "denied")
132
+
133
+
134
+ == Video Upload From Browser:
135
+
136
+ When uploading a video from your browser you need make a form upload with the followings params:
137
+ $ upload_token(params, nexturl)
138
+ params => params like :title => "title", :description => "description", :category => "People", :tags => ["test"]
139
+ nexturl => redirect to this url after upload
140
+
141
+
142
+ Controller
143
+ def upload
144
+ @upload_info = YouTubeIt::Client.new.upload_token(params, videos_url)
145
+ end
146
+
147
+ View (upload.html.erb)
148
+ <% form_tag @upload_info[:url], :multipart => true do %>
149
+ <%= hidden_field_tag :token, @upload_info[:token] %>
150
+ <%= label_tag :file %>
151
+ <%= file_field_tag :file %>
152
+ <%= submit_tag "Upload video" %>
153
+ <% end %>
154
+
155
+ == WIDESCREEN VIDEOS
156
+
157
+ If the videos has support for widescreen:
158
+ $ video.embed_html_with_width(1280)
159
+
160
+ Note: you can specify width or just use the default of 1280.
161
+
162
+ == LOGGING
163
+
164
+ YouTubeIt passes all logs through the logger variable on the class itself. In Rails context, assign the Rails logger to that variable to collect the messages
165
+ (don't forget to set the level to debug):
166
+ $ YouTubeIt.logger = RAILS_DEFAULT_LOGGER
167
+ $ RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
168
+
169
+ == CONTRIBUTORS:
170
+
171
+ * Kyle J. Ginavan.
172
+ * Mauro Torres - http://github.com/chebyte
173
+ * Marko Seppa - https://github.com/mseppae
174
+
175
+ == LICENSE:
176
+
177
+ MIT License
178
+
179
+ Copyright (c) 2010 Kyle J. Ginavan
180
+
181
+ Permission is hereby granted, free of charge, to any person obtaining
182
+ a copy of this software and associated documentation files (the
183
+ 'Software'), to deal in the Software without restriction, including
184
+ without limitation the rights to use, copy, modify, merge, publish,
185
+ distribute, sublicense, and/or sell copies of the Software, and to
186
+ permit persons to whom the Software is furnished to do so, subject to
187
+ the following conditions:
188
+
189
+ The above copyright notice and this permission notice shall be
190
+ included in all copies or substantial portions of the Software.
191
+
192
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
193
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
194
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
195
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
196
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
197
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
198
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/kylejginavan/youtube_it"
12
12
  gem.add_dependency('oauth','>=0.4.4')
13
13
  gem.add_dependency('builder')
14
- gem.authors = ["chebyte","kylejginavan"]
14
+ gem.authors = ["kylejginavan","chebyte", "mseppae"]
15
15
  end
16
16
  Jeweler::GemcutterTasks.new
17
17
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.0
1
+ 1.4.1
@@ -122,8 +122,6 @@ class YouTubeIt
122
122
  attr_reader :latitude
123
123
  attr_reader :longitude
124
124
 
125
- attr_reader :statistics
126
-
127
125
  # Videos related to the current video.
128
126
  #
129
127
  # === Returns
@@ -150,7 +148,7 @@ class YouTubeIt
150
148
  # === Returns
151
149
  # String: The Youtube video id.
152
150
  def unique_id
153
- video_id[/videos\/([^<]+)/, 1]
151
+ video_id[/videos\/([^<]+)/, 1] || video_id[/video\:([^<]+)/, 1]
154
152
  end
155
153
 
156
154
  # Allows you to check whether the video can be embedded on a webpage.
@@ -1,18 +1,18 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:yt="http://gdata.youtube.com/schemas/2007" gd:etag="W/&quot;A0UBR347eCp7ImA9Wx9bFEs.&quot;">
3
- <id>tag:youtube.com,2008:video:TESTVIDEO</id>
3
+ <id>tag:youtube.com,2008:video:AbC123DeFgH</id>
4
4
  <published>2010-12-29T13:57:49.000Z</published>
5
5
  <updated>2011-02-23T13:54:16.000Z</updated>
6
6
  <category scheme="http://schemas.google.com/g/2005#kind" term="http://gdata.youtube.com/schemas/2007#video"/>
7
7
  <category scheme="http://gdata.youtube.com/schemas/2007/categories.cat" term="Test" label="Test"/>
8
8
  <category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="test"/>
9
9
  <title>YouTube Test Video</title>
10
- <content type="application/x-shockwave-flash" src="http://www.youtube.com/v/YTTESTVIDEO?f=videos&amp;app=youtube_gdata"/>
11
- <link rel="alternate" type="text/html" href="http://www.youtube.com/watch?v=YTTESTVIDEO&amp;feature=youtube_gdata"/>
12
- <link rel="http://gdata.youtube.com/schemas/2007#video.responses" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/YTTESTVIDEO/responses?v=2"/>
13
- <link rel="http://gdata.youtube.com/schemas/2007#video.related" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/YTTESTVIDEO/related?v=2"/>
14
- <link rel="http://gdata.youtube.com/schemas/2007#mobile" type="text/html" href="http://m.youtube.com/details?v=YTTESTVIDEO"/>
15
- <link rel="self" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/YTTESTVIDEO?v=2"/>
10
+ <content type="application/x-shockwave-flash" src="http://www.youtube.com/v/YTAbC123DeF?f=videos&amp;app=youtube_gdata"/>
11
+ <link rel="alternate" type="text/html" href="http://www.youtube.com/watch?v=AbC123DeFgH&amp;feature=youtube_gdata"/>
12
+ <link rel="http://gdata.youtube.com/schemas/2007#video.responses" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/AbC123DeFgH/responses?v=2"/>
13
+ <link rel="http://gdata.youtube.com/schemas/2007#video.related" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/AbC123DeFgH/related?v=2"/>
14
+ <link rel="http://gdata.youtube.com/schemas/2007#mobile" type="text/html" href="http://m.youtube.com/details?v=AbC123DeFgH"/>
15
+ <link rel="self" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/AbC123DeFgH?v=2"/>
16
16
  <author>
17
17
  <name>Test user</name>
18
18
  <uri>http://gdata.youtube.com/feeds/api/users/test_user</uri>
@@ -25,27 +25,27 @@
25
25
  <yt:accessControl action="list" permission="allowed"/>
26
26
  <yt:accessControl action="syndicate" permission="allowed"/>
27
27
  <gd:comments>
28
- <gd:feedLink href="http://gdata.youtube.com/feeds/api/videos/YTTESTVIDEO/comments?v=2" countHint="1000"/>
28
+ <gd:feedLink href="http://gdata.youtube.com/feeds/api/videos/AbC123DeFgH/comments?v=2" countHint="1000"/>
29
29
  </gd:comments>
30
30
  <media:group>
31
31
  <media:category label="Sports" scheme="http://gdata.youtube.com/schemas/2007/categories.cat">Test</media:category>
32
- <media:content url="http://www.youtube.com/v/YTTESTVIDEO?f=videos&amp;app=youtube_gdata" type="application/x-shockwave-flash" medium="video" isDefault="true" expression="full" duration="356" yt:format="5"/>
33
- <media:content url="rtsp://v7.cache6.c.youtube.com/YTTESTCACHE/0/0/0/video.3gp" type="video/3gpp" medium="video" expression="full" duration="356" yt:format="1"/>
34
- <media:content url="rtsp://v8.cache7.c.youtube.com/YTTESTCACHE/0/0/0/video.3gp" type="video/3gpp" medium="video" expression="full" duration="356" yt:format="6"/>
32
+ <media:content url="http://www.youtube.com/v/AbC123DeFgH?f=videos&amp;app=youtube_gdata" type="application/x-shockwave-flash" medium="video" isDefault="true" expression="full" duration="356" yt:format="5"/>
33
+ <media:content url="rtsp://v7.cache6.c.youtube.com/TESTCACHE/0/0/0/video.3gp" type="video/3gpp" medium="video" expression="full" duration="356" yt:format="1"/>
34
+ <media:content url="rtsp://v8.cache7.c.youtube.com/TESTCACHE/0/0/0/video.3gp" type="video/3gpp" medium="video" expression="full" duration="356" yt:format="6"/>
35
35
  <media:credit role="uploader" scheme="urn:youtube" yt:type="partner">Test user</media:credit>
36
36
  <media:description type="plain">Youtube Test Video</media:description>
37
37
  <media:keywords>Test, Youtube, Youtube_it, Ruby</media:keywords>
38
- <media:player url="http://www.youtube.com/watch?v=YTTESTVIDEO&amp;feature=youtube_gdata_player"/>
39
- <media:thumbnail url="http://i.ytimg.com/vi/YTTESTVIDEO/default.jpg" height="90" width="120" time="00:02:58" yt:name="default"/>
40
- <media:thumbnail url="http://i.ytimg.com/vi/YTTESTVIDEO/hqdefault.jpg" height="360" width="480" yt:name="hqdefault"/>
41
- <media:thumbnail url="http://i.ytimg.com/vi/YTTESTVIDEO/1.jpg" height="90" width="120" time="00:01:29" yt:name="start"/>
42
- <media:thumbnail url="http://i.ytimg.com/vi/YTTESTVIDEO/2.jpg" height="90" width="120" time="00:02:58" yt:name="middle"/>
43
- <media:thumbnail url="http://i.ytimg.com/vi/YTTESTVIDEO/3.jpg" height="90" width="120" time="00:04:27" yt:name="end"/>
38
+ <media:player url="http://www.youtube.com/watch?v=AbC123DeFgH&amp;feature=youtube_gdata_player"/>
39
+ <media:thumbnail url="http://i.ytimg.com/vi/AbC123DeFgH/default.jpg" height="90" width="120" time="00:02:58" yt:name="default"/>
40
+ <media:thumbnail url="http://i.ytimg.com/vi/AbC123DeFgH/hqdefault.jpg" height="360" width="480" yt:name="hqdefault"/>
41
+ <media:thumbnail url="http://i.ytimg.com/vi/AbC123DeFgH/1.jpg" height="90" width="120" time="00:01:29" yt:name="start"/>
42
+ <media:thumbnail url="http://i.ytimg.com/vi/AbC123DeFgH/2.jpg" height="90" width="120" time="00:02:58" yt:name="middle"/>
43
+ <media:thumbnail url="http://i.ytimg.com/vi/AbC123DeFgH/3.jpg" height="90" width="120" time="00:04:27" yt:name="end"/>
44
44
  <media:title type="plain">Ich sterbe für YouTube</media:title>
45
45
  <yt:aspectRatio>widescreen</yt:aspectRatio>
46
46
  <yt:duration seconds="356"/>
47
47
  <yt:uploaded>2010-12-29T13:57:49.000Z</yt:uploaded>
48
- <yt:videoid>YTTESTVIDEO</yt:videoid>
48
+ <yt:videoid>AbC123DeFgH</yt:videoid>
49
49
  </media:group>
50
50
  <gd:rating average="4.305027" max="5" min="1" numRaters="2049" rel="http://schemas.google.com/g/2005#overall"/>
51
51
  <yt:statistics favoriteCount="200" viewCount="240000"/>
data/test/test_video.rb CHANGED
@@ -2,17 +2,17 @@ require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  class TestVideo < Test::Unit::TestCase
4
4
  def test_should_extract_unique_id_from_video_id
5
- video = YouTubeIt::Model::Video.new(:video_id => "http://gdata.youtube.com/feeds/videos/ZTUVgYoeN_o")
5
+ video = YouTubeIt::Model::Video.new(:video_id => "tag:youtube.com,2008:video:ZTUVgYoeN_o")
6
6
  assert_equal "ZTUVgYoeN_o", video.unique_id
7
7
  end
8
8
 
9
9
  def test_should_extract_unique_id_with_hypen_from_video_id
10
- video = YouTubeIt::Model::Video.new(:video_id => "http://gdata.youtube.com/feeds/videos/BDqs-OZWw9o")
10
+ video = YouTubeIt::Model::Video.new(:video_id => "tag:youtube.com,2008:video:BDqs-OZWw9o")
11
11
  assert_equal "BDqs-OZWw9o", video.unique_id
12
12
  end
13
13
 
14
14
  def test_should_have_related_videos
15
- video = YouTubeIt::Model::Video.new(:video_id => "http://gdata.youtube.com/feeds/videos/BDqs-OZWw9o")
15
+ video = YouTubeIt::Model::Video.new(:video_id => "tag:youtube.com,2008:video:BDqs-OZWw9o")
16
16
  response = video.related
17
17
 
18
18
  assert_equal "http://gdata.youtube.com/feeds/api/videos/BDqs-OZWw9o/related", response.feed_id
@@ -24,7 +24,7 @@ class TestVideo < Test::Unit::TestCase
24
24
  end
25
25
 
26
26
  def test_should_have_response_videos
27
- video = YouTubeIt::Model::Video.new(:video_id => "http://gdata.youtube.com/feeds/videos/BDqs-OZWw9o")
27
+ video = YouTubeIt::Model::Video.new(:video_id => "tag:youtube.com,2008:video:BDqs-OZWw9o")
28
28
  response = video.responses
29
29
 
30
30
  assert_equal "http://gdata.youtube.com/feeds/api/videos/BDqs-OZWw9o/responses", response.feed_id
@@ -36,7 +36,7 @@ class TestVideo < Test::Unit::TestCase
36
36
  end
37
37
 
38
38
  def test_should_scale_video_embed
39
- video = YouTubeIt::Model::Video.new(:video_id => "http://gdata.youtube.com/feeds/videos/EkF4JD2rO3Q", :player_url=>"http://www.youtube.com/v/EkF4JD2rO3Q&feature=youtube_gdata_player", :widescreen => true)
39
+ video = YouTubeIt::Model::Video.new(:video_id => "tag:youtube.com,2008:video:EkF4JD2rO3Q", :player_url=>"http://www.youtube.com/v/EkF4JD2rO3Q&feature=youtube_gdata_player", :widescreen => true)
40
40
  assert_equal "<object width=\"1280\" height=\"745\">\n<param name=\"movie\" value=\"http://www.youtube.com/v/EkF4JD2rO3Q&feature=youtube_gdata_player\"></param>\n<param name=\"wmode\" value=\"transparent\"></param>\n<embed src=\"http://www.youtube.com/v/EkF4JD2rO3Q&feature=youtube_gdata_player\" type=\"application/x-shockwave-flash\"\nwmode=\"transparent\" width=\"1280\" height=\"745\"></embed>\n</object>\n", video.embed_html_with_width(1280)
41
41
  end
42
42
  end
@@ -1,6 +1,164 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  class TestVideoFeedParser < Test::Unit::TestCase
4
+
5
+ # VIDEO ATTRIBUTES AFFECTED BY PARSING
6
+
7
+ def test_should_display_unique_id_correctly_after_parsing
8
+ with_video_response do |parser|
9
+ video = parser.parse
10
+ assert_equal "AbC123DeFgH", video.unique_id
11
+ end
12
+ end
13
+
14
+ # PARSED VIDEO ATTRIBUTES
15
+ def test_should_parse_duration_correctly
16
+ with_video_response do |parser|
17
+ video = parser.parse
18
+ assert_equal 356, video.duration
19
+ end
20
+ end
21
+
22
+ def test_should_parse_widescreen_correctly
23
+ with_video_response do |parser|
24
+ video = parser.parse
25
+ assert_equal true, video.widescreen?
26
+ end
27
+ end
28
+
29
+ def test_should_parse_noembed_correctly
30
+ with_video_response do |parser|
31
+ video = parser.parse
32
+ assert_equal false, video.noembed
33
+ end
34
+ end
35
+
36
+ def test_should_parse_racy_correctly
37
+ with_video_response do |parser|
38
+ video = parser.parse
39
+ assert_equal false, video.racy
40
+ end
41
+ end
42
+
43
+ def test_should_parse_video_id_correctly
44
+ with_video_response do |parser|
45
+ video = parser.parse
46
+ assert_equal "tag:youtube.com,2008:video:AbC123DeFgH", video.video_id
47
+ end
48
+ end
49
+
50
+ def test_should_parse_published_at_correctly
51
+ with_video_response do |parser|
52
+ video = parser.parse
53
+ assert_equal Time.parse("Wed Dec 29 13:57:49 UTC 2010"), video.published_at
54
+ end
55
+ end
56
+
57
+ def test_should_parse_updated_at_correctly
58
+ with_video_response do |parser|
59
+ video = parser.parse
60
+ assert_equal Time.parse("Wed Feb 23 13:54:16 UTC 2011"), video.updated_at
61
+ end
62
+ end
63
+
64
+ def test_should_parse_categories_correctly
65
+ with_video_response do |parser|
66
+ video = parser.parse
67
+ assert_equal "Test", video.categories.first.label
68
+ assert_equal "Test", video.categories.first.term
69
+ end
70
+ end
71
+
72
+ def test_should_parse_keywords_correctly
73
+ with_video_response do |parser|
74
+ video = parser.parse
75
+ assert_equal ["test"], video.keywords
76
+ end
77
+ end
78
+
79
+ def test_should_parse_description_correctly
80
+ with_video_response do |parser|
81
+ video = parser.parse
82
+ assert_equal "Youtube Test Video", video.description
83
+ end
84
+ end
85
+
86
+ def test_should_parse_title_correctly
87
+ with_video_response do |parser|
88
+ video = parser.parse
89
+ assert_equal "YouTube Test Video", video.title
90
+ end
91
+ end
92
+
93
+ def test_should_parse_html_content_correctly
94
+ with_video_response do |parser|
95
+ video = parser.parse
96
+ assert_equal nil, video.html_content
97
+ end
98
+ end
99
+
100
+ def test_should_parse_thumbnails_correctly
101
+ with_video_response do |parser|
102
+ video = parser.parse
103
+ thumbnail = video.thumbnails.first
104
+ assert_equal 90, thumbnail.height
105
+ assert_equal "00:02:58", thumbnail.time
106
+ assert_equal "http://i.ytimg.com/vi/AbC123DeFgH/default.jpg", thumbnail.url
107
+ assert_equal 120, thumbnail.width
108
+ end
109
+ end
110
+
111
+ def test_should_parse_player_url_correctly
112
+ with_video_response do |parser|
113
+ video = parser.parse
114
+ assert_equal "http://www.youtube.com/watch?v=AbC123DeFgH&feature=youtube_gdata_player", video.player_url
115
+ end
116
+ end
117
+
118
+ def test_should_parse_view_count_correctly
119
+ with_video_response do |parser|
120
+ video = parser.parse
121
+ assert_equal 240000, video.view_count
122
+ end
123
+ end
124
+
125
+ def test_should_parse_favorite_count_correctly
126
+ with_video_response do |parser|
127
+ video = parser.parse
128
+ assert_equal 200, video.favorite_count
129
+ end
130
+ end
131
+
132
+ # RATING
133
+
134
+ def test_should_parse_average_correctly
135
+ with_video_response do |parser|
136
+ video = parser.parse
137
+ assert_equal 4.305027, video.rating.average
138
+ end
139
+ end
140
+
141
+ def test_should_parse_max_correctly
142
+ with_video_response do |parser|
143
+ video = parser.parse
144
+ assert_equal 5, video.rating.max
145
+ end
146
+ end
147
+
148
+ def test_should_parse_min_correctly
149
+ with_video_response do |parser|
150
+ video = parser.parse
151
+ assert_equal 1, video.rating.min
152
+ end
153
+ end
154
+
155
+ def test_should_parse_rater_count_correctly
156
+ with_video_response do |parser|
157
+ video = parser.parse
158
+ assert_equal 2049, video.rating.rater_count
159
+ end
160
+ end
161
+
4
162
  def test_should_parse_likes_correctly
5
163
  with_video_response do |parser|
6
164
  video = parser.parse
@@ -14,6 +172,86 @@ class TestVideoFeedParser < Test::Unit::TestCase
14
172
  assert_equal 350, video.rating.dislikes
15
173
  end
16
174
  end
175
+
176
+ # TOD: GEODATA
177
+
178
+ def test_should_parse_where_geodata_correctly
179
+ with_video_response do |parser|
180
+ video = parser.parse
181
+ assert_equal nil, video.where
182
+ end
183
+ end
184
+
185
+ def test_should_parse_position_geodata_correctly
186
+ with_video_response do |parser|
187
+ video = parser.parse
188
+ assert_equal nil, video.position
189
+ end
190
+ end
191
+
192
+ def test_should_parse_latitude_geodata_correctly
193
+ with_video_response do |parser|
194
+ video = parser.parse
195
+ assert_equal nil, video.latitude
196
+ end
197
+ end
198
+
199
+ def test_should_parse_longitude_geodata_correctly
200
+ with_video_response do |parser|
201
+ video = parser.parse
202
+ assert_equal nil, video.longitude
203
+ end
204
+ end
205
+
206
+ # AUTHOR
207
+
208
+ def test_should_parse_author_name_correctly
209
+ with_video_response do |parser|
210
+ video = parser.parse
211
+ assert_equal "Test user", video.author.name
212
+ end
213
+ end
214
+
215
+ def test_should_parse_author_uri_correctly
216
+ with_video_response do |parser|
217
+ video = parser.parse
218
+ assert_equal "http://gdata.youtube.com/feeds/api/users/test_user", video.author.uri
219
+ end
220
+ end
221
+
222
+ # MEDIA CONTENT
223
+
224
+ def test_should_parse_if_media_content_is_default_content_correctly
225
+ with_video_response do |parser|
226
+ video = parser.parse
227
+ content = video.media_content.first
228
+ assert_equal true, content.default
229
+ end
230
+ end
231
+
232
+ def test_should_parse_duration_of_media_contents_correctly
233
+ with_video_response do |parser|
234
+ video = parser.parse
235
+ content = video.media_content.first
236
+ assert_equal 356, content.duration
237
+ end
238
+ end
239
+
240
+ def test_should_parse_mime_type_of_media_content_correctly
241
+ with_video_response do |parser|
242
+ video = parser.parse
243
+ content = video.media_content.first
244
+ assert_equal "application/x-shockwave-flash", content.mime_type
245
+ end
246
+ end
247
+
248
+ def test_should_parse_url_of_media_content_correctly
249
+ with_video_response do |parser|
250
+ video = parser.parse
251
+ content = video.media_content.first
252
+ assert_equal "http://www.youtube.com/v/AbC123DeFgH?f=videos&app=youtube_gdata", content.url
253
+ end
254
+ end
17
255
 
18
256
  def with_video_response &block
19
257
  File.open(File.dirname(__FILE__) + '/files/youtube_video_response.xml') do |xml|
data/youtube_it.gemspec CHANGED
@@ -5,20 +5,20 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{youtube_it}
8
- s.version = "1.4.0"
8
+ s.version = "1.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["chebyte", "kylejginavan"]
12
- s.date = %q{2011-02-23}
11
+ s.authors = ["kylejginavan", "chebyte", "mseppae"]
12
+ s.date = %q{2011-02-24}
13
13
  s.description = %q{Upload, delete, update, comment on youtube videos all from one gem.}
14
14
  s.email = %q{kylejginavan@gmail.com}
15
15
  s.extra_rdoc_files = [
16
- "README.txt"
16
+ "README.rdoc"
17
17
  ]
18
18
  s.files = [
19
19
  "History.txt",
20
20
  "Manifest.txt",
21
- "README.txt",
21
+ "README.rdoc",
22
22
  "Rakefile",
23
23
  "TODO.txt",
24
24
  "VERSION",
@@ -44,7 +44,6 @@ Gem::Specification.new do |s|
44
44
  "lib/youtube_it/request/video_upload.rb",
45
45
  "lib/youtube_it/response/video_search.rb",
46
46
  "lib/youtube_it/version.rb",
47
- "pkg/youtube_it-1.3.1.gem",
48
47
  "test/files/youtube_video_response.xml",
49
48
  "test/helper.rb",
50
49
  "test/test.mov",
metadata CHANGED
@@ -2,16 +2,17 @@
2
2
  name: youtube_it
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.4.0
5
+ version: 1.4.1
6
6
  platform: ruby
7
7
  authors:
8
- - chebyte
9
8
  - kylejginavan
9
+ - chebyte
10
+ - mseppae
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
14
 
14
- date: 2011-02-23 00:00:00 -06:00
15
+ date: 2011-02-24 00:00:00 -06:00
15
16
  default_executable:
16
17
  dependencies:
17
18
  - !ruby/object:Gem::Dependency
@@ -43,11 +44,11 @@ executables: []
43
44
  extensions: []
44
45
 
45
46
  extra_rdoc_files:
46
- - README.txt
47
+ - README.rdoc
47
48
  files:
48
49
  - History.txt
49
50
  - Manifest.txt
50
- - README.txt
51
+ - README.rdoc
51
52
  - Rakefile
52
53
  - TODO.txt
53
54
  - VERSION
@@ -73,7 +74,6 @@ files:
73
74
  - lib/youtube_it/request/video_upload.rb
74
75
  - lib/youtube_it/response/video_search.rb
75
76
  - lib/youtube_it/version.rb
76
- - pkg/youtube_it-1.3.1.gem
77
77
  - test/files/youtube_video_response.xml
78
78
  - test/helper.rb
79
79
  - test/test.mov
data/README.txt DELETED
@@ -1,243 +0,0 @@
1
- == DESCRIPTION:
2
-
3
- youtube_it is the most complete Ruby client for the YouTube GData API. It provides an easy
4
- way to access the latest YouTube video search results from your own programs.
5
- In comparison with the earlier Youtube search interfaces, this new API and
6
- library offers much-improved flexibility around executing complex search
7
- queries to obtain well-targeted video search results.
8
-
9
- == SYNOPSIS:
10
-
11
- Create a client:
12
-
13
- require 'youtube_it'
14
- client = YouTubeIt::Client.new
15
-
16
- if you need use your dev_key for search you can make
17
-
18
- client = YouTubeIt::Client.new(:dev_key => 'your dev key')
19
-
20
- Basic queries:
21
-
22
- client.videos_by(:query => "penguin")
23
- client.videos_by(:query => "penguin", :page => 2, :per_page => 15)
24
- client.videos_by(:tags => ['tiger', 'leopard'])
25
- client.videos_by(:categories => [:news, :sports])
26
- client.videos_by(:categories => [:news, :sports], :tags => ['soccer', 'football'])
27
- client.videos_by(:user => 'liz')
28
- client.videos_by(:favorites, :user => 'liz')
29
- client.video_by("FQK1URcxmb4")
30
- client.video_by_user("chebyte","FQK1URcxmb4")
31
-
32
- Standard feeds:
33
-
34
- client.videos_by(:most_viewed)
35
- client.videos_by(:most_linked, :page => 3)
36
- client.videos_by(:top_rated, :time => :today)
37
-
38
- Advanced queries (with boolean operators OR (either), AND (include), NOT (exclude)):
39
-
40
- client.videos_by(:categories => { :either => [:news, :sports], :exclude => [:comedy] }, :tags => { :include => ['football'], :exclude => ['soccer'] })
41
-
42
-
43
- Upload videos:
44
- You need on youtube account and developer key
45
- You can get these keys at the http://code.google.com/apis/youtube/dashboard/
46
-
47
- client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
48
-
49
- Or better yet, you can use OAuth
50
-
51
- client = YouTubeIt::OAuthClient.new("consumer_key", "consumer_secret", "youtube_username", "developer_key")
52
- client.authorize_from_access("access_token", "access_secret")
53
-
54
- * upload video
55
-
56
- client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test])
57
-
58
- * you can upload video with developer tag
59
-
60
- client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :dev_tag => 'tagdev')
61
-
62
-
63
- * update video
64
-
65
- client.video_update("FQK1URcxmb4", :title => "new test",:description => 'new description', :category => 'People',:keywords => %w[cool blah test])
66
-
67
- * delete video
68
-
69
- client.video_delete("FQK1URcxmb4")
70
-
71
- Profiles
72
-
73
- You can get a users profile:
74
-
75
- client.profile(user_id)
76
-
77
-
78
- Comments
79
-
80
- You can add or list comments with the following way:
81
-
82
- client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
83
-
84
- * get all comments:
85
-
86
- client.comments(video_id)
87
-
88
- * add a new comment:
89
-
90
- client.add_comment(video_id, "test comment!")
91
-
92
- Favorites
93
-
94
- You can add, delete or list your favorites videos:
95
-
96
- client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
97
-
98
- * get all favorites:
99
-
100
- client.favorites
101
-
102
- * add a new favorite:
103
-
104
- client.add_favorite(video_id)
105
-
106
- * delete favorite:
107
-
108
- client.delete_favorite(video_id)
109
-
110
- Playlist
111
-
112
- You can add, delete or list your playlists:
113
-
114
- client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
115
-
116
- * get all playlists:
117
-
118
- client.playlists
119
-
120
- * select your playlist:
121
-
122
- client.playlist(playlist_id)
123
-
124
- * get all videos from your playlist:
125
-
126
- my_playlist = client.playlist(playlist_id)
127
-
128
- my_playlist.videos
129
-
130
- * create new playlist:
131
-
132
- my_playlist = client.add_playlist(:title => "new playlist", :description => "playlist description")
133
-
134
- * delete a playlist:
135
-
136
- client.delete_playlist(playlist_id)
137
-
138
- * add video to playlist:
139
-
140
- client.add_video_to_playlist(playlist_id, video_id)
141
-
142
- * remove video from playlist:
143
-
144
- client.remove_video_from_playlist(playlist_id, playlist_entry_id)
145
-
146
- * get all playlists from some user
147
-
148
- client.playlists_for(user) #return array with the playlists
149
-
150
- Access Control List
151
-
152
- You can give permissions in your videos, for example denied comments, rate, etc...
153
- you can read more there http://code.google.com/apis/youtube/2.0/reference.html#youtube_data_api_tag_yt:accessControl
154
- you have available the followings options:
155
-
156
- * :rate, :comment, :commentVote, :videoRespond, :list, :embed, :syndicate
157
-
158
- with just two values:
159
- * allowed or denied
160
-
161
- Example
162
-
163
- client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
164
-
165
- * upload video with denied comments
166
-
167
- client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :comment => "denied")
168
-
169
-
170
- == Upload videos from browser:
171
-
172
- For upload a video from browser you need make a form upload with the followings params
173
-
174
- upload_token(params, nexturl)
175
-
176
- params => params like :title => "title", :description => "description", :category => "People", :tags => ["test"]
177
- nexturl => redirect to this url after upload
178
-
179
- Example
180
-
181
- Controller:
182
-
183
- def upload
184
- @upload_info = YouTubeIt::Client.new.upload_token(params, videos_url)
185
- end
186
-
187
- Views: upload.html.erb
188
-
189
- <% form_tag @upload_info[:url], :multipart => true do %>
190
- <%= hidden_field_tag :token, @upload_info[:token] %>
191
- <%= label_tag :file %>
192
- <%= file_field_tag :file %>
193
- <%= submit_tag "Upload video" %>
194
- <% end %>
195
-
196
- == WideScreen Videos
197
-
198
- if the videos has support for widescreen, you can show them with this way
199
-
200
- video.embed_html_with_width(1280)
201
-
202
- you can specify width or just use the default (1280)
203
-
204
- == LOGGING
205
-
206
- YouTubeIt passes all logs through the logger variable on the class itself. In Rails context, assign the Rails logger to that variable to collect the messages
207
- (don't forget to set the level to debug):
208
-
209
- YouTubeIt.logger = RAILS_DEFAULT_LOGGER
210
- RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
211
-
212
- == REQUIREMENTS:
213
-
214
- * builder gem
215
-
216
- == INSTALL:
217
-
218
- * sudo gem install youtube_it
219
-
220
- == LICENSE:
221
-
222
- MIT License
223
-
224
- Copyright (c) 2010 Kyle J. Ginavan
225
-
226
- Permission is hereby granted, free of charge, to any person obtaining
227
- a copy of this software and associated documentation files (the
228
- 'Software'), to deal in the Software without restriction, including
229
- without limitation the rights to use, copy, modify, merge, publish,
230
- distribute, sublicense, and/or sell copies of the Software, and to
231
- permit persons to whom the Software is furnished to do so, subject to
232
- the following conditions:
233
-
234
- The above copyright notice and this permission notice shall be
235
- included in all copies or substantial portions of the Software.
236
-
237
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
238
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
239
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
240
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
241
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
242
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
243
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Binary file