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 +4 -4
- data/.gitignore +0 -5
- data/LICENSE.txt +17 -18
- data/README.md +15 -1
- data/bin/console +7 -0
- data/bin/setup +5 -0
- data/lib/ruboty/youtube/client.rb +17 -42
- data/lib/ruboty/youtube/version.rb +1 -1
- data/ruboty-youtube.gemspec +10 -9
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: decdcda64ea5b12b48f08e535d3762cceb01090e
|
4
|
+
data.tar.gz: cf07f3b5e3bde8a16ffa75c151d9c3af0f5799d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16df76022c53f682bc58f752300e35968f66d0a0824d1db9f37e551174fbf5683f51e3ac6f94af37ad9ea4b191a0880af9bdecd27f31e78f982f55b512b3feaf
|
7
|
+
data.tar.gz: fa1f843c6faf9704bc676e86c709ce7d4452c3c310deaa2d8e13c9b9cca59f438fe7b530b0b4a17f340f79e4e8652af101c028277998a6576b85083e901abde8
|
data/.gitignore
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
3
|
+
Copyright (c) 2015 kaihar4
|
4
4
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
OF
|
22
|
-
|
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
|
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
|
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -1,17 +1,15 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
3
|
require 'faraday'
|
4
|
-
require '
|
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
|
-
@
|
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
|
24
|
-
req.url
|
25
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
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, :
|
51
|
-
|
52
|
-
when
|
53
|
-
|
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
|
-
|
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
|
-
|
78
|
-
'max-results' => 1
|
54
|
+
filters: 'video'
|
79
55
|
}
|
80
|
-
when :pls
|
56
|
+
when :pl, :pls
|
81
57
|
{
|
82
|
-
|
83
|
-
'max-results' => 15
|
58
|
+
filters: 'playlist'
|
84
59
|
}
|
85
60
|
end
|
86
61
|
|
data/ruboty-youtube.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
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.
|
16
|
-
spec.
|
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.
|
20
|
-
spec.
|
21
|
-
spec.
|
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.
|
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
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaihar4
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
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.
|
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.
|
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.
|
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: []
|