niconize 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/niconize/client.rb +44 -0
- data/lib/niconize/program.rb +9 -16
- data/lib/niconize/version.rb +2 -2
- data/lib/niconize.rb +3 -34
- metadata +3 -3
- data/lib/niconize/live.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2dd2227fcb3c2d07a558b2da07dc471c1793477e
|
4
|
+
data.tar.gz: 44f51cee9c2debfb64f305196943290aaed88cfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c00fbfce37a52e7c2f5dc0384e34c4fa8a7ad46de3de5a90a304bc32527ecf82789f500abfa0c15a10bbe656b2e20fe11ce229a2d7d3ce2924a918783c9ff72
|
7
|
+
data.tar.gz: dfe0b71dcb6b3a605f529e1c101f87278dd937ff70bfb7b7861062e1a157c37ec6731bd0b5cdd1f16cee3e382e37f498573c7d9c5584cb9c1e289a472d7336ba
|
data/README.md
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Niconize
|
2
|
+
class Client
|
3
|
+
class LoginError < StandardError; end
|
4
|
+
|
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
|
+
|
33
|
+
def program(lv)
|
34
|
+
login unless logined
|
35
|
+
Niconize::Program.new(self, lv)
|
36
|
+
end
|
37
|
+
|
38
|
+
def reserved_programs
|
39
|
+
query = { 'mode' => 'list' }
|
40
|
+
response = agent.get(URL[:reserve], query)
|
41
|
+
response.search('timeshift_reserved_list').children.map { |vid_element| Niconize::Program.new(self, 'lv' + vid_element.inner_text) }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/niconize/program.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class Niconize
|
4
|
-
def program(lv)
|
5
|
-
login unless @logined
|
6
|
-
Program.new(self, lv)
|
7
|
-
end
|
8
|
-
|
1
|
+
module Niconize
|
9
2
|
class Program
|
3
|
+
class TimeshiftError < StandardError; end
|
4
|
+
|
10
5
|
attr_reader :lv, :vid
|
11
6
|
|
12
|
-
def initialize(
|
13
|
-
@
|
14
|
-
@agent =
|
7
|
+
def initialize(client, lv)
|
8
|
+
@client = client
|
9
|
+
@agent = client.agent
|
15
10
|
@lv = lv
|
16
11
|
@vid = lv.sub(/^lv/, '')
|
17
12
|
end
|
@@ -26,13 +21,13 @@ class Niconize
|
|
26
21
|
'_' => ''
|
27
22
|
}
|
28
23
|
|
29
|
-
@agent.post(URL[:reserve], data)
|
24
|
+
@agent.post(Niconize::Client::URL[:reserve], data)
|
30
25
|
end
|
31
26
|
|
32
27
|
private
|
33
28
|
|
34
29
|
def reserved?
|
35
|
-
!!@
|
30
|
+
!!@client.reserved_programs.map { |program| program.vid }.include?(vid)
|
36
31
|
end
|
37
32
|
|
38
33
|
def live_page
|
@@ -49,11 +44,9 @@ class Niconize
|
|
49
44
|
'vid' => vid,
|
50
45
|
'token' => token
|
51
46
|
}
|
52
|
-
response = @agent.get(URL[:reserve], query)
|
47
|
+
response = @agent.get(Niconize::Client::URL[:reserve], query)
|
53
48
|
raise TimeshiftError, 'It is the limit of the number of your reservation' unless response.at('div.reserve')
|
54
49
|
response.at('div.reserve').inner_html.scan(/ulck_[0-9]+/)[0]
|
55
50
|
end
|
56
|
-
|
57
|
-
class TimeshiftError < StandardError; end
|
58
51
|
end
|
59
52
|
end
|
data/lib/niconize/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
module Niconize
|
2
|
+
VERSION = "0.0.7"
|
3
3
|
end
|
data/lib/niconize.rb
CHANGED
@@ -1,36 +1,5 @@
|
|
1
|
-
require "niconize/version"
|
2
1
|
require "mechanize"
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
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/program'
|
36
|
-
require_relative 'niconize/live'
|
3
|
+
require "niconize/client"
|
4
|
+
require "niconize/program"
|
5
|
+
require "niconize/version"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: niconize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomohiro Suwa(tsuwatch)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|
@@ -65,7 +65,7 @@ files:
|
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
67
|
- lib/niconize.rb
|
68
|
-
- lib/niconize/
|
68
|
+
- lib/niconize/client.rb
|
69
69
|
- lib/niconize/program.rb
|
70
70
|
- lib/niconize/version.rb
|
71
71
|
- niconize.gemspec
|
data/lib/niconize/live.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require_relative './program'
|
2
|
-
|
3
|
-
class Niconize
|
4
|
-
def live
|
5
|
-
login unless @logined
|
6
|
-
@live ||= Live.new(self)
|
7
|
-
end
|
8
|
-
|
9
|
-
class Live
|
10
|
-
def initialize(parent)
|
11
|
-
@parent = parent
|
12
|
-
@agent = parent.agent
|
13
|
-
end
|
14
|
-
|
15
|
-
def reserved_programs
|
16
|
-
query = { 'mode' => 'list' }
|
17
|
-
response = @agent.get(URL[:reserve], query)
|
18
|
-
response.search('timeshift_reserved_list').children.map { |vid_element| Program.new(@parent, 'lv' + vid_element.inner_text) }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|