ruboty-youtube 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -4
- data/lib/ruboty/handlers/youtube.rb +16 -9
- data/lib/ruboty/youtube/client.rb +8 -7
- data/lib/ruboty/youtube/version.rb +1 -1
- data/ruboty-youtube.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1aa78fe2e84056fbfd105a91c11c74f77545c0ba
|
4
|
+
data.tar.gz: 0fa67331fd1b867a40d91d1de05c894a335755d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb027275ed4ae4d04c5bb0fd7ce18b8c5f9a57d5f89e1bfad8790790917af01f7952a9c74662ecdf8ddafd06fbcb230d2bb3f9f8f5a9cc0991d9dd7789188f39
|
7
|
+
data.tar.gz: 0eb3fb79d8dae12cace2210b5c2ff7cd448e765e579530f888d7a79d0fe80f8baa64a3b719a960e42f460805137b28cac5677d684bbbc200085ff31adff011a7
|
data/README.md
CHANGED
@@ -13,10 +13,14 @@ gem 'ruboty-youtube'
|
|
13
13
|
## Usage
|
14
14
|
|
15
15
|
```
|
16
|
-
@ruboty yt top <keyword> - Search a movie from YouTube
|
17
|
-
@ruboty yt rand <keyword> - Search a movie randomly from YouTube
|
18
|
-
@ruboty yt pl <keyword>
|
19
|
-
@ruboty yt
|
16
|
+
@ruboty yt video top <keyword> - Search a movie from YouTube
|
17
|
+
@ruboty yt video rand <keyword> - Search a movie randomly from YouTube
|
18
|
+
@ruboty yt pl top <keyword> - Search a playlist from YouTube
|
19
|
+
@ruboty yt pl rand <keyword> - Search a playlist randomly from YouTube
|
20
|
+
|
21
|
+
# 'video' is optional.
|
22
|
+
@ruboty yt top <keyword> - Search a movie from YouTube
|
23
|
+
@ruboty yt rand <keyword> - Search a movie randomly from YouTube
|
20
24
|
```
|
21
25
|
|
22
26
|
## Development
|
@@ -1,18 +1,25 @@
|
|
1
1
|
module Ruboty
|
2
2
|
module Handlers
|
3
3
|
class Youtube < Base
|
4
|
-
on /yt (?<mode
|
4
|
+
on /yt ((?<target>(video|pl)) )?(?<mode>(top|rand)) (?<keyword>.+)/, name: 'yt', description: 'Search from YouTube'
|
5
5
|
|
6
6
|
def yt(message)
|
7
|
-
|
8
|
-
message
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
result =
|
8
|
+
if message[:target]
|
9
|
+
Ruboty::Youtube::Client.new(
|
10
|
+
message[:keyword],
|
11
|
+
message[:mode].to_sym,
|
12
|
+
message[:target].to_sym
|
13
|
+
).search
|
14
|
+
else
|
15
|
+
Ruboty::Youtube::Client.new(
|
16
|
+
message[:keyword],
|
17
|
+
message[:mode].to_sym,
|
18
|
+
:video
|
19
|
+
).search
|
20
|
+
end
|
13
21
|
|
14
|
-
|
15
|
-
Ruboty::Youtube::Client.new(query, mode).get
|
22
|
+
message.reply(result) if result
|
16
23
|
end
|
17
24
|
end
|
18
25
|
end
|
@@ -8,16 +8,17 @@ module Ruboty
|
|
8
8
|
class Client
|
9
9
|
YOUTUBE_URL = 'https://www.youtube.com'
|
10
10
|
|
11
|
-
def initialize(query, mode)
|
11
|
+
def initialize(query, mode, target)
|
12
12
|
@conn = Faraday.new(url: YOUTUBE_URL, ssl: { verify: false }) do |faraday|
|
13
13
|
faraday.request :url_encoded
|
14
14
|
faraday.adapter Faraday.default_adapter
|
15
15
|
end
|
16
16
|
@query = query
|
17
17
|
@mode = mode
|
18
|
+
@target = target
|
18
19
|
end
|
19
20
|
|
20
|
-
def
|
21
|
+
def search
|
21
22
|
response = @conn.get {|req|
|
22
23
|
req.url '/results', params
|
23
24
|
}.body
|
@@ -35,9 +36,9 @@ module Ruboty
|
|
35
36
|
end
|
36
37
|
|
37
38
|
case @mode
|
38
|
-
when :top
|
39
|
+
when :top
|
39
40
|
YOUTUBE_URL + result.first
|
40
|
-
when:rand
|
41
|
+
when:rand
|
41
42
|
YOUTUBE_URL + result.sample
|
42
43
|
end
|
43
44
|
end
|
@@ -48,12 +49,12 @@ module Ruboty
|
|
48
49
|
}
|
49
50
|
|
50
51
|
params =
|
51
|
-
case @
|
52
|
-
when :
|
52
|
+
case @target
|
53
|
+
when :video
|
53
54
|
{
|
54
55
|
filters: 'video'
|
55
56
|
}
|
56
|
-
when :pl
|
57
|
+
when :pl
|
57
58
|
{
|
58
59
|
filters: 'playlist'
|
59
60
|
}
|
data/ruboty-youtube.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_runtime_dependency 'ruboty'
|
21
21
|
spec.add_runtime_dependency 'faraday'
|
22
|
-
spec.add_runtime_dependency '
|
22
|
+
spec.add_runtime_dependency 'nokogiri'
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler', '~> 1.9'
|
25
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-youtube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaihar4
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: nokogiri
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|