nico_search_snapshot 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/nico_search_snapshot/result.rb +32 -0
- data/lib/nico_search_snapshot/version.rb +3 -0
- data/lib/nico_search_snapshot.rb +106 -0
- data/nico_search_snapshot.gemspec +25 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ad31e56fd50f50c54150a762ebf13370fa469efc
|
4
|
+
data.tar.gz: a561d8fa409cf43a1de1266f49e65924159e29c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9ca2e5e5c663bb4f307e0e41e3097df493b230851786e19d23183c242c020205636644f88dd48770bac1831e350f21d95025537585483587a2acfc2aadecb072
|
7
|
+
data.tar.gz: 2a4dfca00971095188a0df195c8ff4b546cacc655b3624d9c32261d6bb6c71d2d91c37c65841cb0f10aaccda7c0fdefa2ed185e7d12244d42f2758c1c1b47cc9
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 TODO: Write your name
|
4
|
+
|
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:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
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
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# NicoSearchSnapshot
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
Utility for nicovideo snapshot search at <http://search.nicovideo.jp/docs/api/snapshot.html>.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'nico_search_snapshot'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install nico_search_snapshot
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'nico_search_snapshot'
|
25
|
+
nico = NicoSearchSnapshot.new('Your Application Name')
|
26
|
+
results = nico.search('query string')
|
27
|
+
results.each do |r|
|
28
|
+
puts r.cmsid
|
29
|
+
puts r.title
|
30
|
+
puts r.desctiption
|
31
|
+
# ...
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nico_search_snapshot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
44
|
+
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
49
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "temp"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
class NicoSearchSnapshot
|
2
|
+
class Result
|
3
|
+
@@names = [:cmsid, :title, :description, :tags, :start_time, :thumbnail_url,
|
4
|
+
:view_counter, :comment_counter, :mylist_counter, :last_res_body,
|
5
|
+
:length_seconds]
|
6
|
+
|
7
|
+
attr_accessor *@@names
|
8
|
+
|
9
|
+
def initialize(hash = nil)
|
10
|
+
hash ||= {}
|
11
|
+
hash.each { |k,v|
|
12
|
+
send("#{k}=", v) if respond_to? "#{k}="
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_hash
|
17
|
+
Hash[*@@names.map{|v| [v, send(v)] }.flatten]
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_tsv
|
21
|
+
to_hash.values.join("\t")
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
to_hash.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
to_hash.inspect
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'httpclient'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class NicoSearchSnapshot
|
5
|
+
|
6
|
+
# NicoSearchSnapshot.new('Your Application Name')
|
7
|
+
def initialize(issuer = nil)
|
8
|
+
@issuer = issuer
|
9
|
+
end
|
10
|
+
|
11
|
+
# Search video
|
12
|
+
#
|
13
|
+
# Simply search.
|
14
|
+
# nico = NicoSearchSnapshot.new
|
15
|
+
# results = nico.search('query')
|
16
|
+
#
|
17
|
+
# Size of results default is 10, max is 100.
|
18
|
+
# results = nico.search('query', size: 100) # Top 100 items
|
19
|
+
# results = nico.search('query', size: 100, from 200) # 201 ~ 300
|
20
|
+
#
|
21
|
+
# <tt>all</tt> option is original of this library. You can get all of the
|
22
|
+
# results at once by some request for server.
|
23
|
+
# results = nico.search('query', all: true)
|
24
|
+
#
|
25
|
+
# Keyword or tag.
|
26
|
+
# # by keyword(default)
|
27
|
+
# nico.search('query', search: [:title, :description, :tags])
|
28
|
+
# # title only
|
29
|
+
# nico.search('query', search: [:title])
|
30
|
+
# # by tag(full match)
|
31
|
+
# nico.search('query', search: [:tag_exact])
|
32
|
+
#
|
33
|
+
# Result fields. Fields name is <tt>cmsid</tt>, <tt>title</tt>,
|
34
|
+
# <tt>description</tt>, <tt>tags</tt>, <tt>start_time</tt>,
|
35
|
+
# <tt>thumbnail_url</tt>, <tt>view_counter</tt>, <tt>comment_counter</tt>,
|
36
|
+
# <tt>mylist_counter</tt>, <tt>last_res_body</tt> and <tt>length_seconds</tt>.
|
37
|
+
# Default is all fields.
|
38
|
+
# nico.search('query', join: [:cmsid, :title, :description])
|
39
|
+
#
|
40
|
+
# Filter
|
41
|
+
# # just 5 minutes
|
42
|
+
# nico.search('query', filters: [{
|
43
|
+
# type: :equal, field: :length_seconds, value: 300}])
|
44
|
+
# # Published at Jan 2015 and view count is greater than 10000
|
45
|
+
# results = nico.search('hello', filters: [
|
46
|
+
# {type: :range, field: :start_time, from: '2015-01-01 00:00:00',
|
47
|
+
# to: '2015-02-01 00:00:00', include_upper: false},
|
48
|
+
# {type: :range, field: :view_counter, from: 10000, include_lower: false}])
|
49
|
+
#
|
50
|
+
# Sort by field. Fields name is <tt>last_comment_time</tt>,
|
51
|
+
# <tt>view_counter</tt>, <tt>start_time</tt>, <tt>mylist_counter</tt>,
|
52
|
+
# <tt>comment_counter</tt> and <tt>length_seconds</tt>.
|
53
|
+
#
|
54
|
+
# Order: <tt>asc</tt> or <tt>desc</tt>. Default is <tt>desc</tt>.
|
55
|
+
# nico.search('query', sort_by: :view_counter, order: asc)
|
56
|
+
def search(query, **options)
|
57
|
+
options = self.class.default_options.merge(options)
|
58
|
+
options[:query] = query
|
59
|
+
options[:issuer] = @issuer if @issuer
|
60
|
+
all = options.delete(:all)
|
61
|
+
options[:size] = 100 if all
|
62
|
+
|
63
|
+
resp = http_client.post('http://api.search.nicovideo.jp/api/snapshot/',
|
64
|
+
options.to_json)
|
65
|
+
|
66
|
+
results = resp.body.split("\n").map{|l| JSON.parse(l)}
|
67
|
+
total = results.find{|c| c['type'] == 'stats'}['values'].first['total'].to_i
|
68
|
+
return [] if total == 0
|
69
|
+
|
70
|
+
hits = results.find{|c| c['type'] == 'hits' }['values'].map{|r| Result.new(r) }
|
71
|
+
|
72
|
+
if all && total > options[:from] + options[:size] then
|
73
|
+
hits + search(query, options.merge({
|
74
|
+
from: options[:from] + options[:size],
|
75
|
+
size: options[:size],
|
76
|
+
all: all}))
|
77
|
+
else
|
78
|
+
hits
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def self.default_options
|
85
|
+
@default_options ||= {
|
86
|
+
service: ["video"],
|
87
|
+
search: ["title", "description", "tags"],
|
88
|
+
join: ["cmsid", "title", "description", "tags", "start_time",
|
89
|
+
"thumbnail_url", "view_counter", "comment_counter",
|
90
|
+
"mylist_counter", "last_res_body", "length_seconds"],
|
91
|
+
filters: [],
|
92
|
+
sort_by: "last_comment_time",
|
93
|
+
order: "desc",
|
94
|
+
from: 0,
|
95
|
+
size: 10
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
def http_client
|
100
|
+
@http_client ||= HTTPClient.new
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
require 'nico_search_snapshot/result'
|
106
|
+
require 'nico_search_snapshot/version'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nico_search_snapshot/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nico_search_snapshot"
|
8
|
+
spec.version = NicoSearchSnapshot::VERSION
|
9
|
+
spec.authors = ["ishidamakot"]
|
10
|
+
spec.email = []
|
11
|
+
|
12
|
+
spec.summary = %q{nicovideo snapshot search utility.}
|
13
|
+
spec.description = %q{nicovideo snapshot search utility.}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "httpclient", '>= 2.6.0'
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10.a"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nico_search_snapshot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ishidamakot
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httpclient
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.6.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.6.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.10.a
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.10.a
|
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: nicovideo snapshot search utility.
|
56
|
+
email: []
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- ".gitignore"
|
62
|
+
- CODE_OF_CONDUCT.md
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/console
|
68
|
+
- bin/setup
|
69
|
+
- lib/nico_search_snapshot.rb
|
70
|
+
- lib/nico_search_snapshot/result.rb
|
71
|
+
- lib/nico_search_snapshot/version.rb
|
72
|
+
- nico_search_snapshot.gemspec
|
73
|
+
homepage: ''
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.2.2
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: nicovideo snapshot search utility.
|
97
|
+
test_files: []
|
98
|
+
has_rdoc:
|