nicoscraper 0.2.9 → 0.2.10

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.
@@ -3,30 +3,30 @@ module Nicos
3
3
  class Config
4
4
  @@waitConfigDefault =
5
5
  @@waitConfig = {
6
- 'seqAccLimit' => 10, # 連続してリクエストする回数
7
- 'afterSeq' => 10, # 連続リクエスト後のウェイト(以下全て単位は秒)
8
- 'each' => 1, # 連続リクエスト時の、1リクエスト毎のウェイト
6
+ :seqAccLimit => 10, # 連続してリクエストする回数
7
+ :afterSeq => 10, # 連続リクエスト後のウェイト(以下全て単位は秒)
8
+ :each => 1, # 連続リクエスト時の、1リクエスト毎のウェイト
9
9
 
10
- 'increment' => 1, # アクセス拒絶時の、次回以降の1リクエスト毎のウェイトの増加量
10
+ :increment => 1, # アクセス拒絶時の、次回以降の1リクエスト毎のウェイトの増加量
11
11
 
12
- 'deniedSeqReq'=> { # 連続アクセス拒絶時
13
- 'retryLimit' => 3, # 再試行回数の上限
14
- 'wait' => 120 # 再試行までのウェイト
12
+ :deniedSeqReq=> { # 連続アクセス拒絶時
13
+ :retryLimit => 3, # 再試行回数の上限
14
+ :wait => 120 # 再試行までのウェイト
15
15
  },
16
16
 
17
- 'serverIsBusy'=> { # サーバ混雑時
18
- 'retryLimit' => 3,
19
- 'wait' => 120
17
+ :serverIsBusy=> { # サーバ混雑時
18
+ :retryLimit => 3,
19
+ :wait => 120
20
20
  },
21
21
 
22
- 'serviceUnavailable' => { # 503時
23
- 'retryLimit' => 3,
24
- 'wait' => 120
22
+ :serviceUnavailable => { # 503時
23
+ :retryLimit => 3,
24
+ :wait => 120
25
25
  },
26
26
 
27
- 'timedOut' => { # タイムアウト時
28
- 'retryLimit' => 3,
29
- 'wait' => 10
27
+ :timedOut => { # タイムアウト時
28
+ :retryLimit => 3,
29
+ :wait => 10
30
30
  }
31
31
  }
32
32
 
@@ -39,7 +39,7 @@ module Nicos
39
39
 
40
40
  def Config.setWait(waitConfig)
41
41
  case waitConfig
42
- when "default"
42
+ when :default
43
43
  @@waitConfig = @@waitConfigDefault
44
44
  when nil
45
45
  else
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{nicoscraper}
8
- s.version = "0.2.9"
8
+ s.version = "0.2.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Masami Yonehara}]
12
- s.date = %q{2011-09-29}
12
+ s.date = %q{2011-09-30}
13
13
  s.description = %q{It scrape movies and mylists of Niconico douga.
14
14
  }
15
15
  s.email = %q{zeitdiebe@gmail.com}
@@ -1,16 +1,17 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.unshift File.dirname(__FILE__) + "/../lib"
2
+ #$:.unshift File.dirname(__FILE__) + "/../lib"
3
3
 
4
- require 'nicoscraper'
4
+ require '../lib/nicoscraper.rb'
5
+
6
+ describe Nicos::Movie, "After executiton of 'getInfo' method." +
7
+ "And for example, with passing argument (sm1097445)" do
5
8
 
6
- describe Nicos::Movie, "After executiton of 'getInfo' method" do
7
9
  before(:all) do
8
10
  @movie = Nicos::Movie.new("sm1097445")
9
- @movie.getInfo
10
- p @movie
11
+ @result = @movie.getInfo
11
12
  end
12
13
 
13
- it "should have following values" do
14
+ it "should have the following structure and values." do
14
15
  @movie.available .should be_true
15
16
 
16
17
  @movie.video_id .should == "sm1097445"
@@ -38,11 +39,21 @@ describe Nicos::Movie, "After executiton of 'getInfo' method" do
38
39
  end
39
40
 
40
41
  it "should return true when execute 'isBelongsTo' method." +
41
- "passing arguments (1450136)" do
42
+ "with passing arguments (1450136)" do
42
43
  result = @movie.isBelongsTo(1450136)
43
44
  result .should_not be_nil
44
45
  result .should be_true
45
46
  end
47
+
48
+ it "should return the following values." do
49
+ @result[:parsed] .should be_instance_of(Hash)
50
+ @result[:status] .should equal(:success)
51
+ @result[:retry] .should have_key(:deniedSeqReq)
52
+ @result[:retry] .should have_key(:serverIsBusy)
53
+ @result[:retry] .should have_key(:serviceUnavailable)
54
+ @result[:retry] .should have_key(:timedOut)
55
+
56
+ end
46
57
  end
47
58
 
48
59
  describe Nicos::Movie, "when access with non-existent video_id" do
@@ -55,36 +66,3 @@ describe Nicos::Movie, "when access with non-existent video_id" do
55
66
  @movie.available .should be_false
56
67
  end
57
68
  end
58
-
59
- describe Nicos::Mylist, "After executiton of 'getInfo' method" do
60
- before(:all) do
61
- @mylist = Nicos::Mylist.new(15196568)
62
- @mylist.getInfo
63
- puts @mylist
64
- end
65
-
66
- it "should have following values" do
67
- @mylist.available .should be_true
68
-
69
- @mylist.mylist_id .should == 15196568
70
- @mylist.user_id .should be_nil
71
- @mylist.title .should == "【Oblivion】おっさんの大冒険"
72
- @mylist.description .should_not be_nil
73
- @mylist.public .should be_nil
74
- @mylist.default_sort .should be_nil
75
- @mylist.create_time .should be_nil
76
- @mylist.update_time .should_not be_nil
77
-
78
- @mylist.icon_id .should be_nil
79
- @mylist.movies .should_not be_nil
80
- @mylist.movies .should be_kind_of(Array)
81
- @mylist.author .should == "おぽこ"
82
- end
83
-
84
- it "should return over 0.9 when execute 'getSimilarity' method." +
85
- "passing arguments (1450136)" do
86
- result = @mylist.getSimilarity
87
- result .should_not be_nil
88
- result .should >= 0.9
89
- end
90
- end
@@ -3,33 +3,117 @@
3
3
 
4
4
  require '../lib/nicoscraper.rb'
5
5
 
6
- describe Nicos::Movie, "After executiton of 'getInfo' method" do
6
+ describe Nicos::Mylist, "After executiton of 'getInfo' method" +
7
+ "And for example, with passing argument (15196568)" do
7
8
  before(:all) do
8
9
  @mylist = Nicos::Mylist.new(15196568)
9
10
  @mylist.getInfo
10
- p @mylist
11
11
  end
12
12
 
13
- it "should have following values" do
13
+
14
+ it "should have the following values" do
15
+ @mylist.available .should be_true
16
+
17
+ @mylist.mylist_id .should == 15196568
18
+ @mylist.user_id .should be_nil
19
+ @mylist.title .should == "【Oblivion】おっさんの大冒険"
20
+ @mylist.description .should_not be_nil
21
+ @mylist.public .should be_nil
22
+ @mylist.default_sort .should be_nil
23
+ @mylist.create_time .should be_nil
24
+ @mylist.update_time .should_not be_nil
25
+
26
+ @mylist.icon_id .should be_nil
27
+ @mylist.movies .should_not be_nil
28
+ @mylist.movies .should be_kind_of(Array)
29
+ @mylist.author .should == "おぽこ"
30
+ end
31
+
32
+
33
+ it "should have Movie class instances. and these have the following structure." do
14
34
  @mylist.available.should be_true
15
35
 
16
36
  @mylist.mylist_id.should === 15196568
17
- @mylist.movies .should be_instance_of(Array)
37
+ @mylist.movies .should be_instance_of(Array)
18
38
 
19
39
  movieObj = @mylist.movies[0]
20
- movieObj.available .should be_true
40
+ movieObj.available .should be_true
21
41
 
22
- movieObj.video_id .should_not be_nil
23
- movieObj.title .should_not be_nil
24
- movieObj.first_retrieve .should_not be_nil
42
+ movieObj.video_id .should_not be_nil
43
+ movieObj.title .should_not be_nil
44
+ movieObj.first_retrieve .should_not be_nil
25
45
  #movieObj.memo .should_not be_nil
26
- movieObj.description .should_not be_nil
27
- movieObj.thumbnail_url.should_not be_nil
28
- movieObj.length .should_not be_nil
46
+ movieObj.description .should_not be_nil
47
+ movieObj.thumbnail_url .should_not be_nil
48
+ movieObj.length .should_not be_nil
29
49
 
30
- movieObj.view_counter .should_not == 0
31
- movieObj.comment_num .should_not == 0
32
- movieObj.mylist_counter.should_not == 0
50
+ movieObj.view_counter .should_not == 0
51
+ movieObj.comment_num .should_not == 0
52
+ movieObj.mylist_counter .should_not == 0
33
53
  end
34
54
 
35
55
  end
56
+
57
+
58
+ describe Nicos::Mylist, "After executiton of 'getInfo' method" +
59
+ "for non-existent mylist." do
60
+ before(:all) do
61
+ @mylist = Nicos::Mylist.new(999999999)
62
+ end
63
+
64
+ it "should " do
65
+ r = @mylist.getInfo
66
+ r[:status] .should === :notFound
67
+ r[:result] .should be_nil
68
+
69
+ @mylist.available .should_not be_true
70
+ end
71
+ end
72
+
73
+
74
+ describe Nicos::Mylist, "After executiton of 'getInfo' method" +
75
+ "for nonpublic mylist." do
76
+ before(:all) do
77
+ @mylist = Nicos::Mylist.new(22947348)
78
+ end
79
+
80
+ it "should " do
81
+ r = @mylist.getInfo
82
+ r[:status] .should === :notPublic
83
+ r[:result] .should be_nil
84
+
85
+ @mylist.available .should_not be_true
86
+ end
87
+ end
88
+
89
+ # マイリストは削除と404の区別がない?
90
+ describe Nicos::Mylist, "After executiton of 'getInfo' method" +
91
+ "for deleted mylist." do
92
+ before(:all) do
93
+ @mylist = Nicos::Mylist.new(23361251) # 自分のマイリストで、公開設定にしてから削除したもの。
94
+ end
95
+
96
+ it "should " do
97
+ r = @mylist.getInfo
98
+ # r["status] .should === :deleted
99
+ r[:status] .should === :notFound
100
+ r[:result] .should be_nil
101
+
102
+ @mylist.available .should_not be_true
103
+ end
104
+ end
105
+
106
+
107
+ describe Nicos::Mylist, "After executiton of 'getInfo' method" do
108
+ before(:all) do
109
+ @mylist = Nicos::Mylist.new(15196568)
110
+ @mylist.getInfo
111
+ end
112
+
113
+ it "should return over 0.9 when execute 'getSimilarity' method." +
114
+ "passing arguments (1450136)" do
115
+ result = @mylist.getSimilarity
116
+ result .should_not be_nil
117
+ result .should >= 0.9
118
+ end
119
+ end
@@ -7,15 +7,15 @@ require '../lib/nicoscraper.rb'
7
7
  describe "When execute 'Nicos::Connector::setWait" do
8
8
  before(:all) do
9
9
  wait = {
10
- 'seqAccLimit' => 100,
10
+ :seqAccLimit => 100,
11
11
 
12
- 'deniedSeqReq'=> {
13
- 'retryLimit' => 30,
14
- 'wait' => 1200
12
+ :deniedSeqReq => {
13
+ :retryLimit => 30,
14
+ :wait => 1200
15
15
  },
16
16
 
17
- 'serverIsBusy'=> {
18
- 'retryLimit' => 10
17
+ :serverIsBusy => {
18
+ :retryLimit => 10
19
19
  }
20
20
  }
21
21
 
@@ -25,49 +25,49 @@ describe "When execute 'Nicos::Connector::setWait" do
25
25
  it "should have following values." do
26
26
  c = Nicos::Searcher::ByTag.new()
27
27
  c.waitConfig .should_not be_nil
28
- c.waitConfig["seqAccLimit"]
28
+ c.waitConfig[:seqAccLimit]
29
29
  .should == 100
30
- c.waitConfig["afterSeq"]
30
+ c.waitConfig[:afterSeq]
31
31
  .should == 10
32
- c.waitConfig["each"]
32
+ c.waitConfig[:each]
33
33
  .should == 1
34
- c.waitConfig["increment"]
34
+ c.waitConfig[:increment]
35
35
  .should == 1
36
- c.waitConfig["deniedSeqReq"]["retryLimit"]
36
+ c.waitConfig[:deniedSeqReq][:retryLimit]
37
37
  .should == 30
38
- c.waitConfig["deniedSeqReq"]["wait"]
38
+ c.waitConfig[:deniedSeqReq][:wait]
39
39
  .should == 1200
40
- c.waitConfig["serverIsBusy"]["retryLimit"]
40
+ c.waitConfig[:serverIsBusy][:retryLimit]
41
41
  .should == 10
42
- c.waitConfig["serverIsBusy"]["wait"]
42
+ c.waitConfig[:serverIsBusy][:wait]
43
43
  .should == 120
44
- c.waitConfig["serviceUnavailable"]["retryLimit"]
44
+ c.waitConfig[:serviceUnavailable][:retryLimit]
45
45
  .should == 3
46
- c.waitConfig["serviceUnavailable"]["wait"]
46
+ c.waitConfig[:serviceUnavailable][:wait]
47
47
  .should == 120
48
- c.waitConfig["timedOut"]["retryLimit"]
48
+ c.waitConfig[:timedOut][:retryLimit]
49
49
  .should == 3
50
- c.waitConfig["timedOut"]["wait"]
50
+ c.waitConfig[:timedOut][:wait]
51
51
  .should == 10
52
52
  end
53
53
 
54
54
  after(:all) do
55
- Nicos::Connector::Config::setWait("default")
55
+ Nicos::Connector::Config::setWait(:default)
56
56
  end
57
57
  end
58
58
 
59
59
  describe "When execute 'Nicos::Connector::setWait" do
60
60
  before(:all) do
61
61
  wait = {
62
- 'seqAccLimit' => 100,
62
+ :seqAccLimit => 100,
63
63
 
64
- 'deniedSeqReq'=> {
65
- 'retryLimit' => 30,
66
- 'wait' => 1200
64
+ :deniedSeqReq => {
65
+ :retryLimit => 30,
66
+ :wait => 1200
67
67
  },
68
68
 
69
- 'serverIsBusy'=> {
70
- 'retryLimit' => 10
69
+ :serverIsBusy => {
70
+ :retryLimit => 10
71
71
  }
72
72
  }
73
73
 
@@ -79,55 +79,55 @@ describe "When execute 'Nicos::Connector::setWait" do
79
79
 
80
80
  it "should have following values." do
81
81
  @c1.waitConfig .should_not be_nil
82
- @c1.waitConfig["seqAccLimit"]
82
+ @c1.waitConfig[:seqAccLimit]
83
83
  .should == 100
84
- @c1.waitConfig["afterSeq"]
84
+ @c1.waitConfig[:afterSeq]
85
85
  .should == 10
86
- @c1.waitConfig["each"]
86
+ @c1.waitConfig[:each]
87
87
  .should == 1
88
- @c1.waitConfig["increment"]
88
+ @c1.waitConfig[:increment]
89
89
  .should == 1
90
- @c1.waitConfig["deniedSeqReq"]["retryLimit"]
90
+ @c1.waitConfig[:deniedSeqReq][:retryLimit]
91
91
  .should == 30
92
- @c1.waitConfig["deniedSeqReq"]["wait"]
92
+ @c1.waitConfig[:deniedSeqReq][:wait]
93
93
  .should == 1200
94
- @c1.waitConfig["serverIsBusy"]["retryLimit"]
94
+ @c1.waitConfig[:serverIsBusy][:retryLimit]
95
95
  .should == 10
96
- @c1.waitConfig["serverIsBusy"]["wait"]
96
+ @c1.waitConfig[:serverIsBusy][:wait]
97
97
  .should == 120
98
- @c1.waitConfig["serviceUnavailable"]["retryLimit"]
98
+ @c1.waitConfig[:serviceUnavailable][:retryLimit]
99
99
  .should == 3
100
- @c1.waitConfig["serviceUnavailable"]["wait"]
100
+ @c1.waitConfig[:serviceUnavailable][:wait]
101
101
  .should == 120
102
- @c1.waitConfig["timedOut"]["retryLimit"]
102
+ @c1.waitConfig[:timedOut][:retryLimit]
103
103
  .should == 3
104
- @c1.waitConfig["timedOut"]["wait"]
104
+ @c1.waitConfig[:timedOut][:wait]
105
105
  .should == 10
106
106
 
107
107
  @c2.waitConfig .should_not be_nil
108
- @c2.waitConfig["seqAccLimit"]
108
+ @c2.waitConfig[:seqAccLimit]
109
109
  .should == 10
110
- @c2.waitConfig["afterSeq"]
110
+ @c2.waitConfig[:afterSeq]
111
111
  .should == 10
112
- @c2.waitConfig["each"]
112
+ @c2.waitConfig[:each]
113
113
  .should == 1
114
- @c2.waitConfig["increment"]
114
+ @c2.waitConfig[:increment]
115
115
  .should == 1
116
- @c2.waitConfig["deniedSeqReq"]["retryLimit"]
116
+ @c2.waitConfig[:deniedSeqReq][:retryLimit]
117
117
  .should == 3
118
- @c2.waitConfig["deniedSeqReq"]["wait"]
118
+ @c2.waitConfig[:deniedSeqReq][:wait]
119
119
  .should == 120
120
- @c2.waitConfig["serverIsBusy"]["retryLimit"]
120
+ @c2.waitConfig[:serverIsBusy][:retryLimit]
121
121
  .should == 3
122
- @c2.waitConfig["serverIsBusy"]["wait"]
122
+ @c2.waitConfig[:serverIsBusy][:wait]
123
123
  .should == 120
124
- @c2.waitConfig["serviceUnavailable"]["retryLimit"]
124
+ @c2.waitConfig[:serviceUnavailable][:retryLimit]
125
125
  .should == 3
126
- @c2.waitConfig["serviceUnavailable"]["wait"]
126
+ @c2.waitConfig[:serviceUnavailable][:wait]
127
127
  .should == 120
128
- @c2.waitConfig["timedOut"]["retryLimit"]
128
+ @c2.waitConfig[:timedOut][:retryLimit]
129
129
  .should == 3
130
- @c2.waitConfig["timedOut"]["wait"]
130
+ @c2.waitConfig[:timedOut][:wait]
131
131
  .should == 10
132
132
  end
133
133
  end
@@ -136,38 +136,37 @@ describe "When execute 'Nicos::Searcher::ByTag.execute' method " +
136
136
  "and return a string except \"continue\" in this block" do
137
137
  before(:all) do
138
138
  wait = {
139
- 'seqAccLimit' => 0, # 連続してリクエストする回数
140
- 'afterSeq' => 0, # 連続リクエスト後のウェイト(以下全て単位は秒)
141
- 'each' => 0, # 連続リクエスト時の、1リクエスト毎のウェイト
139
+ :seqAccLimit => 100, # 連続してリクエストする回数
140
+ :afterSeq => 0, # 連続リクエスト後のウェイト(以下全て単位は秒)
141
+ :each => 0, # 連続リクエスト時の、1リクエスト毎のウェイト
142
142
 
143
- 'increment' => 0, # アクセス拒絶時の、次回以降の1リクエスト毎のウェイトの増加量
143
+ :increment => 0, # アクセス拒絶時の、次回以降の1リクエスト毎のウェイトの増加量
144
144
 
145
- 'deniedSeqReq'=> { # 連続アクセス拒絶時
146
- 'retryLimit' => 3, # 再試行回数の上限
147
- 'wait' => 120 # 再試行までのウェイト
145
+ :deniedSeqReq=> { # 連続アクセス拒絶時
146
+ :retryLimit => 3, # 再試行回数の上限
147
+ :wait => 120 # 再試行までのウェイト
148
148
  },
149
149
 
150
- 'serverIsBusy'=> { # サーバ混雑時
151
- 'retryLimit' => 3,
152
- 'wait' => 120
150
+ :serverIsBusy=> { # サーバ混雑時
151
+ :retryLimit => 3,
152
+ :wait => 120
153
153
  },
154
154
 
155
- 'serviceUnavailable' => { # 503時
156
- 'retryLimit' => 3,
157
- 'wait' => 120
155
+ :serviceUnavailable => { # 503時
156
+ :retryLimit => 3,
157
+ :wait => 120
158
158
  },
159
159
 
160
- 'timedOut' => { # タイムアウト時
161
- 'retryLimit' => 3,
162
- 'wait' => 10
160
+ :timedOut => { # タイムアウト時
161
+ :retryLimit => 3,
162
+ :wait => 10
163
163
  }
164
164
  }
165
165
  Nicos::Connector::Config::setWait(wait)
166
-
167
166
  searcher = Nicos::Searcher::ByTag.new()
168
167
  @count = 0
169
168
 
170
- searcher.execute("ゆっくり実況プレイpart1リンク", "post_old") { |result|
169
+ searcher.execute("ゆっくり実況プレイpart1リンク", :post_old) { |result|
171
170
  @count += 1
172
171
  "not continue"
173
172
  }
@@ -184,7 +183,7 @@ describe "When execute 'Nicos::Searcher::ByTag.execute' method " +
184
183
  searcher = Nicos::Searcher::ByTag.new()
185
184
  @count = 0
186
185
 
187
- searcher.execute("ゆっくり実況プレイpart1リンク", "post_old") { |result|
186
+ searcher.execute("ゆっくり実況プレイpart1リンク", :post_old) { |result|
188
187
  @count += 1
189
188
  nil
190
189
  }
@@ -201,7 +200,7 @@ describe "When execute 'Nicos::Searcher::ByTag.execute' method " +
201
200
  searcher = Nicos::Searcher::ByTag.new()
202
201
  count = 0
203
202
 
204
- searcher.execute("ゆっくり実況プレイpart1リンク", "post_old") { |result, status|
203
+ searcher.execute("ゆっくり実況プレイpart1リンク", :post_old:) { |result, status|
205
204
  @result = result
206
205
  @status = status
207
206
  p @status
@@ -236,11 +235,11 @@ p @status
236
235
  end
237
236
 
238
237
  it "should contains movie objects that have following structure." do
239
- @status["results"]["notPublic"] .should be_instance_of(Array)
240
- @status["results"]["limInCommunity"].should be_instance_of(Array)
241
- @status["results"]["notFound"] .should be_instance_of(Array)
242
- @status["results"]["deleted"] .should be_instance_of(Array)
243
- @status["results"]["succeededNum"] .should >= 0
238
+ @status[:results][:notPublic] .should be_instance_of(Array)
239
+ @status[:results][:limInCommunity].should be_instance_of(Array)
240
+ @status[:results][:notFound] .should be_instance_of(Array)
241
+ @status[:results][:deleted] .should be_instance_of(Array)
242
+ @status[:results][:succeededNum] .should >= 0
244
243
  end
245
244
  end
246
245
 
@@ -250,7 +249,7 @@ describe "When execute 'Nicos::Searcher::ByTag.execute' method " +
250
249
  searcher = Nicos::Searcher::ByTag.new()
251
250
  count = 0
252
251
 
253
- searcher.execute("アヤックス", "post_old") { |result, status|
252
+ searcher.execute("アヤックス", :post_old) { |result, status|
254
253
  @result = result
255
254
 
256
255
  count += 1
@@ -283,3 +282,25 @@ describe "When execute 'Nicos::Searcher::ByTag.execute' method " +
283
282
  @result[0].mylist_counter.should_not be_nil
284
283
  end
285
284
  end
285
+
286
+ describe "When execute 'Nicos::Searcher::ByTag.execute' method " +
287
+ "and exception caused." do
288
+ before(:all) do
289
+ searcher = Nicos::Searcher::ByTag.new()
290
+ count = 0
291
+
292
+ searcher.execute("アヤックス", :post_old) { |result, status|
293
+ @result = result
294
+
295
+ count += 1
296
+ puts count
297
+ "continue"
298
+ }
299
+ end
300
+
301
+ it "should have Array of movie objects." do
302
+ @result .should be_kind_of(Array)
303
+ @result[0].should be_instance_of(Nicos::Movie)
304
+ end
305
+
306
+ end