ruboty-youtube 0.0.3 → 0.1.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: 936be7ef0fc77c3364df0a6903bcfd1d7620ea93
4
- data.tar.gz: 23f464843114b392339e8a58cd33d47768843e8d
3
+ metadata.gz: decdcda64ea5b12b48f08e535d3762cceb01090e
4
+ data.tar.gz: cf07f3b5e3bde8a16ffa75c151d9c3af0f5799d7
5
5
  SHA512:
6
- metadata.gz: a0bd2a5ce8c9f7836842630c35f48f77202eb927626f7c45a90aa88258746a77ffa74a25e8931022bb1d1b6d5279e32741d79a816337e40474c3a774e00d0624
7
- data.tar.gz: 01bb40fd01dadfa942d48db6b51ac10719a6bfd929e0c59bb094bf13be8b10cb81cd68dd53f4a59e1291e06f5eb01bcff5c535177414e4e87045992431a0e84d
6
+ metadata.gz: 16df76022c53f682bc58f752300e35968f66d0a0824d1db9f37e551174fbf5683f51e3ac6f94af37ad9ea4b191a0880af9bdecd27f31e78f982f55b512b3feaf
7
+ data.tar.gz: fa1f843c6faf9704bc676e86c709ce7d4452c3c310deaa2d8e13c9b9cca59f438fe7b530b0b4a17f340f79e4e8652af101c028277998a6576b85083e901abde8
data/.gitignore CHANGED
@@ -7,8 +7,3 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
@@ -1,22 +1,21 @@
1
- Copyright (c) 2014 kaihar4
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2015 kaihar4
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
12
11
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
15
14
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -4,7 +4,7 @@ Ruboty handler to search from YouTube.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Add this line to your ruboty's Gemfile:
8
8
 
9
9
  ```ruby
10
10
  gem 'ruboty-youtube'
@@ -18,3 +18,17 @@ gem 'ruboty-youtube'
18
18
  @ruboty yt pl <keyword> - Search a playlist from YouTube
19
19
  @ruboty yt pls <keyword> - Search a playlist randomly from YouTube
20
20
  ```
