Class: YouTubeG::Upload::VideoUpload
- Inherits:
-
Object
- Object
- YouTubeG::Upload::VideoUpload
- Defined in:
- lib/youtube_g/request/video_upload.rb
Overview
require ‘youtube_g’
uploader = YouTubeG::Upload::VideoUpload.new(“user”, “pass”, “dev-key”) uploader.upload File.open(“test.m4v”), :title => ‘test’,
:description => 'cool vid d00d',
:category => 'People',
:keywords => %w[cool blah test]
Instance Method Summary collapse
-
#initialize(user, pass, dev_key, client_id = 'youtube_g') ⇒ VideoUpload
constructor
A new instance of VideoUpload.
-
#upload(data, opts = {}) ⇒ Object
Upload “data” to youtube, where data is either an IO object or raw file data.
Constructor Details
#initialize(user, pass, dev_key, client_id = 'youtube_g') ⇒ VideoUpload
Returns a new instance of VideoUpload.
21 22 23 |
# File 'lib/youtube_g/request/video_upload.rb', line 21 def initialize user, pass, dev_key, client_id = 'youtube_g' @user, @pass, @dev_key, @client_id = user, pass, dev_key, client_id end |
Instance Method Details
#upload(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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/youtube_g/request/video_upload.rb', line 37 def upload data, opts = {} data = data.respond_to?(:read) ? data.read : data @opts = { :mime_type => 'video/mp4', :filename => Digest::MD5.hexdigest(data), :title => '', :description => '', :category => '', :keywords => [] }.merge(opts) uploadBody = generate_upload_body(boundary, video_xml, data) uploadHeader = { "Authorization" => "GoogleLogin auth=#{auth_token}", "X-GData-Client" => "#{@client_id}", "X-GData-Key" => "key=#{@dev_key}", "Slug" => "#{@opts[:filename]}", "Content-Type" => "multipart/related; boundary=#{boundary}", "Content-Length" => "#{uploadBody.length}" } Net::HTTP.start(base_url) do |upload| response = upload.post('/feeds/api/users/' << @user << '/uploads', uploadBody, uploadHeader) xml = REXML::Document.new(response.body) return xml.elements["//id"].text[/videos\/(.+)/, 1] end end |