youtube_it 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/README.txt +20 -5
- data/VERSION +1 -1
- data/lib/youtube_it/client.rb +21 -4
- data/lib/youtube_it/model/video.rb +76 -46
- data/lib/youtube_it/parser.rb +5 -0
- data/lib/youtube_it/request/base_search.rb +11 -10
- data/lib/youtube_it/request/standard_search.rb +12 -10
- data/lib/youtube_it/request/user_search.rb +8 -7
- data/lib/youtube_it/request/video_search.rb +18 -16
- data/test/test_client.rb +16 -10
- data/test/test_video.rb +4 -0
- data/youtube_it.gemspec +4 -3
- metadata +4 -3
data/.gitignore
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
.DS_Store
|
2
|
+
.idea
|
3
|
+
config/database.yml
|
4
|
+
log/*.log
|
5
|
+
public/flash/*.swf
|
6
|
+
tmp/**/*
|
7
|
+
*.tmproj
|
8
|
+
public/stylesheets/packaged/*.css
|
9
|
+
public/javascripts/packaged/*.js
|
10
|
+
tmp
|
11
|
+
log
|
12
|
+
config/*.sphinx.conf
|
13
|
+
db/sphinx/
|
14
|
+
sphinx/**/*
|
15
|
+
public/packages/*
|
16
|
+
.gitconfig
|
17
|
+
|
data/README.txt
CHANGED
@@ -13,6 +13,10 @@ Create a client:
|
|
13
13
|
require 'youtube_it'
|
14
14
|
client = YouTubeIt::Client.new
|
15
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
|
+
|
16
20
|
Basic queries:
|
17
21
|
|
18
22
|
client.videos_by(:query => "penguin")
|
@@ -40,7 +44,7 @@ Upload videos:
|
|
40
44
|
You need on youtube account and developer key
|
41
45
|
You can get these keys at the http://code.google.com/apis/youtube/dashboard/
|
42
46
|
|
43
|
-
client = YouTubeIt::Client.new("youtube_username", "youtube_passwd", "developer_key")
|
47
|
+
client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
|
44
48
|
|
45
49
|
Or better yet, you can use OAuth
|
46
50
|
|
@@ -64,7 +68,7 @@ Comments
|
|
64
68
|
|
65
69
|
You can add or list comments with the following way:
|
66
70
|
|
67
|
-
client = YouTubeIt::Client.new("youtube_username", "youtube_passwd", "developer_key")
|
71
|
+
client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
|
68
72
|
|
69
73
|
* get all comments:
|
70
74
|
|
@@ -78,7 +82,7 @@ Favorites
|
|
78
82
|
|
79
83
|
You can add, delete or list your favorites videos:
|
80
84
|
|
81
|
-
client = YouTubeIt::Client.new("youtube_username", "youtube_passwd", "developer_key")
|
85
|
+
client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
|
82
86
|
|
83
87
|
* get all favorites:
|
84
88
|
|
@@ -96,7 +100,7 @@ Playlist
|
|
96
100
|
|
97
101
|
You can add, delete or list your playlists:
|
98
102
|
|
99
|
-
client = YouTubeIt::Client.new("youtube_username", "youtube_passwd", "developer_key")
|
103
|
+
client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
|
100
104
|
|
101
105
|
* get all playlists:
|
102
106
|
|
@@ -137,9 +141,12 @@ Access Control List
|
|
137
141
|
|
138
142
|
* :rate, :comment, :commentVote, :videoRespond, :list, :embed, :syndicate
|
139
143
|
|
144
|
+
with just two values:
|
145
|
+
* allowed or denied
|
146
|
+
|
140
147
|
Example
|
141
148
|
|
142
|
-
client = YouTubeIt::Client.new("youtube_username", "youtube_passwd", "developer_key")
|
149
|
+
client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
|
143
150
|
|
144
151
|
* upload video with denied comments
|
145
152
|
|
@@ -172,6 +179,14 @@ Access Control List
|
|
172
179
|
<%= submit_tag "Upload video" %>
|
173
180
|
<% end %>
|
174
181
|
|
182
|
+
== WideScreen Videos
|
183
|
+
|
184
|
+
if the videos has support for widescreen, you can show them with this way
|
185
|
+
|
186
|
+
video.embed_html_with_width(1280)
|
187
|
+
|
188
|
+
you can specify width or just use the default (1280)
|
189
|
+
|
175
190
|
== LOGGING
|
176
191
|
|
177
192
|
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
|
data/VERSION
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.8
|
2
2
|
|
data/lib/youtube_it/client.rb
CHANGED
@@ -2,8 +2,23 @@ class YouTubeIt
|
|
2
2
|
class Client
|
3
3
|
include YouTubeIt::Logging
|
4
4
|
# Previously this was a logger instance but we now do it globally
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
def initialize *params
|
7
|
+
if params.first.is_a?(Hash)
|
8
|
+
hash_options = params.first
|
9
|
+
@user = hash_options[:username]
|
10
|
+
@pass = hash_options[:password]
|
11
|
+
@dev_key = hash_options[:dev_key]
|
12
|
+
@client_id = hash_options[:client_id] || "youtube_it"
|
13
|
+
@legacy_debug_flag = hash_options[:debug]
|
14
|
+
else
|
15
|
+
puts "* warning: the method YouTubeIt::Client.new(user, passwd, dev_key) is depricated, use YouTubeIt::Client.new(:username => 'user', :password => 'passwd', :dev_key => 'dev_key')"
|
16
|
+
@user = params.shift
|
17
|
+
@pass = params.shift
|
18
|
+
@dev_key = params.shift
|
19
|
+
@client_id = params.shift || "youtube_it"
|
20
|
+
@legacy_debug_flag = params.shift
|
21
|
+
end
|
7
22
|
end
|
8
23
|
|
9
24
|
# Retrieves an array of standard feed, custom query, or user videos.
|
@@ -37,6 +52,8 @@ class YouTubeIt
|
|
37
52
|
request_params = params.respond_to?(:to_hash) ? params : options
|
38
53
|
request_params[:page] = integer_or_default(request_params[:page], 1)
|
39
54
|
|
55
|
+
request_params[:dev_key] = @dev_key if @dev_key
|
56
|
+
|
40
57
|
unless request_params[:max_results]
|
41
58
|
request_params[:max_results] = integer_or_default(request_params[:per_page], 25)
|
42
59
|
end
|
@@ -67,13 +84,13 @@ class YouTubeIt
|
|
67
84
|
# === Returns
|
68
85
|
# YouTubeIt::Model::Video
|
69
86
|
def video_by(vid)
|
70
|
-
video_id = vid =~ /^http/ ? vid : "http://gdata.youtube.com/feeds/videos/#{vid}"
|
87
|
+
video_id = vid =~ /^http/ ? vid : "http://gdata.youtube.com/feeds/api/videos/#{vid}?v=2#{@dev_key ? '&key='+@dev_key : ''}"
|
71
88
|
parser = YouTubeIt::Parser::VideoFeedParser.new(video_id)
|
72
89
|
parser.parse
|
73
90
|
end
|
74
91
|
|
75
92
|
def video_by_user(user, vid)
|
76
|
-
video_id = "http://gdata.youtube.com/feeds/api/users/#{user}/uploads/#{vid}"
|
93
|
+
video_id = "http://gdata.youtube.com/feeds/api/users/#{user}/uploads/#{vid}?v=2#{@dev_key ? '&key='+@dev_key : ''}"
|
77
94
|
parser = YouTubeIt::Parser::VideoFeedParser.new(video_id)
|
78
95
|
parser.parse
|
79
96
|
end
|
@@ -14,27 +14,27 @@ class YouTubeIt
|
|
14
14
|
# Instantiates a new video format object.
|
15
15
|
#
|
16
16
|
# == Parameters
|
17
|
-
# :format_code<Fixnum>:: The Youtube Format code of the object.
|
17
|
+
# :format_code<Fixnum>:: The Youtube Format code of the object.
|
18
18
|
# :name<Symbol>:: The name of the format
|
19
|
-
#
|
19
|
+
#
|
20
20
|
# == Returns
|
21
21
|
# YouTubeIt::Model::Video::Format: Video format object
|
22
22
|
def initialize(format_code, name)
|
23
23
|
@format_code = format_code
|
24
24
|
@name = name
|
25
25
|
|
26
|
-
@@formats[format_code] = self
|
26
|
+
@@formats[format_code] = self
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
# Allows you to get the video format for a specific format code.
|
30
|
-
#
|
30
|
+
#
|
31
31
|
# A full list of format codes is available at:
|
32
|
-
#
|
32
|
+
#
|
33
33
|
# http://code.google.com/apis/youtube/reference.html#youtube_data_api_tag_media:content
|
34
34
|
#
|
35
35
|
# == Parameters
|
36
|
-
# :format_code<Fixnum>:: The Youtube Format code of the object.
|
37
|
-
#
|
36
|
+
# :format_code<Fixnum>:: The Youtube Format code of the object.
|
37
|
+
#
|
38
38
|
# == Returns
|
39
39
|
# YouTubeIt::Model::Video::Format: Video format object
|
40
40
|
def self.by_code(format_code)
|
@@ -50,77 +50,80 @@ class YouTubeIt
|
|
50
50
|
# HTTP URL to the embeddable player (SWF) for this video. This format
|
51
51
|
# is not available for a video that is not embeddable.
|
52
52
|
SWF = YouTubeIt::Model::Video::Format.new(5, :swf)
|
53
|
-
|
53
|
+
|
54
54
|
# RTSP streaming URL for mobile video playback. MPEG-4 SP video (up to 176x144) and AAC audio.
|
55
55
|
THREE_GPP = YouTubeIt::Model::Video::Format.new(6, :three_gpp)
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
# *Fixnum*:: Duration of a video in seconds.
|
59
59
|
attr_reader :duration
|
60
|
-
|
60
|
+
|
61
|
+
# *Boolean*:: Specifies that a video may or may not be 16:9 ratio.
|
62
|
+
attr_reader :widescreen
|
63
|
+
|
61
64
|
# *Boolean*:: Specifies that a video may or may not be embedded on other websites.
|
62
65
|
attr_reader :noembed
|
63
|
-
|
66
|
+
|
64
67
|
# *Fixnum*:: Specifies the order in which the video appears in a playlist.
|
65
68
|
attr_reader :position
|
66
|
-
|
69
|
+
|
67
70
|
# *Boolean*:: Specifies that a video is flagged as adult or not.
|
68
71
|
attr_reader :racy
|
69
|
-
|
72
|
+
|
70
73
|
# *String*: Specifies a URI that uniquely and permanently identifies the video.
|
71
74
|
attr_reader :video_id
|
72
|
-
|
75
|
+
|
73
76
|
# *Time*:: When the video was published on Youtube.
|
74
77
|
attr_reader :published_at
|
75
|
-
|
78
|
+
|
76
79
|
# *Time*:: When the video's data was last updated.
|
77
80
|
attr_reader :updated_at
|
78
|
-
|
79
|
-
# *Array*:: A array of YouTubeIt::Model::Category objects that describe the videos categories.
|
81
|
+
|
82
|
+
# *Array*:: A array of YouTubeIt::Model::Category objects that describe the videos categories.
|
80
83
|
attr_reader :categories
|
81
|
-
|
84
|
+
|
82
85
|
# *Array*:: An array of words associated with the video.
|
83
86
|
attr_reader :keywords
|
84
|
-
|
87
|
+
|
85
88
|
# *String*:: Description of the video.
|
86
89
|
attr_reader :description
|
87
|
-
|
90
|
+
|
88
91
|
# *String*:: Title for the video.
|
89
92
|
attr_reader :title
|
90
|
-
|
93
|
+
|
91
94
|
# *String*:: Description of the video.
|
92
95
|
attr_reader :html_content
|
93
|
-
|
96
|
+
|
94
97
|
# YouTubeIt::Model::Author:: Information about the YouTube user who owns a piece of video content.
|
95
98
|
attr_reader :author
|
96
|
-
|
99
|
+
|
97
100
|
# *Array*:: An array of YouTubeIt::Model::Content objects describing the individual media content data available for this video. Most, but not all, videos offer this.
|
98
101
|
attr_reader :media_content
|
99
|
-
|
100
|
-
# *Array*:: An array of YouTubeIt::Model::Thumbnail objects that contain information regarding the videos thumbnail images.
|
102
|
+
|
103
|
+
# *Array*:: An array of YouTubeIt::Model::Thumbnail objects that contain information regarding the videos thumbnail images.
|
101
104
|
attr_reader :thumbnails
|
102
|
-
|
105
|
+
|
103
106
|
# *String*:: The link to watch the URL on YouTubes website.
|
104
107
|
attr_reader :player_url
|
105
|
-
|
108
|
+
|
106
109
|
# YouTubeIt::Model::Rating:: Information about the videos rating.
|
107
110
|
attr_reader :rating
|
108
|
-
|
111
|
+
|
109
112
|
# *Fixnum*:: Number of times that the video has been viewed
|
110
113
|
attr_reader :view_count
|
111
114
|
|
112
115
|
# *Fixnum*:: Number of times that the video has been favorited
|
113
116
|
attr_reader :favorite_count
|
114
|
-
|
115
|
-
|
117
|
+
|
118
|
+
|
116
119
|
# Geodata
|
117
120
|
attr_reader :where
|
118
121
|
attr_reader :position
|
119
122
|
attr_reader :latitude
|
120
123
|
attr_reader :longitude
|
121
|
-
|
124
|
+
|
122
125
|
attr_reader :statistics
|
123
|
-
|
126
|
+
|
124
127
|
# Videos related to the current video.
|
125
128
|
#
|
126
129
|
# === Returns
|
@@ -128,28 +131,28 @@ class YouTubeIt
|
|
128
131
|
def related
|
129
132
|
YouTubeIt::Parser::VideosFeedParser.new("http://gdata.youtube.com/feeds/api/videos/#{unique_id}/related").parse
|
130
133
|
end
|
131
|
-
|
134
|
+
|
132
135
|
# Video responses to the current video.
|
133
136
|
#
|
134
137
|
# === Returns
|
135
|
-
# YouTubeIt::Response::VideoSearch
|
138
|
+
# YouTubeIt::Response::VideoSearch
|
136
139
|
def responses
|
137
140
|
YouTubeIt::Parser::VideosFeedParser.new("http://gdata.youtube.com/feeds/api/videos/#{unique_id}/responses").parse
|
138
141
|
end
|
139
|
-
|
140
|
-
# The ID of the video, useful for searching for the video again without having to store it anywhere.
|
142
|
+
|
143
|
+
# The ID of the video, useful for searching for the video again without having to store it anywhere.
|
141
144
|
# A regular query search, with this id will return the same video.
|
142
|
-
#
|
145
|
+
#
|
143
146
|
# === Example
|
144
147
|
# >> video.unique_id
|
145
148
|
# => "ZTUVgYoeN_o"
|
146
|
-
#
|
149
|
+
#
|
147
150
|
# === Returns
|
148
151
|
# String: The Youtube video id.
|
149
152
|
def unique_id
|
150
153
|
video_id[/videos\/([^<]+)/, 1]
|
151
154
|
end
|
152
|
-
|
155
|
+
|
153
156
|
# Allows you to check whether the video can be embedded on a webpage.
|
154
157
|
#
|
155
158
|
# === Returns
|
@@ -157,15 +160,23 @@ class YouTubeIt
|
|
157
160
|
def embeddable?
|
158
161
|
not @noembed
|
159
162
|
end
|
160
|
-
|
163
|
+
|
164
|
+
# Allows you to check whether the video is widescreen (16:9) or not.
|
165
|
+
#
|
166
|
+
# === Returns
|
167
|
+
# Boolean: True if the video is (approximately) 16:9, false if not.
|
168
|
+
def widescreen?
|
169
|
+
@widescreen
|
170
|
+
end
|
171
|
+
|
161
172
|
# Provides a URL and various other types of information about a video.
|
162
|
-
#
|
173
|
+
#
|
163
174
|
# === Returns
|
164
175
|
# YouTubeIt::Model::Content: Data about the embeddable video.
|
165
176
|
def default_media_content
|
166
177
|
@media_content.find { |c| c.is_default? }
|
167
178
|
end
|
168
|
-
|
179
|
+
|
169
180
|
# Gives you the HTML to embed the video on your website.
|
170
181
|
#
|
171
182
|
# === Returns
|
@@ -175,20 +186,39 @@ class YouTubeIt
|
|
175
186
|
<object width="#{width}" height="#{height}">
|
176
187
|
<param name="movie" value="#{embed_url}"></param>
|
177
188
|
<param name="wmode" value="transparent"></param>
|
178
|
-
<embed src="#{embed_url}" type="application/x-shockwave-flash"
|
189
|
+
<embed src="#{embed_url}" type="application/x-shockwave-flash"
|
179
190
|
wmode="transparent" width="#{width}" height="#{height}"></embed>
|
180
191
|
</object>
|
181
192
|
EDOC
|
182
193
|
end
|
183
194
|
|
195
|
+
# Gives you the HTML to embed the video on your website.
|
196
|
+
#
|
197
|
+
# === Returns
|
198
|
+
# String: The HTML for embedding the video on your website.
|
199
|
+
def embed_html_with_width(width = 1280)
|
200
|
+
height = (widescreen? ? width * 9/16 : width * 3/4) + 25
|
201
|
+
|
202
|
+
<<EDOC
|
203
|
+
<object width="#{width}" height="#{height}">
|
204
|
+
<param name="movie" value="#{embed_url}"></param>
|
205
|
+
<param name="wmode" value="transparent"></param>
|
206
|
+
<embed src="#{embed_url}" type="application/x-shockwave-flash"
|
207
|
+
wmode="transparent" width="#{width}" height="#{height}"></embed>
|
208
|
+
</object>
|
209
|
+
EDOC
|
210
|
+
end
|
211
|
+
|
184
212
|
# The URL needed for embedding the video in a page.
|
185
213
|
#
|
186
214
|
# === Returns
|
187
215
|
# String: Absolute URL for embedding video
|
188
216
|
def embed_url
|
189
|
-
@player_url.sub('watch?', '').sub('=', '/')
|
217
|
+
@player_url.sub('watch?', '').sub('=', '/').sub('feature/', 'feature=')
|
190
218
|
end
|
191
|
-
|
219
|
+
|
220
|
+
|
192
221
|
end
|
193
222
|
end
|
194
223
|
end
|
224
|
+
|
data/lib/youtube_it/parser.rb
CHANGED
@@ -83,6 +83,10 @@ class YouTubeIt
|
|
83
83
|
description = media_group.elements["media:description"].text
|
84
84
|
duration = media_group.elements["yt:duration"].attributes["seconds"].to_i
|
85
85
|
|
86
|
+
unless media_group.elements["yt:aspectRatio"].nil?
|
87
|
+
widescreen = media_group.elements["yt:aspectRatio"].text == 'widescreen' ? true : false
|
88
|
+
end
|
89
|
+
|
86
90
|
media_content = []
|
87
91
|
media_group.elements.each("media:content") do |mce|
|
88
92
|
media_content << parse_media_content(mce)
|
@@ -142,6 +146,7 @@ class YouTubeIt
|
|
142
146
|
:rating => rating,
|
143
147
|
:view_count => view_count,
|
144
148
|
:favorite_count => favorite_count,
|
149
|
+
:widescreen => widescreen,
|
145
150
|
:noembed => noembed,
|
146
151
|
:racy => racy,
|
147
152
|
:where => where,
|
@@ -1,26 +1,27 @@
|
|
1
1
|
class YouTubeIt
|
2
|
-
module Request #:nodoc:
|
2
|
+
module Request #:nodoc:
|
3
3
|
class BaseSearch #:nodoc:
|
4
4
|
attr_reader :url
|
5
|
-
|
5
|
+
|
6
6
|
private
|
7
|
-
|
7
|
+
|
8
8
|
def base_url
|
9
|
-
"http://gdata.youtube.com/feeds/api/"
|
9
|
+
"http://gdata.youtube.com/feeds/api/"
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def set_instance_variables( variables )
|
13
|
-
variables.each do |key, value|
|
13
|
+
variables.each do |key, value|
|
14
14
|
name = key.to_s
|
15
15
|
instance_variable_set("@#{name}", value) if respond_to?(name)
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def build_query_params(params)
|
20
20
|
qs = params.to_a.map { | k, v | v.nil? ? nil : "#{YouTubeIt.esc(k)}=#{YouTubeIt.esc(v)}" }.compact.sort.join('&')
|
21
|
-
qs.empty? ? '' : "?#{qs}"
|
21
|
+
qs.empty? ? '' : (@dev_key ? "?#{qs}&key=#{@dev_key}" : "?#{qs}")
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
end
|
26
|
-
end
|
26
|
+
end
|
27
|
+
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class YouTubeIt
|
2
|
-
module Request #:nodoc:
|
2
|
+
module Request #:nodoc:
|
3
3
|
class StandardSearch < BaseSearch #:nodoc:
|
4
4
|
attr_reader :max_results # max_results
|
5
5
|
attr_reader :order_by # orderby, ([relevance], viewCount, published, rating)
|
@@ -11,6 +11,7 @@ class YouTubeIt
|
|
11
11
|
:recently_featured, :watch_on_mobile ]
|
12
12
|
|
13
13
|
def initialize(type, options={})
|
14
|
+
@dev_key = options[:dev_key] if options[:dev_key]
|
14
15
|
if TYPES.include?(type)
|
15
16
|
@max_results, @order_by, @offset, @time = nil
|
16
17
|
set_instance_variables(options)
|
@@ -23,18 +24,19 @@ class YouTubeIt
|
|
23
24
|
private
|
24
25
|
|
25
26
|
def base_url
|
26
|
-
super << "standardfeeds/"
|
27
|
+
super << "standardfeeds/"
|
27
28
|
end
|
28
29
|
|
29
30
|
def to_youtube_params
|
30
|
-
{
|
31
|
-
'max-results' => @max_results,
|
32
|
-
'orderby' => @order_by,
|
33
|
-
'start-index' => @offset,
|
34
|
-
'time' => @time
|
31
|
+
{
|
32
|
+
'max-results' => @max_results,
|
33
|
+
'orderby' => @order_by,
|
34
|
+
'start-index' => @offset,
|
35
|
+
'time' => @time
|
35
36
|
}
|
36
|
-
end
|
37
|
+
end
|
37
38
|
end
|
38
|
-
|
39
|
+
|
39
40
|
end
|
40
|
-
end
|
41
|
+
end
|
42
|
+
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class YouTubeIt
|
2
|
-
module Request #:nodoc:
|
3
|
-
class UserSearch < BaseSearch #:nodoc:
|
2
|
+
module Request #:nodoc:
|
3
|
+
class UserSearch < BaseSearch #:nodoc:
|
4
4
|
attr_reader :max_results # max_results
|
5
5
|
attr_reader :order_by # orderby, ([relevance], viewCount, published, rating)
|
6
6
|
attr_reader :offset # start-index
|
@@ -8,9 +8,9 @@ class YouTubeIt
|
|
8
8
|
def initialize(params, options={})
|
9
9
|
@max_results, @order_by, @offset = nil
|
10
10
|
@url = base_url
|
11
|
-
|
11
|
+
@dev_key = options[:dev_key] if options[:dev_key]
|
12
12
|
if params == :favorites
|
13
|
-
@url << "#{options[:user]}/favorites"
|
13
|
+
@url << "#{options[:user]}/favorites"
|
14
14
|
set_instance_variables(options)
|
15
15
|
elsif params[:user] && options[:favorites]
|
16
16
|
@url << "#{params[:user]}/favorites"
|
@@ -20,7 +20,7 @@ class YouTubeIt
|
|
20
20
|
@url << "#{params[:user]}/uploads"
|
21
21
|
set_instance_variables(params)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
@url << build_query_params(to_youtube_params)
|
25
25
|
end
|
26
26
|
|
@@ -38,6 +38,7 @@ class YouTubeIt
|
|
38
38
|
}
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
end
|
43
|
-
end
|
43
|
+
end
|
44
|
+
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class YouTubeIt
|
2
|
-
module Request #:nodoc:
|
2
|
+
module Request #:nodoc:
|
3
3
|
class VideoSearch < BaseSearch #:nodoc:
|
4
4
|
# From here: http://code.google.com/apis/youtube/reference.html#yt_format
|
5
5
|
ONLY_EMBEDDABLE = 5
|
@@ -14,38 +14,39 @@ class YouTubeIt
|
|
14
14
|
attr_reader :video_format # format (1=mobile devices)
|
15
15
|
attr_reader :racy # racy ([exclude], include)
|
16
16
|
attr_reader :author
|
17
|
-
|
17
|
+
|
18
18
|
def initialize(params={})
|
19
19
|
# Initialize our various member data to avoid warnings and so we'll
|
20
20
|
# automatically fall back to the youtube api defaults
|
21
|
-
@max_results, @order_by,
|
22
|
-
@offset, @query,
|
23
|
-
@response_format, @video_format,
|
21
|
+
@max_results, @order_by,
|
22
|
+
@offset, @query,
|
23
|
+
@response_format, @video_format,
|
24
24
|
@racy, @author = nil
|
25
25
|
@url = base_url
|
26
|
-
|
26
|
+
@dev_key = params[:dev_key] if params[:dev_key]
|
27
|
+
|
27
28
|
# Return a single video (base_url + /T7YazwP8GtY)
|
28
29
|
return @url << "/" << params[:video_id] if params[:video_id]
|
29
|
-
|
30
|
+
|
30
31
|
@url << "/-/" if (params[:categories] || params[:tags])
|
31
32
|
@url << categories_to_params(params.delete(:categories)) if params[:categories]
|
32
33
|
@url << tags_to_params(params.delete(:tags)) if params[:tags]
|
33
34
|
|
34
35
|
set_instance_variables(params)
|
35
|
-
|
36
|
+
|
36
37
|
if( params[ :only_embeddable ] )
|
37
38
|
@video_format = ONLY_EMBEDDABLE
|
38
39
|
end
|
39
40
|
|
40
41
|
@url << build_query_params(to_youtube_params)
|
41
42
|
end
|
42
|
-
|
43
|
+
|
43
44
|
private
|
44
|
-
|
45
|
+
|
45
46
|
def base_url
|
46
47
|
super << "videos"
|
47
48
|
end
|
48
|
-
|
49
|
+
|
49
50
|
def to_youtube_params
|
50
51
|
{
|
51
52
|
'max-results' => @max_results,
|
@@ -59,14 +60,14 @@ class YouTubeIt
|
|
59
60
|
}
|
60
61
|
end
|
61
62
|
|
62
|
-
# Convert category symbols into strings and build the URL. GData requires categories to be capitalized.
|
63
|
+
# Convert category symbols into strings and build the URL. GData requires categories to be capitalized.
|
63
64
|
# Categories defined like: categories => { :include => [:news], :exclude => [:sports], :either => [..] }
|
64
65
|
# or like: categories => [:news, :sports]
|
65
66
|
def categories_to_params(categories)
|
66
67
|
if categories.respond_to?(:keys) and categories.respond_to?(:[])
|
67
68
|
s = ""
|
68
69
|
s << categories[:either].map { |c| c.to_s.capitalize }.join("%7C") << '/' if categories[:either]
|
69
|
-
s << categories[:include].map { |c| c.to_s.capitalize }.join("/") << '/' if categories[:include]
|
70
|
+
s << categories[:include].map { |c| c.to_s.capitalize }.join("/") << '/' if categories[:include]
|
70
71
|
s << ("-" << categories[:exclude].map { |c| c.to_s.capitalize }.join("/-")) << '/' if categories[:exclude]
|
71
72
|
s
|
72
73
|
else
|
@@ -80,14 +81,15 @@ class YouTubeIt
|
|
80
81
|
if tags.respond_to?(:keys) and tags.respond_to?(:[])
|
81
82
|
s = ""
|
82
83
|
s << tags[:either].map { |t| YouTubeIt.esc(t.to_s) }.join("%7C") << '/' if tags[:either]
|
83
|
-
s << tags[:include].map { |t| YouTubeIt.esc(t.to_s) }.join("/") << '/' if tags[:include]
|
84
|
+
s << tags[:include].map { |t| YouTubeIt.esc(t.to_s) }.join("/") << '/' if tags[:include]
|
84
85
|
s << ("-" << tags[:exclude].map { |t| YouTubeIt.esc(t.to_s) }.join("/-")) << '/' if tags[:exclude]
|
85
86
|
s
|
86
87
|
else
|
87
88
|
tags.map { |t| YouTubeIt.esc(t.to_s) }.join("/") << '/'
|
88
|
-
end
|
89
|
+
end
|
89
90
|
end
|
90
|
-
|
91
|
+
|
91
92
|
end
|
92
93
|
end
|
93
94
|
end
|
95
|
+
|
data/test/test_client.rb
CHANGED
@@ -10,7 +10,7 @@ class TestClient < Test::Unit::TestCase
|
|
10
10
|
RAILS_ENV = "test"
|
11
11
|
|
12
12
|
def setup
|
13
|
-
@client = YouTubeIt::Client.new(ACCOUNT[:user], ACCOUNT[:passwd] , ACCOUNT[:dev_key])
|
13
|
+
@client = YouTubeIt::Client.new(:username => ACCOUNT[:user], :password => ACCOUNT[:passwd] , :dev_key => ACCOUNT[:dev_key])
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_should_respond_to_a_basic_query
|
@@ -145,24 +145,23 @@ class TestClient < Test::Unit::TestCase
|
|
145
145
|
|
146
146
|
def test_should_get_videos_for_query_search_with_categories_excluded
|
147
147
|
video = @client.video_by("EkF4JD2rO3Q")
|
148
|
-
assert_equal "<object width=\"425\" height=\"350\">\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\"
|
148
|
+
assert_equal "<object width=\"425\" height=\"350\">\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\"\n wmode=\"transparent\" width=\"425\" height=\"350\"></embed>\n</object>\n", video.embed_html
|
149
149
|
assert_valid_video video
|
150
150
|
end
|
151
151
|
|
152
152
|
def test_should_get_video_from_user
|
153
153
|
video = @client.video_by_user("chebyte","FQK1URcxmb4")
|
154
|
-
assert_equal "<object width=\"425\" height=\"350\">\n <param name=\"movie\" value=\"http://www.youtube.com/v/FQK1URcxmb4&feature=youtube_gdata_player\"></param>\n <param name=\"wmode\" value=\"transparent\"></param>\n <embed src=\"http://www.youtube.com/v/FQK1URcxmb4&feature=youtube_gdata_player\" type=\"application/x-shockwave-flash\"
|
154
|
+
assert_equal "<object width=\"425\" height=\"350\">\n <param name=\"movie\" value=\"http://www.youtube.com/v/FQK1URcxmb4&feature=youtube_gdata_player\"></param>\n <param name=\"wmode\" value=\"transparent\"></param>\n <embed src=\"http://www.youtube.com/v/FQK1URcxmb4&feature=youtube_gdata_player\" type=\"application/x-shockwave-flash\"\n wmode=\"transparent\" width=\"425\" height=\"350\"></embed>\n</object>\n", video.embed_html
|
155
155
|
assert_valid_video video
|
156
156
|
end
|
157
157
|
|
158
|
-
|
159
158
|
def test_should_always_return_a_logger
|
160
159
|
@client = YouTubeIt::Client.new
|
161
160
|
assert_not_nil @client.logger
|
162
161
|
end
|
163
162
|
|
164
163
|
def test_should_not_bail_if_debug_is_true
|
165
|
-
assert_nothing_raised { YouTubeIt::Client.new(true) }
|
164
|
+
assert_nothing_raised { YouTubeIt::Client.new(:debug => true) }
|
166
165
|
end
|
167
166
|
|
168
167
|
def test_should_determine_if_embeddable_video_is_embeddable
|
@@ -197,10 +196,10 @@ class TestClient < Test::Unit::TestCase
|
|
197
196
|
|
198
197
|
def test_should_update_a_video
|
199
198
|
OPTIONS[:title] = "title changed"
|
200
|
-
video = @client.
|
201
|
-
|
202
|
-
|
203
|
-
@client.
|
199
|
+
video = @client.video_upload(File.open("test/test.mov"), OPTIONS)
|
200
|
+
updated_video = @client.video_update(video.unique_id, OPTIONS)
|
201
|
+
assert updated_video.title == "title changed"
|
202
|
+
@client.video_delete(video.unique_id)
|
204
203
|
end
|
205
204
|
|
206
205
|
def test_should_delete_video
|
@@ -213,7 +212,7 @@ class TestClient < Test::Unit::TestCase
|
|
213
212
|
video = @client.video_upload(File.open("test/test.mov"), OPTIONS.merge(:comment => "denied"))
|
214
213
|
assert_valid_video video
|
215
214
|
doc = Nokogiri::HTML(open("http://www.youtube.com/watch?v=#{video.unique_id}"))
|
216
|
-
doc.css('.comments-disabled').each{|tag| assert (tag.content.strip == "Adding comments has been disabled for this video.")}
|
215
|
+
doc.css('.comments-disabled').each{|tag| assert (tag.content.strip == "All Comments\n \n Adding comments has been disabled for this video.")}
|
217
216
|
@client.video_delete(video.unique_id)
|
218
217
|
end
|
219
218
|
|
@@ -267,6 +266,13 @@ class TestClient < Test::Unit::TestCase
|
|
267
266
|
assert @client.delete_playlist(playlist.playlist_id)
|
268
267
|
end
|
269
268
|
|
269
|
+
def test_should_determine_if_widescreen_video_is_widescreen
|
270
|
+
widescreen_id = 'QqQVll-MP3I'
|
271
|
+
|
272
|
+
video = @client.video_by(widescreen_id)
|
273
|
+
assert video.widescreen?
|
274
|
+
end
|
275
|
+
|
270
276
|
private
|
271
277
|
|
272
278
|
def assert_valid_video (video)
|
data/test/test_video.rb
CHANGED
@@ -35,5 +35,9 @@ class TestVideo < Test::Unit::TestCase
|
|
35
35
|
assert_instance_of Time, response.updated_at
|
36
36
|
end
|
37
37
|
|
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)
|
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
|
+
end
|
38
42
|
end
|
39
43
|
|
data/youtube_it.gemspec
CHANGED
@@ -5,18 +5,19 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{youtube_it}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["chebyte", "kylejginavan"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-09}
|
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
16
|
"README.txt"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
-
"
|
19
|
+
".gitignore",
|
20
|
+
"History.txt",
|
20
21
|
"Manifest.txt",
|
21
22
|
"README.txt",
|
22
23
|
"Rakefile",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 8
|
9
|
+
version: 0.0.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- chebyte
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-09 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -28,6 +28,7 @@ extensions: []
|
|
28
28
|
extra_rdoc_files:
|
29
29
|
- README.txt
|
30
30
|
files:
|
31
|
+
- .gitignore
|
31
32
|
- History.txt
|
32
33
|
- Manifest.txt
|
33
34
|
- README.txt
|