21
+
22
+ ## Development
23
+
24
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
25
+
26
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it ( https://github.com/kaihar4/ruboty-youtube/fork )
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ruboty/youtube'
5
+
6
+ require 'irb'
7
+ IRB.start
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install --path vendor/bundle
@@ -1,17 +1,15 @@
1
1
  require 'json'
2
2
 
3
3
  require 'faraday'
4
- require 'mechanize'
4
+ require 'nokogiri'
5
5
 
6
6
  module Ruboty
7
7
  module Youtube
8
8
  class Client
9
9
  YOUTUBE_URL = 'https://www.youtube.com'
10
- YOUTUBE_API_URL = 'http://gdata.youtube.com'
11
10
 
12
11
  def initialize(query, mode)
13
- @agent = Mechanize.new
14
- @conn = Faraday.new(url: YOUTUBE_API_URL) do |faraday|
12
+ @conn = Faraday.new(url: YOUTUBE_URL, ssl: { verify: false }) do |faraday|
15
13
  faraday.request :url_encoded
16
14
  faraday.adapter Faraday.default_adapter
17
15
  end
@@ -20,9 +18,9 @@ module Ruboty
20
18
  end
21
19
 
22
20
  def get
23
- response = @conn.get do |req|
24
- req.url api_path, params
25
- end.body
21
+ response = @conn.get {|req|
22
+ req.url '/results', params
23
+ }.body
26
24
  parse_response(response)
27
25
  rescue
28
26
  nil
@@ -31,56 +29,33 @@ module Ruboty
31
29
  private
32
30
 
33
31
  def parse_response(response)
34
- videos = JSON.parse(response)['feed']['entry']
35
-
36
- case @mode
37
- when :top, :rand
38
- # when @mode is :top -> videos.length is 1
39
- videos.sample['link'][0]['href']
40
- when :pl, :pls
41
- # when @mode is :pl -> videos.length is 1
42
- pl_url = videos.sample['link'][1]['href']
43
- page = @agent.get(pl_url)
44
- YOUTUBE_URL + page.link_with(href: /\/watch/).href
32
+ video_links = Nokogiri::HTML(response).css('.yt-lockup-thumbnail a')
33
+ result = video_links.each_with_object([]) do |video_link, array|
34
+ array << video_link.attribute('href').content
45
35
  end
46
- end
47
36
 
48
- def api_path
49
37
  case @mode
50
- when :top, :rand
51
- '/feeds/api/videos'
52
- when :pl, :pls
53
- '/feeds/api/playlists/snippets'
38
+ when :top, :pl
39
+ YOUTUBE_URL + result.first
40
+ when:rand, :pls
41
+ YOUTUBE_URL + result.sample
54
42
  end
55
43
  end
56
44
 
57
45
  def params
58
46
  default_params = {
59
- alt: 'json',
60
- q: @query
47
+ search_query: @query
61
48
  }
62
49
 
63
50
  params =
64
51
  case @mode
65
- when :top
66
- {
67
- orderBy: "relevance",
68
- 'max-results' => 1
69
- }
70
- when :rand
71
- {
72
- orderBy: "relevance",
73
- 'max-results' => 15
74
- }
75
- when :pl
52
+ when :top, :rand
76
53
  {
77
- v: 2,
78
- 'max-results' => 1
54
+ filters: 'video'
79
55
  }
80
- when :pls
56
+ when :pl, :pls
81
57
  {
82
- v: 2,
83
- 'max-results' => 15
58
+ filters: 'playlist'
84
59
  }
85
60
  end
86
61
 
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Youtube
3
- VERSION = '0.0.3'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
@@ -1,4 +1,5 @@
1
- $LOAD_PATH << File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
2
3
  require 'ruboty/youtube/version'
3
4
 
4
5
  Gem::Specification.new do |spec|
@@ -6,20 +7,20 @@ Gem::Specification.new do |spec|
6
7
  spec.version = Ruboty::Youtube::VERSION
7
8
  spec.authors = ['kaihar4']
8
9
  spec.email = ['kaihar4@gmail.com']
9
- spec.summary = 'Ruboty handler to search from YouTube.'
10
+ spec.summary = 'Ruboty handler to search from YouTube'
10
11
  spec.description = spec.summary
11
12
  spec.homepage = 'https://github.com/kaihar4/ruboty-youtube'
12
13
  spec.license = 'MIT'
13
14
 
14
- spec.files = `git ls-files -z`.split("\x0")
15
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = 'exe'
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
18
  spec.require_paths = ['lib']
18
19
 
19
- spec.add_dependency 'ruboty'
20
- spec.add_dependency 'faraday'
21
- spec.add_dependency 'mechanize'
20
+ spec.add_runtime_dependency 'ruboty'
21
+ spec.add_runtime_dependency 'faraday'
22
+ spec.add_runtime_dependency 'mechanize'
22
23
 
23
- spec.add_development_dependency 'bundler', '~> 1.7'
24
+ spec.add_development_dependency 'bundler', '~> 1.9'
24
25
  spec.add_development_dependency 'rake', '~> 10.0'
25
26
  end
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.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaihar4
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2014-11-15 00:00:00.000000000 Z
11
+ date: 2015-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.7'
61
+ version: '1.9'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.7'
68
+ version: '1.9'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '10.0'
83
- description: Ruboty handler to search from YouTube.
83
+ description: Ruboty handler to search from YouTube
84
84
  email:
85
85
  - kaihar4@gmail.com
86
86
  executables: []
@@ -92,6 +92,8 @@ files:
92
92
  - LICENSE.txt
93
93
  - README.md
94
94
  - Rakefile
95
+ - bin/console
96
+ - bin/setup
95
97
  - lib/ruboty/handlers/youtube.rb
96
98
  - lib/ruboty/youtube.rb
97
99
  - lib/ruboty/youtube/client.rb
@@ -117,8 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
119
  version: '0'
118
120
  requirements: []
119
121
  rubyforge_project:
120
- rubygems_version: 2.2.2
122
+ rubygems_version: 2.4.5
121
123
  signing_key:
122
124
  specification_version: 4
123
- summary: Ruboty handler to search from YouTube.
125
+ summary: Ruboty handler to search from YouTube
124
126
  test_files: []