niconize 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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/niconize/reserve.rb +46 -0
- data/lib/niconize/version.rb +3 -0
- data/lib/niconize.rb +35 -0
- data/niconize.gemspec +24 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c30bc55b82d019579de6222b0cfe8dd765dc4846
|
4
|
+
data.tar.gz: 7222b3d524336a5d48a8a0b38f2f35175d366e71
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f64d7380b8c570f23b04ad6dcbbb3dc96e5ca74885a7ed9353cf666bc95530e481f81d8f1cec1b03283fb2707948cc92bca7cdb4e6fd1d3e50d47dab0ea39c4
|
7
|
+
data.tar.gz: 829f2bbf40444310121276d2f8cb6b457c8db5caf215830cad5894efae1357b5ba0fe76a415ae97f6ded340bcdd10416ee421c3546f12a5cabaac83e1990a3a7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Tomohiro Suwa(tsuwatch)
|
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,29 @@
|
|
1
|
+
# Niconize
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'niconize'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install niconize
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class Niconize
|
2
|
+
def reserve(lv)
|
3
|
+
login unless @logined
|
4
|
+
query = get_query(lv)
|
5
|
+
q = query.scan(/'(.*?)'/)
|
6
|
+
ulck = get_ulck(q[0][0], q[1][0])
|
7
|
+
response = do_reservation(lv, ulck)
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_query(lv)
|
11
|
+
login unless @logined
|
12
|
+
response = @agent.get("http://live.nicovideo.jp/watch/#{lv}")
|
13
|
+
|
14
|
+
response.search('a.watching_reservation')[0]['onclick']
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_ulck(lv, token)
|
18
|
+
login unless @logined
|
19
|
+
lv = lv.sub(/^lv/, '')
|
20
|
+
|
21
|
+
query = {
|
22
|
+
'mode' => 'watch_num',
|
23
|
+
'vid' => lv,
|
24
|
+
'token' => token
|
25
|
+
}
|
26
|
+
response = @agent.get(URL[:reserve], query)
|
27
|
+
raise UlckParseError, 'It is the limit of the number of your reservation' unless response.at('div.reserve')
|
28
|
+
response.at('div.reserve').inner_html.scan(/ulck_[0-9]+/)[0]
|
29
|
+
end
|
30
|
+
|
31
|
+
def do_reservation(lv, ulck)
|
32
|
+
login unless @logined
|
33
|
+
lv = lv.sub(/^lv/, '')
|
34
|
+
|
35
|
+
data = {
|
36
|
+
'mode' => 'regist',
|
37
|
+
'vid' => lv,
|
38
|
+
'token' => ulck,
|
39
|
+
'_' => ''
|
40
|
+
}
|
41
|
+
|
42
|
+
response = @agent.post(URL[:reserve], data)
|
43
|
+
end
|
44
|
+
|
45
|
+
class UlckParseError < StandardError; end
|
46
|
+
end
|
data/lib/niconize.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "niconize/version"
|
2
|
+
require "mechanize"
|
3
|
+
|
4
|
+
class Niconize
|
5
|
+
URL = {
|
6
|
+
login: 'https://secure.nicovideo.jp/secure/login?site=niconico',
|
7
|
+
live_watch: 'http://live.nicovideo.jp/watch/',
|
8
|
+
reserve: 'http://live.nicovideo.jp/api/watchingreservation'
|
9
|
+
}
|
10
|
+
|
11
|
+
attr_reader :agent, :logined
|
12
|
+
|
13
|
+
def initialize(mail, password)
|
14
|
+
@mail = mail
|
15
|
+
@password = password
|
16
|
+
|
17
|
+
@logined = false
|
18
|
+
|
19
|
+
@agent = Mechanize.new
|
20
|
+
@agent.ssl_version = 'SSLv3'
|
21
|
+
@agent.request_headers = {
|
22
|
+
'accept-language' => 'ja, ja-JP'
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def login
|
27
|
+
page = @agent.post(URL[:login], 'mail' => @mail, 'password' => @password)
|
28
|
+
|
29
|
+
raise LoginError, 'Failed to login (x-niconico-authflag is 0)' if page.header['x-niconico-authflag'] == '0'
|
30
|
+
@logined = true
|
31
|
+
end
|
32
|
+
class LoginError < StandardError; end
|
33
|
+
end
|
34
|
+
|
35
|
+
require_relative 'niconize/reserve'
|
data/niconize.gemspec
ADDED
@@ -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 'niconize/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "niconize"
|
8
|
+
spec.version = Niconize::VERSION
|
9
|
+
spec.authors = ["Tomohiro Suwa(tsuwatch)"]
|
10
|
+
spec.email = ["neoen.gsn@gmail.com"]
|
11
|
+
spec.description = %q{wrapper of mechanize for nicovideo}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "mechanize"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: niconize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomohiro Suwa(tsuwatch)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mechanize
|
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.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: wrapper of mechanize for nicovideo
|
56
|
+
email:
|
57
|
+
- neoen.gsn@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/niconize.rb
|
68
|
+
- lib/niconize/reserve.rb
|
69
|
+
- lib/niconize/version.rb
|
70
|
+
- niconize.gemspec
|
71
|
+
homepage: ''
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.0.3
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: wrapper of mechanize for nicovideo
|
95
|
+
test_files: []
|