niconize 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/niconize/live.rb +7 -49
- data/lib/niconize/program.rb +59 -0
- data/lib/niconize/version.rb +1 -1
- data/lib/niconize.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e2fd449ecb1caea083c160e8d493ea5244f7837
|
4
|
+
data.tar.gz: 72919a75160e374013f655af96058bbe1f33a650
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43ba97c373cbf3f91be3d8c1bd6b612bad27e974028a04119d03f90c3cba207310c5f56952c436572fb6e7127bb6b7f7562c88c9eae3b24c438dde7f083cf53e
|
7
|
+
data.tar.gz: c6bfa1f777404b2dce86e0de2a54c5796783ee05d21be04447269a4200948689118b3be20bb3d430bf01fdaec87659f47d1a7f2cf4c3623220b1e76a7dc3f510
|
data/lib/niconize/live.rb
CHANGED
@@ -1,63 +1,21 @@
|
|
1
|
+
require_relative './program'
|
2
|
+
|
1
3
|
class Niconize
|
2
|
-
def live
|
4
|
+
def live
|
3
5
|
login unless @logined
|
4
|
-
Live.new(self
|
6
|
+
@live ||= Live.new(self)
|
5
7
|
end
|
6
8
|
|
7
9
|
class Live
|
8
|
-
|
9
|
-
|
10
|
-
def initialize(parent, lv)
|
10
|
+
def initialize(parent)
|
11
11
|
@parent = parent
|
12
12
|
@agent = parent.agent
|
13
|
-
@lv = lv
|
14
|
-
end
|
15
|
-
|
16
|
-
def reserve
|
17
|
-
raise TimeshiftError, 'This nicolive is already reserved' if reserved?
|
18
|
-
lv_num = lv.sub(/^lv/, '')
|
19
|
-
|
20
|
-
data = {
|
21
|
-
'mode' => 'regist',
|
22
|
-
'vid' => lv_num,
|
23
|
-
'token' => ulck,
|
24
|
-
'_' => ''
|
25
|
-
}
|
26
|
-
|
27
|
-
@agent.post(URL[:reserve], data)
|
28
13
|
end
|
29
14
|
|
30
|
-
|
31
|
-
|
32
|
-
def reserved?
|
33
|
-
lv_num = lv.sub(/^lv/, '')
|
15
|
+
def reserved_programs
|
34
16
|
query = { 'mode' => 'list' }
|
35
17
|
response = @agent.get(URL[:reserve], query)
|
36
|
-
|
37
|
-
!!vid_list.include?(lv_num)
|
38
|
-
end
|
39
|
-
|
40
|
-
def live_page
|
41
|
-
@live_page ||= @agent.get("http://live.nicovideo.jp/watch/#{lv}")
|
42
|
-
end
|
43
|
-
|
44
|
-
def token
|
45
|
-
live_page.search('a.watching_reservation')[0]['onclick'].scan(/'(.*?)'/)[1][0]
|
46
|
-
end
|
47
|
-
|
48
|
-
def ulck
|
49
|
-
lv_num = lv.sub(/^lv/, '')
|
50
|
-
|
51
|
-
query = {
|
52
|
-
'mode' => 'watch_num',
|
53
|
-
'vid' => lv_num,
|
54
|
-
'token' => token
|
55
|
-
}
|
56
|
-
response = @agent.get(URL[:reserve], query)
|
57
|
-
raise TimeshiftError, 'It is the limit of the number of your reservation' unless response.at('div.reserve')
|
58
|
-
response.at('div.reserve').inner_html.scan(/ulck_[0-9]+/)[0]
|
18
|
+
response.search('timeshift_reserved_list').children.map { |vid_element| Program.new(@parent, 'lv' + vid_element.inner_text) }
|
59
19
|
end
|
60
|
-
|
61
|
-
class TimeshiftError < StandardError; end
|
62
20
|
end
|
63
21
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative './live'
|
2
|
+
|
3
|
+
class Niconize
|
4
|
+
def program(lv)
|
5
|
+
login unless @logined
|
6
|
+
Program.new(self, lv)
|
7
|
+
end
|
8
|
+
|
9
|
+
class Program
|
10
|
+
attr_reader :lv, :vid
|
11
|
+
|
12
|
+
def initialize(parent, lv)
|
13
|
+
@parent = parent
|
14
|
+
@agent = parent.agent
|
15
|
+
@lv = lv
|
16
|
+
@vid = lv.sub(/^lv/, '')
|
17
|
+
end
|
18
|
+
|
19
|
+
def reserve
|
20
|
+
raise TimeshiftError, 'This nicolive is already reserved' if reserved?
|
21
|
+
|
22
|
+
data = {
|
23
|
+
'mode' => 'regist',
|
24
|
+
'vid' => vid,
|
25
|
+
'token' => ulck,
|
26
|
+
'_' => ''
|
27
|
+
}
|
28
|
+
|
29
|
+
@agent.post(URL[:reserve], data)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def reserved?
|
35
|
+
!!@parent.live.reserved_programs.map { |program| program.vid }.include?(vid)
|
36
|
+
end
|
37
|
+
|
38
|
+
def live_page
|
39
|
+
@live_page ||= @agent.get("http://live.nicovideo.jp/watch/#{lv}")
|
40
|
+
end
|
41
|
+
|
42
|
+
def token
|
43
|
+
live_page.search('a.watching_reservation')[0]['onclick'].scan(/'(.*?)'/)[1][0]
|
44
|
+
end
|
45
|
+
|
46
|
+
def ulck
|
47
|
+
query = {
|
48
|
+
'mode' => 'watch_num',
|
49
|
+
'vid' => vid,
|
50
|
+
'token' => token
|
51
|
+
}
|
52
|
+
response = @agent.get(URL[:reserve], query)
|
53
|
+
raise TimeshiftError, 'It is the limit of the number of your reservation' unless response.at('div.reserve')
|
54
|
+
response.at('div.reserve').inner_html.scan(/ulck_[0-9]+/)[0]
|
55
|
+
end
|
56
|
+
|
57
|
+
class TimeshiftError < StandardError; end
|
58
|
+
end
|
59
|
+
end
|
data/lib/niconize/version.rb
CHANGED
data/lib/niconize.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomohiro Suwa(tsuwatch)
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- Rakefile
|
67
67
|
- lib/niconize.rb
|
68
68
|
- lib/niconize/live.rb
|
69
|
+
- lib/niconize/program.rb
|
69
70
|
- lib/niconize/version.rb
|
70
71
|
- niconize.gemspec
|
71
72
|
homepage: https://github.com/tsuwatch/niconize
|