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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: decdcda64ea5b12b48f08e535d3762cceb01090e
4
- data.tar.gz: cf07f3b5e3bde8a16ffa75c151d9c3af0f5799d7
3
+ metadata.gz: 1aa78fe2e84056fbfd105a91c11c74f77545c0ba
4
+ data.tar.gz: 0fa67331fd1b867a40d91d1de05c894a335755d8
5
5
  SHA512:
6
- metadata.gz: 16df76022c53f682bc58f752300e35968f66d0a0824d1db9f37e551174fbf5683f51e3ac6f94af37ad9ea4b191a0880af9bdecd27f31e78f982f55b512b3feaf
7
- data.tar.gz: fa1f843c6faf9704bc676e86c709ce7d4452c3c310deaa2d8e13c9b9cca59f438fe7b530b0b4a17f340f79e4e8652af101c028277998a6576b85083e901abde8
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> - Search a playlist from YouTube
19
- @ruboty yt pls <keyword> - Search a playlist randomly from YouTube
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>.+?) (?<keyword>.+)/, name: 'yt', description: 'Search from YouTube'
4
+ on /yt ((?<target>(video|pl)) )?(?<mode>(top|rand)) (?<keyword>.+)/, name: 'yt', description: 'Search from YouTube'
5
5
 
6
6
  def yt(message)
7
- if url = search(message[:keyword], message[:mode].to_sym)
8
- message.reply(url)
9
- end
10
- end
11
-
12
- private
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
- def search(query, mode)
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 get
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, :pl
39
+ when :top
39
40
  YOUTUBE_URL + result.first
40
- when:rand, :pls
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 @mode
52
- when :top, :rand
52
+ case @target
53
+ when :video
53
54
  {
54
55
  filters: 'video'
55
56
  }
56
- when :pl, :pls
57
+ when :pl
57
58
  {
58
59
  filters: 'playlist'
59
60
  }
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Youtube
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -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 'mechanize'
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.1.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: mechanize
42
+ name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="