Class: Tubeclip::Upload::VideoUpload
- Inherits:
-
Object
- Object
- Tubeclip::Upload::VideoUpload
- Includes:
- Logging
- Defined in:
- lib/tubeclip/request/video_upload.rb
Overview
Instance Method Summary collapse
- #add_comment(video_id, comment, opts = {}) ⇒ Object
- #add_favorite(video_id) ⇒ Object
- #add_playlist(options) ⇒ Object
- #add_response(original_video_id, response_video_id) ⇒ Object
- #add_video_to_playlist(playlist_id, video_id, position) ⇒ Object
- #add_video_to_watchlater(video_id) ⇒ Object
- #captions_update(video_id, data, options) ⇒ Object
- #comments(video_id, opts = {}) ⇒ Object
-
#delete(video_id) ⇒ Object
Delete a video on YouTube.
- #delete_comment(video_id, comment_id) ⇒ Object
- #delete_favorite(video_id) ⇒ Object
-
#delete_message(message_id) ⇒ Object
Delete a video message.
- #delete_playlist(playlist_id) ⇒ Object
- #delete_response(original_video_id, response_video_id) ⇒ Object
- #delete_video_from_playlist(playlist_id, playlist_entry_id) ⇒ Object
- #delete_video_from_watchlater(video_id) ⇒ Object
- #enable_http_debugging ⇒ Object
- #favorites(user, opts = {}) ⇒ Object
-
#get_activity(user, opts) ⇒ Object
Return’s a user’s activity feed.
- #get_current_user ⇒ Object
-
#get_my_contacts(opts) ⇒ Object
Fetches the currently authenticated user’s contacts (i.e. friends).
-
#get_my_messages(opts) ⇒ Object
Fetches the currently authenticated user’s messages (i.e. inbox).
-
#get_my_video(video_id) ⇒ Object
Fetches the data of a video, which may be private.
-
#get_my_videos(opts) ⇒ Object
Fetches the data of the videos of the current user, which may be private.
- #get_upload_token(options, nexturl) ⇒ Object
- #get_watch_history ⇒ Object
-
#initialize(*params) ⇒ VideoUpload
constructor
A new instance of VideoUpload.
- #new_subscription_videos(user) ⇒ Object
-
#partial_update(video_id, options) ⇒ Object
Partial updates to a video.
- #playlist(playlist_id, opts = {}) ⇒ Object
-
#playlists(user, opts = {}) ⇒ Object
Fetches playlists for the given user.
- #profile(user = nil) ⇒ Object
- #profile_url(user = nil) ⇒ Object
- #profiles(usernames_to_fetch) ⇒ Object
- #rate_video(video_id, rating) ⇒ Object
- #send_message(opts) ⇒ Object
- #subscribe_channel(channel_name) ⇒ Object
- #subscriptions(user) ⇒ Object
- #unsubscribe_channel(subscription_id) ⇒ Object
-
#update(video_id, options) ⇒ Object
Updates a video in YouTube.
- #update_playlist(playlist_id, options) ⇒ Object
- #update_position_video_from_playlist(playlist_id, playlist_entry_id, position) ⇒ Object
-
#upload(video_data, opts = {}) ⇒ Object
Upload “data” to youtube, where data is either an IO object or raw file data.
- #uri?(string) ⇒ Boolean
- #videos(idxes_to_fetch) ⇒ Object
- #watchlater(user) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(*params) ⇒ VideoUpload
Returns a new instance of VideoUpload.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tubeclip/request/video_upload.rb', line 16 def initialize *params if params.first.is_a?(Hash) = params.first @user = [:username] @password = [:password] @dev_key = [:dev_key] @access_token = [:access_token] @authsub_token = [:authsub_token] @client_id = [:client_id] || "tubeclip" @config_token = [:config_token] else puts "* warning: the method Tubeclip::Upload::VideoUpload.new(username, password, dev_key) is deprecated, use Tubeclip::Upload::VideoUpload.new(:username => 'user', :password => 'passwd', :dev_key => 'dev_key')" @user = params.shift @password = params.shift @dev_key = params.shift @access_token = params.shift @authsub_token = params.shift @client_id = params.shift || "tubeclip" @config_token = params.shift end end |
Instance Method Details
#add_comment(video_id, comment, opts = {}) ⇒ Object
229 230 231 232 233 234 235 236 237 |
# File 'lib/tubeclip/request/video_upload.rb', line 229 def add_comment(video_id, comment, opts = {}) reply_to = opts.delete :reply_to reply_to = reply_to.unique_id if reply_to.is_a? Tubeclip::Model::Comment comment_body = comment_xml_for(:comment => comment, :reply_to => reply_to_url(video_id, reply_to)) comment_url = "/feeds/api/videos/%s/comments" % video_id response = yt_session(base_ssl_url).post(comment_url, comment_body) comment = Tubeclip::Parser::CommentsFeedParser.new(response.body).parse_single_entry return {:code => response.status, :body => response.body, :comment => comment} end |
#add_favorite(video_id) ⇒ Object
254 255 256 257 258 259 260 |
# File 'lib/tubeclip/request/video_upload.rb', line 254 def add_favorite(video_id) favorite_body = video_xml_for(:favorite => video_id) favorite_url = "/feeds/api/users/default/favorites" response = yt_session.post(favorite_url, favorite_body) return {:code => response.status, :body => response.body, :favorite_entry_id => get_entry_id(response.body)} end |
#add_playlist(options) ⇒ Object
396 397 398 399 400 401 402 |
# File 'lib/tubeclip/request/video_upload.rb', line 396 def add_playlist() playlist_body = video_xml_for_playlist() playlist_url = "/feeds/api/users/default/playlists" response = yt_session.post(playlist_url, playlist_body) return Tubeclip::Parser::PlaylistFeedParser.new(response).parse end |
#add_response(original_video_id, response_video_id) ⇒ Object
486 487 488 489 490 491 492 |
# File 'lib/tubeclip/request/video_upload.rb', line 486 def add_response(original_video_id, response_video_id) response_body = video_xml_for(:response => response_video_id) response_url = "/feeds/api/videos/%s/responses" % original_video_id response = yt_session.post(response_url, response_body) return {:code => response.status, :body => response.body} end |
#add_video_to_playlist(playlist_id, video_id, position) ⇒ Object
404 405 406 407 408 409 410 |
# File 'lib/tubeclip/request/video_upload.rb', line 404 def add_video_to_playlist(playlist_id, video_id, position) playlist_body = video_xml_for(:playlist => video_id, :position => position) playlist_url = "/feeds/api/playlists/%s" % playlist_id response = yt_session.post(playlist_url, playlist_body) return {:code => response.status, :body => response.body, :playlist_entry_id => get_entry_id(response.body)} end |
#add_video_to_watchlater(video_id) ⇒ Object
353 354 355 356 357 358 359 |
# File 'lib/tubeclip/request/video_upload.rb', line 353 def add_video_to_watchlater(video_id) playlist_body = video_xml_for(:playlist => video_id) playlist_url = "/feeds/api/users/default/watch_later" response = yt_session.post(playlist_url, playlist_body) return {:code => response.status, :body => response.body, :watchlater_entry_id => get_entry_id(response.body)} end |
#captions_update(video_id, data, options) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/tubeclip/request/video_upload.rb', line 138 def (video_id, data, ) @opts = { :language => 'en-US', :slug => '' }.merge() upload_header = { "Slug" => "#{URI.escape(@opts[:slug])}", "Content-Language"=>@opts[:language], "Content-Type" => "application/vnd.youtube.timedtext; charset=UTF-8", "Content-Length" => "#{data.length}", } upload_url = "/feeds/api/videos/#{video_id}/captions" response = yt_session(base_url).post(upload_url, data, upload_header) return Tubeclip::Parser::CaptionFeedParser.new(response.body).parse end |
#comments(video_id, opts = {}) ⇒ Object
247 248 249 250 251 252 |
# File 'lib/tubeclip/request/video_upload.rb', line 247 def comments(video_id, opts = {}) comment_url = "/feeds/api/videos/%s/comments?" % video_id comment_url << opts.collect { |k,p| [k,p].join '=' }.join('&') response = yt_session.get(comment_url) return Tubeclip::Parser::CommentsFeedParser.new(response).parse end |
#delete(video_id) ⇒ Object
Delete a video on YouTube
204 205 206 207 208 209 |
# File 'lib/tubeclip/request/video_upload.rb', line 204 def delete(video_id) delete_url = "/feeds/api/users/default/uploads/%s" % video_id response = yt_session.delete(delete_url) return true end |
#delete_comment(video_id, comment_id) ⇒ Object
239 240 241 242 243 244 245 |
# File 'lib/tubeclip/request/video_upload.rb', line 239 def delete_comment(video_id, comment_id) comment_id = comment_id.unique_id if comment_id.is_a? Tubeclip::Model::Comment url = "/feeds/api/videos/%s/comments/%s" % [video_id, comment_id] response = yt_session(base_ssl_url).delete(url) return response.status == 200 end |
#delete_favorite(video_id) ⇒ Object
262 263 264 265 266 267 |
# File 'lib/tubeclip/request/video_upload.rb', line 262 def delete_favorite(video_id) favorite_url = "/feeds/api/users/default/favorites/%s" % video_id response = yt_session.delete(favorite_url) return true end |
#delete_message(message_id) ⇒ Object
Delete a video message
212 213 214 215 216 217 |
# File 'lib/tubeclip/request/video_upload.rb', line 212 def () delete_url = "/feeds/api/users/default/inbox/%s" % response = yt_session.delete(delete_url) return true end |
#delete_playlist(playlist_id) ⇒ Object
435 436 437 438 439 440 |
# File 'lib/tubeclip/request/video_upload.rb', line 435 def delete_playlist(playlist_id) playlist_url = "/feeds/api/users/default/playlists/%s" % playlist_id response = yt_session.delete(playlist_url) return true end |
#delete_response(original_video_id, response_video_id) ⇒ Object
494 495 496 497 498 499 |
# File 'lib/tubeclip/request/video_upload.rb', line 494 def delete_response(original_video_id, response_video_id) response_url = "/feeds/api/videos/%s/responses/%s" % [original_video_id, response_video_id] response = yt_session.delete(response_url) return {:code => response.status, :body => response.body} end |
#delete_video_from_playlist(playlist_id, playlist_entry_id) ⇒ Object
428 429 430 431 432 433 |
# File 'lib/tubeclip/request/video_upload.rb', line 428 def delete_video_from_playlist(playlist_id, playlist_entry_id) playlist_url = "/feeds/api/playlists/%s/%s" % [playlist_id, playlist_entry_id] response = yt_session.delete(playlist_url) return true end |
#delete_video_from_watchlater(video_id) ⇒ Object
361 362 363 364 365 366 |
# File 'lib/tubeclip/request/video_upload.rb', line 361 def delete_video_from_watchlater(video_id) playlist_url = "/feeds/api/users/default/watch_later/%s" % video_id response = yt_session.delete(playlist_url) return true end |
#enable_http_debugging ⇒ Object
39 40 41 |
# File 'lib/tubeclip/request/video_upload.rb', line 39 def enable_http_debugging @http_debugging = true end |
#favorites(user, opts = {}) ⇒ Object
472 473 474 475 476 477 |
# File 'lib/tubeclip/request/video_upload.rb', line 472 def favorites(user, opts = {}) favorite_url = "/feeds/api/users/%s/favorites#{opts.empty? ? '' : '?#{opts.to_param}'}" % (user ? user : "default") response = yt_session.get(favorite_url) return Tubeclip::Parser::VideosFeedParser.new(response.body).parse end |
#get_activity(user, opts) ⇒ Object
Return’s a user’s activity feed.
338 339 340 341 342 343 344 |
# File 'lib/tubeclip/request/video_upload.rb', line 338 def get_activity(user, opts) activity_url = "/feeds/api/events?author=%s&v=#{Tubeclip::API_VERSION}&" % (user ? user : "default") activity_url << opts.collect { |k,p| [k,p].join '=' }.join('&') response = yt_session.get(activity_url) return Tubeclip::Parser::ActivityParser.new(response).parse end |
#get_current_user ⇒ Object
479 480 481 482 483 484 |
# File 'lib/tubeclip/request/video_upload.rb', line 479 def get_current_user current_user_url = "/feeds/api/users/default" response = yt_session.get(current_user_url) return Nokogiri::XML(response.body).at("entry/author/name").text end |
#get_my_contacts(opts) ⇒ Object
Fetches the currently authenticated user’s contacts (i.e. friends). When the authentication credentials are incorrect, an AuthenticationError will be raised.
157 158 159 160 161 162 163 |
# File 'lib/tubeclip/request/video_upload.rb', line 157 def get_my_contacts(opts) contacts_url = "/feeds/api/users/default/contacts?v=#{Tubeclip::API_VERSION}" contacts_url << opts.collect { |k,p| [k,p].join '=' }.join('&') response = yt_session.get(contacts_url) return Tubeclip::Parser::ContactsParser.new(response).parse end |
#get_my_messages(opts) ⇒ Object
Fetches the currently authenticated user’s messages (i.e. inbox). When the authentication credentials are incorrect, an AuthenticationError will be raised.
175 176 177 178 179 180 181 |
# File 'lib/tubeclip/request/video_upload.rb', line 175 def (opts) = "/feeds/api/users/default/inbox" << opts.collect { |k,p| [k,p].join '=' }.join('&') response = yt_session.get() return Tubeclip::Parser::MessagesParser.new(response).parse end |
#get_my_video(video_id) ⇒ Object
Fetches the data of a video, which may be private. The video must be owned by this user. When the authentication credentials are incorrect, an AuthenticationError will be raised.
185 186 187 188 189 190 |
# File 'lib/tubeclip/request/video_upload.rb', line 185 def get_my_video(video_id) get_url = "/feeds/api/users/default/uploads/%s" % video_id response = yt_session.get(get_url) return Tubeclip::Parser::VideoFeedParser.new(response.body).parse rescue nil end |
#get_my_videos(opts) ⇒ Object
Fetches the data of the videos of the current user, which may be private. When the authentication credentials are incorrect, an AuthenticationError will be raised.
194 195 196 197 198 199 200 201 |
# File 'lib/tubeclip/request/video_upload.rb', line 194 def get_my_videos(opts) max_results = opts[:per_page] || 50 start_index = ((opts[:page] || 1) -1) * max_results +1 get_url = "/feeds/api/users/default/uploads?max-results=#{max_results}&start-index=#{start_index}" response = yt_session.get(get_url) return Tubeclip::Parser::VideosFeedParser.new(response.body).parse end |
#get_upload_token(options, nexturl) ⇒ Object
219 220 221 222 223 224 225 226 227 |
# File 'lib/tubeclip/request/video_upload.rb', line 219 def get_upload_token(, nexturl) @opts = token_body = video_xml token_url = "/action/GetUploadToken" response = yt_session.post(token_url, token_body) return {:url => "#{response.body[/<url>(.+)<\/url>/, 1]}?nexturl=#{nexturl}", :token => response.body[/<token>(.+)<\/token>/, 1]} end |
#get_watch_history ⇒ Object
501 502 503 504 505 506 |
# File 'lib/tubeclip/request/video_upload.rb', line 501 def get_watch_history watch_history_url = "/feeds/api/users/default/watch_history?v=#{Tubeclip::API_VERSION}" response = yt_session.get(watch_history_url) return Tubeclip::Parser::VideosFeedParser.new(response.body).parse end |
#new_subscription_videos(user) ⇒ Object
508 509 510 511 512 513 |
# File 'lib/tubeclip/request/video_upload.rb', line 508 def new_subscription_videos(user) subscription_url = "/feeds/api/users/%s/newsubscriptionvideos?v=#{Tubeclip::API_VERSION}" % (user ? user : "default") response = yt_session.get(subscription_url) return Tubeclip::Parser::VideosFeedParser.new(response.body).parse end |
#partial_update(video_id, options) ⇒ Object
Partial updates to a video.
129 130 131 132 133 134 135 136 |
# File 'lib/tubeclip/request/video_upload.rb', line 129 def partial_update(video_id, ) update_body = partial_video_xml() update_url = "/feeds/api/users/default/uploads/%s" % video_id update_header = { "Content-Type" => "application/xml" } response = yt_session.patch(update_url, update_body, update_header) return Tubeclip::Parser::VideoFeedParser.new(response.body).parse rescue nil end |
#playlist(playlist_id, opts = {}) ⇒ Object
368 369 370 371 372 373 374 375 376 |
# File 'lib/tubeclip/request/video_upload.rb', line 368 def playlist(playlist_id, opts = {}) playlist_url = "/feeds/api/playlists/%s" % playlist_id params = {'v' => 2, 'orderby' => 'position'} params.merge!(opts) if opts playlist_url << "?#{params.collect { |k,v| [k,v].join '=' }.join('&')}" response = yt_session.get(playlist_url) return Tubeclip::Parser::PlaylistFeedParser.new(response).parse end |
#playlists(user, opts = {}) ⇒ Object
Fetches playlists for the given user. An optional hash of parameters can be given and will be appended to the request. Paging parameters will need to be used to access playlists beyond the most recent 25 (page size default for YouTube API at the time of this writing) if a user has more than 25 playlists.
Paging parameters include the following start-index - 1-based index of which playlist to start from (default is 1) max-results - maximum number of playlists to fetch, up to 25 (default is 25)
386 387 388 389 390 391 392 393 394 |
# File 'lib/tubeclip/request/video_upload.rb', line 386 def playlists(user, opts={}) playlist_url = "/feeds/api/users/%s/playlists" % (user ? user : "default") params = {'v' => Tubeclip::API_VERSION} params.merge!(opts) if opts playlist_url << "?#{params.collect { |k,v| [k,v].join '=' }.join('&')}" response = yt_session.get(playlist_url) return Tubeclip::Parser::PlaylistsFeedParser.new(response).parse end |
#profile(user = nil) ⇒ Object
269 270 271 272 273 |
# File 'lib/tubeclip/request/video_upload.rb', line 269 def profile(user=nil) response = yt_session.get(profile_url(user)) return Tubeclip::Parser::ProfileFeedParser.new(response).parse end |
#profile_url(user = nil) ⇒ Object
333 334 335 |
# File 'lib/tubeclip/request/video_upload.rb', line 333 def profile_url(user=nil) "/feeds/api/users/%s?v=#{Tubeclip::API_VERSION}" % (user || "default") end |
#profiles(usernames_to_fetch) ⇒ Object
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/tubeclip/request/video_upload.rb', line 304 def profiles(usernames_to_fetch) usernames_to_fetch.each_slice(50).map do |usernames| post = Nokogiri::XML <<-BATCH <feed xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:yt='http://gdata.youtube.com/schemas/2007'> </feed> BATCH usernames.each do |username| post.at('feed').add_child <<-ENTRY <entry> <batch:operation type="query" /> <id>#{profile_url(username)}</id> <batch:id>#{username}</batch:id> </entry> ENTRY end post_body = StringIO.new('') post.write_to( post_body, :indent => 2 ) post_body_io = StringIO.new(post_body.string) response = yt_session.post('feeds/api/users/batch', post_body_io ) Tubeclip::Parser::BatchProfileFeedParser.new(response).parse end.reduce({},:merge) end |
#rate_video(video_id, rating) ⇒ Object
442 443 444 445 446 447 448 |
# File 'lib/tubeclip/request/video_upload.rb', line 442 def rate_video(video_id, ) = video_xml_for(:rating => ) = "/feeds/api/videos/#{video_id}/ratings" response = yt_session.post(, ) return {:code => response.status, :body => response.body} end |
#send_message(opts) ⇒ Object
165 166 167 168 169 170 171 |
# File 'lib/tubeclip/request/video_upload.rb', line 165 def (opts) = (opts) = "/feeds/api/users/%s/inbox" % opts[:recipient_id] response = yt_session.post(, ) return {:code => response.status, :body => response.body} end |
#subscribe_channel(channel_name) ⇒ Object
457 458 459 460 461 462 463 |
# File 'lib/tubeclip/request/video_upload.rb', line 457 def subscribe_channel(channel_name) subscribe_body = video_xml_for(:subscribe => channel_name) subscribe_url = "/feeds/api/users/default/subscriptions" response = yt_session.post(subscribe_url, subscribe_body) return {:code => response.status, :body => response.body} end |
#subscriptions(user) ⇒ Object
450 451 452 453 454 455 |
# File 'lib/tubeclip/request/video_upload.rb', line 450 def subscriptions(user) subscription_url = "/feeds/api/users/%s/subscriptions?v=#{Tubeclip::API_VERSION}" % (user ? user : "default") response = yt_session.get(subscription_url) return Tubeclip::Parser::SubscriptionFeedParser.new(response).parse end |
#unsubscribe_channel(subscription_id) ⇒ Object
465 466 467 468 469 470 |
# File 'lib/tubeclip/request/video_upload.rb', line 465 def unsubscribe_channel(subscription_id) unsubscribe_url = "/feeds/api/users/default/subscriptions/%s" % subscription_id response = yt_session.delete(unsubscribe_url) return {:code => response.status, :body => response.body} end |
#update(video_id, options) ⇒ Object
Updates a video in YouTube. Requires:
:title
:description
:category
:keywords
The following are optional attributes:
:private
When the authentication credentials are incorrect, an AuthenticationError will be raised.
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/tubeclip/request/video_upload.rb', line 115 def update(video_id, ) @opts = { :title => '', :description => '', :category => 'People', :keywords => [] }.merge() update_body = video_xml update_url = "/feeds/api/users/default/uploads/%s" % video_id response = yt_session.put(update_url, update_body) return Tubeclip::Parser::VideoFeedParser.new(response.body).parse rescue nil end |
#update_playlist(playlist_id, options) ⇒ Object
420 421 422 423 424 425 426 |
# File 'lib/tubeclip/request/video_upload.rb', line 420 def update_playlist(playlist_id, ) playlist_body = video_xml_for_playlist() playlist_url = "/feeds/api/users/default/playlists/%s" % playlist_id response = yt_session.put(playlist_url, playlist_body) return Tubeclip::Parser::PlaylistFeedParser.new(response).parse end |
#update_position_video_from_playlist(playlist_id, playlist_entry_id, position) ⇒ Object
412 413 414 415 416 417 418 |
# File 'lib/tubeclip/request/video_upload.rb', line 412 def update_position_video_from_playlist(playlist_id, playlist_entry_id, position) playlist_body = video_xml_for(:position => position) playlist_url = "/feeds/api/playlists/%s/%s" % [playlist_id, playlist_entry_id] response = yt_session.put(playlist_url, playlist_body) return {:code => response.status, :body => response.body, :playlist_entry_id => get_entry_id(response.body)} end |
#upload(video_data, opts = {}) ⇒ Object
Upload “data” to youtube, where data is either an IO object or raw file data. The hash keys for opts (which specify video info) are as follows:
:mime_type
:filename
:title
:description
:category
:keywords
:private
New V2 api hash keys for accessControl:
:rate
:comment
:commentVote
:videoRespond
:list
:embed
:syndicate
Specifying :private will make the video private, otherwise it will be public.
When one of the fields is invalid according to YouTube, an UploadError will be raised. Its message contains a list of newline separated errors, containing the key and its error code.
When the authentication credentials are incorrect, an AuthenticationError will be raised.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/tubeclip/request/video_upload.rb', line 77 def upload(video_data, opts = {}) if video_data.is_a?(String) && uri?(video_data) data = Tubeclip::Upload::RemoteFile.new(video_data, opts) else data = video_data end @opts = { :mime_type => 'video/mp4', :title => '', :description => '', :category => 'People', :keywords => [] }.merge(opts) @opts[:filename] ||= generate_uniq_filename_from(data) post_body_io = generate_upload_io(video_xml, data) upload_header = { "Slug" => "#{@opts[:filename]}", "Content-Type" => "multipart/related; boundary=#{boundary}", "Content-Length" => "#{post_body_io.expected_length}", } upload_url = "/feeds/api/users/default/uploads" response = yt_session(uploads_url).post(upload_url, post_body_io, upload_header) return Tubeclip::Parser::VideoFeedParser.new(response.body).parse rescue nil end |
#uri?(string) ⇒ Boolean
43 44 45 46 47 48 49 50 |
# File 'lib/tubeclip/request/video_upload.rb', line 43 def uri?(string) uri = URI.parse(string) %w( http https ).include?(uri.scheme) rescue URI::BadURIError false rescue URI::InvalidURIError false end |
#videos(idxes_to_fetch) ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/tubeclip/request/video_upload.rb', line 275 def videos(idxes_to_fetch) idxes_to_fetch.each_slice(50).map do |idxes| post = Nokogiri::XML <<-BATCH <feed xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:yt='http://gdata.youtube.com/schemas/2007'> </feed> BATCH idxes.each do |idx| post.at('feed').add_child <<-ENTRY <entry> <batch:operation type="query" /> <id>/feeds/api/videos/#{idx}?v=#{Tubeclip::API_VERSION}</id> <batch:id>#{idx}</batch:id> </entry> ENTRY end post_body = StringIO.new('') post.write_to( post_body, :indent => 2 ) post_body_io = StringIO.new(post_body.string) response = yt_session.post('feeds/api/videos/batch', post_body_io ) Tubeclip::Parser::BatchVideoFeedParser.new(response).parse end.reduce({},:merge) end |
#watchlater(user) ⇒ Object
346 347 348 349 350 351 |
# File 'lib/tubeclip/request/video_upload.rb', line 346 def watchlater(user) watchlater_url = "/feeds/api/users/%s/watch_later?v=#{Tubeclip::API_VERSION}" % (user ? user : "default") response = yt_session.get(watchlater_url) return Tubeclip::Parser::PlaylistFeedParser.new(response).parse end |