ruboty-youtube 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/ruboty/youtube/client.rb +52 -19
- data/lib/ruboty/youtube/version.rb +1 -1
- data/ruboty-youtube.gemspec +2 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01271da19abfd2f82e2559926460a955ed4045ef
|
4
|
+
data.tar.gz: cfe2bb7b9da167a6f5c728e634731ac4093cf8a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a46ebbef24baee29293c179d72cc826610afb35fb2db1109ae3daea6d3f714d4d6c91cae12f209b6d8e1bbf5bb3f9267ccf91a1680a75285e3c90faf2fa4ef2d
|
7
|
+
data.tar.gz: 6886af5e9036d931e6488459b010cf2beed9bbcebaa07b0db78452e69974b919bba21c5b34439ae38d533bfdce8024fd32f211e9d63aa8a88798b7d6e58eba48
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Ruboty::Youtube
|
2
2
|
|
3
|
-
Ruboty handler to search
|
3
|
+
Ruboty handler to search from YouTube.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -14,5 +14,6 @@ gem 'ruboty-youtube'
|
|
14
14
|
|
15
15
|
```
|
16
16
|
@ruboty yt top <keyword> - Search a movie from YouTube
|
17
|
-
@ruboty yt rand <keyword> - Search a
|
17
|
+
@ruboty yt rand <keyword> - Search a movie randomly from YouTube
|
18
|
+
@ruboty yt pl <keyword> - Search a playlist from YouTube
|
18
19
|
```
|
@@ -1,13 +1,16 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
3
|
require 'faraday'
|
4
|
+
require 'mechanize'
|
4
5
|
|
5
6
|
module Ruboty
|
6
7
|
module Youtube
|
7
8
|
class Client
|
9
|
+
YOUTUBE_URL = 'https://www.youtube.com'
|
8
10
|
YOUTUBE_API_URL = 'http://gdata.youtube.com'
|
9
11
|
|
10
12
|
def initialize(query, mode)
|
13
|
+
@agent = Mechanize.new
|
11
14
|
@conn = Faraday.new(url: YOUTUBE_API_URL) do |faraday|
|
12
15
|
faraday.request :url_encoded
|
13
16
|
faraday.adapter Faraday.default_adapter
|
@@ -18,35 +21,65 @@ module Ruboty
|
|
18
21
|
|
19
22
|
def get
|
20
23
|
response = @conn.get do |req|
|
21
|
-
req.url
|
24
|
+
req.url api_path, params
|
22
25
|
end.body
|
23
|
-
|
24
|
-
# when @mode is :top -> videos.length is 1
|
25
|
-
videos.sample['link'].first['href']
|
26
|
+
parse_response(response)
|
26
27
|
rescue
|
27
28
|
nil
|
28
29
|
end
|
29
30
|
|
30
31
|
private
|
31
32
|
|
32
|
-
def
|
33
|
+
def parse_response(response)
|
34
|
+
videos = JSON.parse(response)['feed']['entry']
|
35
|
+
|
33
36
|
case @mode
|
34
|
-
when :top
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
when :rand
|
42
|
-
{
|
43
|
-
orderBy: "relevance",
|
44
|
-
'max-results' => 15,
|
45
|
-
alt: 'json',
|
46
|
-
q: @query
|
47
|
-
}
|
37
|
+
when :top, :rand
|
38
|
+
# when @mode is :top -> videos.length is 1
|
39
|
+
videos.sample['link'][0]['href']
|
40
|
+
when :pl
|
41
|
+
pl_url = videos.sample['link'][1]['href']
|
42
|
+
page = @agent.get(pl_url)
|
43
|
+
YOUTUBE_URL + page.link_with(href: /\/watch/).href
|
48
44
|
end
|
49
45
|
end
|
46
|
+
|
47
|
+
def api_path
|
48
|
+
case @mode
|
49
|
+
when :top, :rand
|
50
|
+
'/feeds/api/videos'
|
51
|
+
when :pl
|
52
|
+
'/feeds/api/playlists/snippets'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def params
|
57
|
+
default_params = {
|
58
|
+
alt: 'json',
|
59
|
+
q: @query
|
60
|
+
}
|
61
|
+
|
62
|
+
params =
|
63
|
+
case @mode
|
64
|
+
when :top
|
65
|
+
{
|
66
|
+
orderBy: "relevance",
|
67
|
+
'max-results' => 1
|
68
|
+
}
|
69
|
+
when :rand
|
70
|
+
{
|
71
|
+
orderBy: "relevance",
|
72
|
+
'max-results' => 15
|
73
|
+
}
|
74
|
+
when :pl
|
75
|
+
{
|
76
|
+
v: 2,
|
77
|
+
'max-results' => 1
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
default_params.merge(params)
|
82
|
+
end
|
50
83
|
end
|
51
84
|
end
|
52
85
|
end
|
data/ruboty-youtube.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.version = Ruboty::Youtube::VERSION
|
7
7
|
spec.authors = ['kaihar4']
|
8
8
|
spec.email = ['kaihar4@gmail.com']
|
9
|
-
spec.summary = '
|
9
|
+
spec.summary = 'Ruboty handler to search from YouTube.'
|
10
10
|
spec.description = spec.summary
|
11
11
|
spec.homepage = 'https://github.com/kaihar4/ruboty-youtube'
|
12
12
|
spec.license = 'MIT'
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
|
19
19
|
spec.add_dependency 'ruboty'
|
20
20
|
spec.add_dependency 'faraday'
|
21
|
+
spec.add_dependency 'mechanize'
|
21
22
|
|
22
23
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-youtube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaihar4
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mechanize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +80,7 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '10.0'
|
69
|
-
description:
|
83
|
+
description: Ruboty handler to search from YouTube.
|
70
84
|
email:
|
71
85
|
- kaihar4@gmail.com
|
72
86
|
executables: []
|
@@ -106,5 +120,5 @@ rubyforge_project:
|
|
106
120
|
rubygems_version: 2.2.2
|
107
121
|
signing_key:
|
108
122
|
specification_version: 4
|
109
|
-
summary:
|
123
|
+
summary: Ruboty handler to search from YouTube.
|
110
124
|
test_files: []
|