youtube_it 2.3.1 → 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -0
- data/lib/youtube_it.rb +3 -2
- data/lib/youtube_it/chain_io.rb +19 -9
- data/lib/youtube_it/request/remote_file.rb +68 -0
- data/lib/youtube_it/request/video_upload.rb +19 -4
- data/lib/youtube_it/version.rb +1 -1
- data/youtube_it.gemspec +2 -1
- metadata +19 -7
data/README.rdoc
CHANGED
@@ -133,6 +133,9 @@ Upload Video:
|
|
133
133
|
Upload Video With A Developer Tag (Note the tags are not immediately available):
|
134
134
|
$ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :dev_tag => 'tagdev')
|
135
135
|
|
136
|
+
Upload Video from url:
|
137
|
+
$ client.video_upload("http://media.railscasts.com/assets/episodes/videos/412-fast-rails-commands.mp4", :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test])
|
138
|
+
|
136
139
|
Upload Private Video:
|
137
140
|
$ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :private => true)
|
138
141
|
|
data/lib/youtube_it.rb
CHANGED
@@ -37,11 +37,11 @@ class YouTubeIt
|
|
37
37
|
def self.adapter=(faraday_adapter)
|
38
38
|
@adapter = faraday_adapter
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def self.adapter
|
42
42
|
@adapter ||= Faraday.default_adapter
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
# Gets mixed into the classes to provide the logger method
|
46
46
|
module Logging #:nodoc:
|
47
47
|
|
@@ -84,6 +84,7 @@ end
|
|
84
84
|
request/standard_search
|
85
85
|
request/video_upload
|
86
86
|
request/video_search
|
87
|
+
request/remote_file
|
87
88
|
response/video_search
|
88
89
|
middleware/faraday_authheader.rb
|
89
90
|
middleware/faraday_oauth.rb
|
data/lib/youtube_it/chain_io.rb
CHANGED
@@ -18,7 +18,7 @@ class YouTubeIt::ChainIO
|
|
18
18
|
# Read off the first element in the stack
|
19
19
|
current_io = @chain.shift
|
20
20
|
return false if !current_io
|
21
|
-
|
21
|
+
|
22
22
|
buf = current_io.read(buffer_size)
|
23
23
|
if !buf && @chain.empty? # End of streams
|
24
24
|
release_handle(current_io) if @autoclose
|
@@ -34,8 +34,8 @@ class YouTubeIt::ChainIO
|
|
34
34
|
buf
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
38
|
-
# Predict the length of all embedded IOs. Will automatically send file size.
|
37
|
+
|
38
|
+
# Predict the length of all embedded IOs. Will automatically send file size.
|
39
39
|
def expected_length
|
40
40
|
@chain.inject(0) do | len, io |
|
41
41
|
if io.respond_to?(:length)
|
@@ -47,30 +47,40 @@ class YouTubeIt::ChainIO
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
private
|
52
52
|
def release_handle(io)
|
53
53
|
io.close if io.respond_to?(:close)
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
# Net::HTTP only can send chunks of 1024 bytes. This is very inefficient, so we have a spare IO that will send more when asked for 1024.
|
58
58
|
# We use delegation because the read call is recursive.
|
59
59
|
class YouTubeIt::GreedyChainIO < DelegateClass(YouTubeIt::ChainIO)
|
60
60
|
BIG_CHUNK = 512 * 1024 # 500 kb
|
61
|
-
|
61
|
+
|
62
62
|
def initialize(*with_ios)
|
63
63
|
__setobj__(YouTubeIt::ChainIO.new(with_ios))
|
64
64
|
end
|
65
|
-
|
66
|
-
def read(
|
67
|
-
__getobj__.read(
|
65
|
+
|
66
|
+
def read(size = BIG_CHUNK, dst_buf = nil)
|
67
|
+
src_buf = __getobj__.read(size)
|
68
|
+
return nil unless src_buf
|
69
|
+
copy_buf(src_buf, dst_buf) if dst_buf
|
70
|
+
src_buf
|
68
71
|
end
|
69
72
|
|
70
73
|
def length()
|
71
74
|
__getobj__.expected_length
|
72
75
|
end
|
73
76
|
|
77
|
+
private
|
78
|
+
|
79
|
+
def copy_buf(src_buf, dst_buf)
|
80
|
+
dst_buf[0..-1] = ''
|
81
|
+
dst_buf << src_buf
|
82
|
+
end
|
83
|
+
|
74
84
|
end
|
75
85
|
|
76
86
|
#:startdoc:
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'fiber'
|
4
|
+
class YouTubeIt
|
5
|
+
module Upload
|
6
|
+
|
7
|
+
|
8
|
+
class RemoteFile
|
9
|
+
def initialize( url)
|
10
|
+
@pos = 0
|
11
|
+
@url = url
|
12
|
+
@uri = URI(@url)
|
13
|
+
|
14
|
+
@fiber = Fiber.new do |first|
|
15
|
+
|
16
|
+
Net::HTTP.start(@uri.host, @uri.port) do |http|
|
17
|
+
request = Net::HTTP::Get.new @uri.request_uri
|
18
|
+
http.request request do |response|
|
19
|
+
response.read_body do |chunk|
|
20
|
+
@pos += chunk.bytesize
|
21
|
+
Fiber.yield chunk
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def ping?
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def pos
|
34
|
+
@pos
|
35
|
+
end
|
36
|
+
|
37
|
+
def head
|
38
|
+
@head_result || Net::HTTP.start(@uri.host, @uri.port) do |http|
|
39
|
+
@head_result = http.request(Net::HTTP::Head.new(@uri.request_uri))
|
40
|
+
end
|
41
|
+
@head_result
|
42
|
+
end
|
43
|
+
|
44
|
+
def filename
|
45
|
+
File.basename(@url)
|
46
|
+
end
|
47
|
+
|
48
|
+
def path
|
49
|
+
@url
|
50
|
+
end
|
51
|
+
|
52
|
+
def length
|
53
|
+
@content_length ||= head.content_length
|
54
|
+
return @content_length
|
55
|
+
end
|
56
|
+
|
57
|
+
def read(buf_size = 524288)
|
58
|
+
buf = ""
|
59
|
+
while (buf.bytesize < buf_size.to_i) && @fiber.alive?
|
60
|
+
_chunk = @fiber.resume
|
61
|
+
buf << _chunk if _chunk.is_a? String
|
62
|
+
end
|
63
|
+
buf
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -45,6 +45,14 @@ class YouTubeIt
|
|
45
45
|
@http_debugging = true
|
46
46
|
end
|
47
47
|
|
48
|
+
def uri?(string)
|
49
|
+
uri = URI.parse(string)
|
50
|
+
%w( http https ).include?(uri.scheme)
|
51
|
+
rescue URI::BadURIError
|
52
|
+
false
|
53
|
+
rescue URI::InvalidURIError
|
54
|
+
false
|
55
|
+
end
|
48
56
|
#
|
49
57
|
# Upload "data" to youtube, where data is either an IO object or
|
50
58
|
# raw file data.
|
@@ -71,7 +79,14 @@ class YouTubeIt
|
|
71
79
|
# errors, containing the key and its error code.
|
72
80
|
#
|
73
81
|
# When the authentication credentials are incorrect, an AuthenticationError will be raised.
|
74
|
-
def upload(
|
82
|
+
def upload(video_data, opts = {})
|
83
|
+
|
84
|
+
if video_data.is_a?(String) && uri?(video_data)
|
85
|
+
data = YouTubeIt::Upload::RemoteFile.new(video_data)
|
86
|
+
else
|
87
|
+
data = video_data
|
88
|
+
end
|
89
|
+
|
75
90
|
@opts = { :mime_type => 'video/mp4',
|
76
91
|
:title => '',
|
77
92
|
:description => '',
|
@@ -265,7 +280,7 @@ class YouTubeIt
|
|
265
280
|
def videos(idxes_to_fetch)
|
266
281
|
idxes_to_fetch.each_slice(50).map do |idxes|
|
267
282
|
post = Nokogiri::XML <<-BATCH
|
268
|
-
<feed
|
283
|
+
<feed
|
269
284
|
xmlns='http://www.w3.org/2005/Atom'
|
270
285
|
xmlns:media='http://search.yahoo.com/mrss/'
|
271
286
|
xmlns:batch='http://schemas.google.com/gdata/batch'
|
@@ -290,7 +305,7 @@ class YouTubeIt
|
|
290
305
|
YouTubeIt::Parser::BatchVideoFeedParser.new(response).parse
|
291
306
|
end.reduce({},:merge)
|
292
307
|
end
|
293
|
-
|
308
|
+
|
294
309
|
def profiles(usernames_to_fetch)
|
295
310
|
usernames_to_fetch.each_slice(50).map do |usernames|
|
296
311
|
post = Nokogiri::XML <<-BATCH
|
@@ -740,7 +755,7 @@ class YouTubeIt
|
|
740
755
|
end
|
741
756
|
builder.use FaradayMiddleware::YoutubeAuthHeader, authorization_headers
|
742
757
|
builder.use Faraday::Response::YouTubeIt
|
743
|
-
builder.adapter
|
758
|
+
builder.adapter Faraday.default_adapter
|
744
759
|
end
|
745
760
|
end
|
746
761
|
end
|
data/lib/youtube_it/version.rb
CHANGED
data/youtube_it.gemspec
CHANGED
@@ -20,7 +20,8 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_runtime_dependency("simple_oauth", ">= 0.1.5")
|
21
21
|
s.add_runtime_dependency("faraday", "~> 0.8")
|
22
22
|
s.add_runtime_dependency("builder", ">= 0")
|
23
|
-
s.add_runtime_dependency("
|
23
|
+
s.add_runtime_dependency("webmock")
|
24
|
+
s.add_runtime_dependency("excon")
|
24
25
|
s.add_runtime_dependency("json", "~> 1.8.0")
|
25
26
|
s.files = Dir.glob("lib/**/*") + %w(README.rdoc youtube_it.gemspec)
|
26
27
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: youtube_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 2.3.
|
5
|
+
version: 2.3.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- kylejginavan
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-06-28 00:00:00 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: nokogiri
|
@@ -80,27 +80,38 @@ dependencies:
|
|
80
80
|
type: :runtime
|
81
81
|
version_requirements: *id006
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
|
-
name:
|
83
|
+
name: webmock
|
84
84
|
prerelease: false
|
85
85
|
requirement: &id007 !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
87
87
|
requirements:
|
88
|
-
- -
|
88
|
+
- - ">="
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: 0
|
90
|
+
version: "0"
|
91
91
|
type: :runtime
|
92
92
|
version_requirements: *id007
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
|
-
name:
|
94
|
+
name: excon
|
95
95
|
prerelease: false
|
96
96
|
requirement: &id008 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: "0"
|
102
|
+
type: :runtime
|
103
|
+
version_requirements: *id008
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: json
|
106
|
+
prerelease: false
|
107
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
97
108
|
none: false
|
98
109
|
requirements:
|
99
110
|
- - ~>
|
100
111
|
- !ruby/object:Gem::Version
|
101
112
|
version: 1.8.0
|
102
113
|
type: :runtime
|
103
|
-
version_requirements: *
|
114
|
+
version_requirements: *id009
|
104
115
|
description: Upload, delete, update, comment on youtube videos all from one gem.
|
105
116
|
email:
|
106
117
|
- kylejginavan@gmail.com
|
@@ -138,6 +149,7 @@ files:
|
|
138
149
|
- lib/youtube_it/model/video.rb
|
139
150
|
- lib/youtube_it/request/base_search.rb
|
140
151
|
- lib/youtube_it/request/error.rb
|
152
|
+
- lib/youtube_it/request/remote_file.rb
|
141
153
|
- lib/youtube_it/request/standard_search.rb
|
142
154
|
- lib/youtube_it/request/user_search.rb
|
143
155
|
- lib/youtube_it/request/video_search.rb
|