ruboty-niconico 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/lib/ruboty/handlers/niconico.rb +21 -0
- data/lib/ruboty/niconico.rb +3 -0
- data/lib/ruboty/niconico/actions/niconico.rb +66 -0
- data/lib/ruboty/niconico/version.rb +5 -0
- data/ruboty-niconico.gemspec +24 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 427c39d264ec61f034ce726a6199a134fd877ff2
|
4
|
+
data.tar.gz: a62584413c99ab2fa5b4cc7c3a54082224a7c0f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b2e47248fafdf57f1a805809ae6302dcc8c36a31246a4023bfae932fd17ed3078c3b92899b417d404700de8585be824825aad7d4085fa9a29e01f6a58ca8597
|
7
|
+
data.tar.gz: 79fa6435b3aba02c31216e50ae30b9b7ac514ef994a8cd150d5c7b8dca818f86d3a9138b5e0de9a18c56308b263a9c6841149fd68a94b7fd3d4413d2e1eaedee
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Taga Yasunori
|
2
|
+
|
3
|
+
MIT License
|
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:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Ruboty::Niconico
|
2
|
+
|
3
|
+
Ruboty handler to search from NiconicoVideo.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ruboty-niconico'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ruboty-niconico
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```
|
24
|
+
@ruboty nico top <keyword> - Search a movie from NiconicoVideo.
|
25
|
+
@ruboty nico rand <keyword> - Search a movie randomly from NiconicoVideo.
|
26
|
+
```
|
27
|
+
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it ( https://github.com/[my-github-username]/ruboty-niconico/fork )
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "ruboty/niconico/actions/niconico"
|
2
|
+
|
3
|
+
module Ruboty
|
4
|
+
module Handlers
|
5
|
+
class Niconico < Base
|
6
|
+
on /nico (?<mode>.+?) (?<keyword>.+)/, name: 'niconico', description: 'Search from nicovideo'
|
7
|
+
|
8
|
+
def niconico(message)
|
9
|
+
if url = search(message[:keyword], message[:mode].to_sym)
|
10
|
+
message.reply(url)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def search(query, mode)
|
17
|
+
Ruboty::Niconico::Actions::Niconico.new(query, mode).post
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Niconico
|
3
|
+
module Actions
|
4
|
+
class Niconico < Ruboty::Actions::Base
|
5
|
+
NICOVIDEO_SEARCH_API_URL = "http://api.search.nicovideo.jp/api/snapshot/"
|
6
|
+
|
7
|
+
def initialize(query, mode)
|
8
|
+
@query = query
|
9
|
+
@mode = mode
|
10
|
+
end
|
11
|
+
|
12
|
+
def post
|
13
|
+
case @mode
|
14
|
+
when :top
|
15
|
+
video_url(response.first)
|
16
|
+
when :rand
|
17
|
+
video_url(response.sample)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def video_url(cmsid)
|
24
|
+
cmsid ? 'http://www.nicovideo.jp/watch/%s' % cmsid : nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def response
|
28
|
+
uri = URI.parse(api_url)
|
29
|
+
response = Net::HTTP.start(uri.host) do |http|
|
30
|
+
http.open_timeout = 5
|
31
|
+
http.read_timeout = 10
|
32
|
+
http.post(uri.path, params.to_json)
|
33
|
+
end
|
34
|
+
response.body.scan(/\{"_rowid":.+?,"cmsid":".+?"\}/).map do | value |
|
35
|
+
/\"cmsid\":\"(?<cmsid>.+)\"/ =~ value
|
36
|
+
cmsid
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def connection
|
41
|
+
Faraday.new do |connection|
|
42
|
+
connection.request :url_encoded
|
43
|
+
connection.adapter :net_http
|
44
|
+
connection.response :json
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def api_url
|
49
|
+
NICOVIDEO_SEARCH_API_URL
|
50
|
+
end
|
51
|
+
|
52
|
+
def params
|
53
|
+
{
|
54
|
+
query: @query,
|
55
|
+
service: ["video"],
|
56
|
+
search: ["title"],
|
57
|
+
join: ["cmsid"],
|
58
|
+
sort_by: "view_counter",
|
59
|
+
size: 100,
|
60
|
+
issuer: "ruboty-niconico"
|
61
|
+
}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruboty/niconico/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruboty-niconico"
|
8
|
+
spec.version = Ruboty::Niconico::VERSION
|
9
|
+
spec.authors = ["Taga Yasunori"]
|
10
|
+
spec.email = ["yasukun.taga@gmail.com"]
|
11
|
+
spec.summary = %q{ Ruboty handler to search from NiconicoVideo.}
|
12
|
+
spec.homepage = "https://github.com/yassun/ruboty-niconico"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency "ruboty"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-niconico
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Taga Yasunori
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruboty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- yasukun.taga@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/ruboty/handlers/niconico.rb
|
68
|
+
- lib/ruboty/niconico.rb
|
69
|
+
- lib/ruboty/niconico/actions/niconico.rb
|
70
|
+
- lib/ruboty/niconico/version.rb
|
71
|
+
- ruboty-niconico.gemspec
|
72
|
+
homepage: https://github.com/yassun/ruboty-niconico
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.2.2
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Ruboty handler to search from NiconicoVideo.
|
96
|
+
test_files: []
|