mikedamage-ruby_tube 0.2.4 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/ruby_tube.rb +1 -0
- data/lib/ruby_tube_no_auth.rb +72 -0
- data/lib/yt_client.rb +6 -6
- metadata +2 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2
|
1
|
+
0.3.2
|
data/lib/ruby_tube.rb
CHANGED
@@ -2,6 +2,7 @@ require File.join(File.dirname(__FILE__), "yt_client.rb")
|
|
2
2
|
require File.join(File.dirname(__FILE__), "yt_video.rb")
|
3
3
|
require File.join(File.dirname(__FILE__), "yt_comment.rb")
|
4
4
|
require File.join(File.dirname(__FILE__), "yt_rating.rb")
|
5
|
+
require File.join(File.dirname(__FILE__), "ruby_tube_no_auth.rb")
|
5
6
|
|
6
7
|
class RubyTube < YTClient
|
7
8
|
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class RubyTubeNoAuth
|
2
|
+
attr_accessor :client
|
3
|
+
|
4
|
+
def initialize(dev_key="")
|
5
|
+
@client = GData::Client::YouTube.new
|
6
|
+
@client.source = "RubyTube"
|
7
|
+
if dev_key
|
8
|
+
@client.developer_key = dev_key
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(id)
|
13
|
+
res = @client.get("http://gdata.youtube.com/feeds/api/videos/#{id}")
|
14
|
+
xml = Hpricot.XML(res.body)
|
15
|
+
entry = xml.at("entry")
|
16
|
+
vid = YTVideo.new({
|
17
|
+
:id => (entry/"yt:videoid").text,
|
18
|
+
:title => (entry/"title").text,
|
19
|
+
:description => (entry/"media:description").text,
|
20
|
+
:keywords => (entry/"media:keywords").text,
|
21
|
+
:duration => (entry/"yt:duration").attr("seconds").to_i,
|
22
|
+
:player_uri => (entry/"link[@rel='alternate']").attr("href"),
|
23
|
+
:ratings_uri => (entry/"link[@rel$='ratings']").attr("href"),
|
24
|
+
:comments_uri => (entry/"gd:comments").search("gd:feedlink").attr("href"),
|
25
|
+
:comment_count => (entry/"gd:comments").search("gd:feedlink").attr("countHint").to_i,
|
26
|
+
:published_at => Time.parse((entry/"published").text),
|
27
|
+
:updated_at => Time.parse((entry/"updated").text),
|
28
|
+
:view_count => (entry/"yt:statistics").nil? ? 0 : (entry/"yt:statistics").attr("viewCount"),
|
29
|
+
:favorite_count => (entry/"yt:statistics").nil? ? 0 : (entry/"yt:statistics").attr("favoriteCount"),
|
30
|
+
:comments => comments((entry/"yt:videoid").text),
|
31
|
+
:ratings => ratings((entry/"yt:videoid").text),
|
32
|
+
:status => status,
|
33
|
+
:thumbnails => process_thumbnail_urls(entry)
|
34
|
+
})
|
35
|
+
vid
|
36
|
+
end
|
37
|
+
|
38
|
+
def comments(id)
|
39
|
+
res = @client.get("http://gdata.youtube.com/feeds/api/videos/#{id}/comments")
|
40
|
+
xml = Hpricot.XML(res.body)
|
41
|
+
comments = Array.new
|
42
|
+
if (xml/"entry").nitems > 0
|
43
|
+
(xml/"entry").each do |entry|
|
44
|
+
cmt = YTComment.new({
|
45
|
+
:title => (entry/"title").text,
|
46
|
+
:content => (entry/"content").text,
|
47
|
+
:author => (entry/"author").search("name").text,
|
48
|
+
:author_uri => (entry/"author").search("uri").text,
|
49
|
+
:video_uri => (entry/"link[@rel='related']").attr("href")
|
50
|
+
})
|
51
|
+
comments << cmt
|
52
|
+
end
|
53
|
+
end
|
54
|
+
comments
|
55
|
+
end
|
56
|
+
|
57
|
+
def ratings(id)
|
58
|
+
response = Hpricot.XML(@client.get("http://gdata.youtube.com/feeds/api/videos/#{id}").body)
|
59
|
+
ratings = (response/"gd:rating")
|
60
|
+
if ratings.nitems > 0
|
61
|
+
return ratings
|
62
|
+
else
|
63
|
+
return nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def process_thumbnail_urls(hpricot)
|
69
|
+
thumbs = (hpricot/"media:thumbnail")
|
70
|
+
{:big => thumbs.last["url"], :small => thumbs.first["url"]}
|
71
|
+
end
|
72
|
+
end
|
data/lib/yt_client.rb
CHANGED
@@ -28,12 +28,12 @@ class YTClient
|
|
28
28
|
def all
|
29
29
|
if @all_vids
|
30
30
|
if Time.parse((@all_vids/"updated").text) < (Time.now - @options[:refresh])
|
31
|
-
@all_vids = Hpricot(@client.get(self.class.base_uri + "/users/default/uploads").body)
|
31
|
+
@all_vids = Hpricot.XML(@client.get(self.class.base_uri + "/users/default/uploads").body)
|
32
32
|
else
|
33
33
|
return @all_vids
|
34
34
|
end
|
35
35
|
else
|
36
|
-
@all_vids = Hpricot(@client.get(self.class.base_uri + "/users/default/uploads").body)
|
36
|
+
@all_vids = Hpricot.XML(@client.get(self.class.base_uri + "/users/default/uploads").body)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -42,11 +42,11 @@ class YTClient
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def check_video(id)
|
45
|
-
Hpricot(@client.get(self.class.base_uri + "/videos/#{id}").body)
|
45
|
+
Hpricot.XML(@client.get(self.class.base_uri + "/videos/#{id}").body)
|
46
46
|
end
|
47
47
|
|
48
48
|
def ratings(id)
|
49
|
-
response = Hpricot(@client.get(self.class.base_uri + "/videos/#{id}").body)
|
49
|
+
response = Hpricot.XML(@client.get(self.class.base_uri + "/videos/#{id}").body)
|
50
50
|
ratings = (response/"gd:rating")
|
51
51
|
if ratings.nitems > 0
|
52
52
|
return ratings
|
@@ -56,7 +56,7 @@ class YTClient
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def comments(id)
|
59
|
-
Hpricot(@client.get(self.class.base_uri + "/videos/#{id}/comments").body)
|
59
|
+
Hpricot.XML(@client.get(self.class.base_uri + "/videos/#{id}/comments").body)
|
60
60
|
end
|
61
61
|
|
62
62
|
def upload(file, options={})
|
@@ -99,7 +99,7 @@ REQDATA
|
|
99
99
|
'Connection' => 'close'
|
100
100
|
}
|
101
101
|
res = http.post(upload_uri.path, request_data, headers)
|
102
|
-
response = {:code => res.code, :body => Hpricot(res.body)}
|
102
|
+
response = {:code => res.code, :body => Hpricot.XML(res.body)}
|
103
103
|
return response
|
104
104
|
end
|
105
105
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mikedamage-ruby_tube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Green
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- Rakefile
|
60
60
|
- VERSION
|
61
61
|
- lib/ruby_tube.rb
|
62
|
+
- lib/ruby_tube_no_auth.rb
|
62
63
|
- lib/yt_client.rb
|
63
64
|
- lib/yt_comment.rb
|
64
65
|
- lib/yt_rating.rb
|