nicoscraper 0.2.12 → 0.2.13
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.
- data/Gemfile +0 -2
- data/Gemfile.lock +0 -13
- data/README.md +37 -27
- data/VERSION +1 -1
- data/lib/classes/connector.rb +43 -161
- data/lib/classes/movie.rb +46 -45
- data/lib/classes/mylist.rb +111 -141
- data/lib/classes/parser.rb +343 -264
- data/lib/classes/searcher.rb +4 -4
- data/lib/classes/tools.rb +11 -0
- data/lib/config/mylist.rb +5 -0
- data/lib/nicoscraper.rb +1 -1
- data/nicoscraper.gemspec +4 -8
- data/test/mylist_getmoreinfo_spec.rb +122 -0
- data/test/mylist_spec.rb +7 -3
- metadata +17 -37
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,36 +1,23 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
damerau-levenshtein (0.5.3)
|
5
4
|
git (1.2.5)
|
6
5
|
jeweler (1.6.4)
|
7
6
|
bundler (~> 1.0)
|
8
7
|
git (>= 1.2.5)
|
9
8
|
rake
|
10
9
|
libxml-ruby (2.2.2)
|
11
|
-
mechanize (2.0.1)
|
12
|
-
net-http-digest_auth (>= 1.1.1, ~> 1.1)
|
13
|
-
net-http-persistent (~> 1.8)
|
14
|
-
nokogiri (~> 1.4)
|
15
|
-
webrobots (>= 0.0.9, ~> 0.0)
|
16
|
-
net-http-digest_auth (1.1.1)
|
17
|
-
net-http-persistent (1.9)
|
18
|
-
nokogiri (1.5.0)
|
19
10
|
rake (0.8.7)
|
20
11
|
rcov (0.9.10)
|
21
12
|
shoulda (2.11.3)
|
22
|
-
webrobots (0.0.11)
|
23
|
-
nokogiri (>= 1.4.4)
|
24
13
|
|
25
14
|
PLATFORMS
|
26
15
|
ruby
|
27
16
|
|
28
17
|
DEPENDENCIES
|
29
18
|
bundler (~> 1.0.0)
|
30
|
-
damerau-levenshtein (>= 0.5.3)
|
31
19
|
jeweler (~> 1.6.4)
|
32
20
|
libxml-ruby (>= 2.2.2)
|
33
|
-
mechanize (>= 2.0.0)
|
34
21
|
rake (= 0.8.7)
|
35
22
|
rcov
|
36
23
|
shoulda
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
以下は[rubydoc](http://rubydoc.info/gems/nicoscraper/
|
1
|
+
以下は[rubydoc](http://rubydoc.info/gems/nicoscraper/)からの転載です。詳細はそちらを御覧下さい。
|
2
2
|
|
3
3
|
|
4
4
|
NicoScraper
|
@@ -9,8 +9,8 @@ NicoScraper
|
|
9
9
|
**Author:** Masami Yonehara
|
10
10
|
**Copyright:** 2011
|
11
11
|
**License:** MIT License
|
12
|
-
**Latest Version:** 0.2.
|
13
|
-
**Release Date:** Oct
|
12
|
+
**Latest Version:** 0.2.13
|
13
|
+
**Release Date:** Oct 17th 2011
|
14
14
|
|
15
15
|
|
16
16
|
何をするライブラリ?
|
@@ -62,7 +62,7 @@ NicoScraper
|
|
62
62
|
|
63
63
|
<Nicos::Movie:0x00000002537aa8
|
64
64
|
@video_id="sm1097445",
|
65
|
-
@available=
|
65
|
+
@available=true,
|
66
66
|
@title="【初音ミク】みくみくにしてあげる♪【してやんよ】",
|
67
67
|
@description="おまえら、みっくみくにしてやんよ。歌詞は...",
|
68
68
|
@thumbnail_url="http://tn-skr2.smile...",
|
@@ -98,6 +98,9 @@ NicoScraper
|
|
98
98
|
|
99
99
|
<Nicos::Mylist:0x00000002884670
|
100
100
|
@mylist_id=15196568,
|
101
|
+
@available=true,
|
102
|
+
@title="【Oblivion】おっさんの大冒険",
|
103
|
+
...
|
101
104
|
@movies=[
|
102
105
|
#<Nicos::Movie:0x0000000255a968
|
103
106
|
@video_id="sm8481759",
|
@@ -110,8 +113,6 @@ NicoScraper
|
|
110
113
|
@title="【Oblivion】おっさんの大冒険2(ゆっくり実況)",
|
111
114
|
... ,
|
112
115
|
],
|
113
|
-
@available=true,
|
114
|
-
@title="【Oblivion】おっさんの大冒険",
|
115
116
|
... >
|
116
117
|
|
117
118
|
というように、動画インスタンスを勝手につくりだして配列として保持します。もちろん、これらの動画インスタンスには独立した操作を加えられます。
|
@@ -129,9 +130,9 @@ NicoScraper
|
|
129
130
|
|
130
131
|
searchByTag = Nicos::Searcher::ByTag.new()
|
131
132
|
searchByTag.execute(
|
132
|
-
'VOCALOID',
|
133
|
-
:post_new
|
134
|
-
) { |result, status|
|
133
|
+
'VOCALOID', # 検索したいタグ文字列
|
134
|
+
:post_new # ソート方法
|
135
|
+
) { |result, status| # 動画インスタンスの配列 / その時点でのアクセス結果
|
135
136
|
terminate = false
|
136
137
|
|
137
138
|
result.each { |movie| # first_retrieve == 投稿日
|
@@ -146,7 +147,7 @@ NicoScraper
|
|
146
147
|
"continue" unless terminate
|
147
148
|
}
|
148
149
|
|
149
|
-
この例では、`VOCALOID
|
150
|
+
この例では、`VOCALOID`というタグの付く動画を、`:post_new`=投稿日時が新しい順からさかのぼって取得し、取得した動画の日付が3日前の0時0分を超えるまでそれを続けます。
|
150
151
|
|
151
152
|
ブロック内の第1引数には取得結果に基づく動画インスタンスが与えられるのですが、これは32個分の配列です。なぜ32個のセットなのかと言うと、ご存知のようにニコニコ動画の検索画面はページで区切られており、Searcherモジュールの各メソッドはページ毎に情報を取得し、ページ単位でブロックをコールするからです。HTMLから取得するにしろAtomフィードから取得するにしろ、1ページに32個の動画情報が含まれています。第2引数にはそれまでのアクセス成否情報等が渡されます。
|
152
153
|
|
@@ -176,7 +177,7 @@ NicoScraper
|
|
176
177
|
|
177
178
|
|
178
179
|
**その動画が属する、シリーズとみなせるマイリストのIDを返します。**
|
179
|
-
{Nicos::Movie#
|
180
|
+
{Nicos::Movie#SearchSeriesMl Nicos::Movie::SearchSeriesMl}
|
180
181
|
|
181
182
|
`isBelongsTo`と`getSimilarity`の組み合わせにより、ある動画の説明文中にマイリストの記載がある場合、そのマイリストがタイトルの類似性によるシリーズとみなせるならば、そのIDを返します。
|
182
183
|
|
@@ -226,33 +227,36 @@ NicoScraper
|
|
226
227
|
|
227
228
|
###レスポンスの種類に対する反応について
|
228
229
|
|
229
|
-
|
230
|
+
ニコニコ動画のサーバのレスポンスには、正常にデータを返す以外にいくつかの反応があります。この反応に応じて再試行するか、それともそのリクエストをパスするかが決定されます。以下はレスポンスの内容と、それに対応するウェイト設定用ハッシュのキー、およびメソッドが返すステータスです。ステータスについては各メソッドの説明を参照して下さい。
|
230
231
|
|
231
|
-
|
232
|
+
**削除済み** `:deleted`
|
233
|
+
**404** `:notFound`
|
232
234
|
|
233
|
-
|
235
|
+
再試行をせず、次の処理に移行します。
|
236
|
+
|
237
|
+
**非公開** `:notPublic`
|
238
|
+
**コミュニティ限定** `:limInCommunity`
|
234
239
|
|
235
|
-
|
240
|
+
動画がマイリストが非公開設定されている場合、あるいはコミュニティ未加入者には非公開になっている動画があります。後者については(前者も自分のものであれば)ログイン処理を事前に行うことで技術的には取得可能ですが、v0.2では未実装です。これらの動画の場合、処理は404に準じます。なお、この場合は内部的には403が返ってきています。
|
236
241
|
|
237
|
-
|
242
|
+
**連続アクセスの拒絶** `:deniedSeqReq`
|
238
243
|
|
239
|
-
|
244
|
+
"短時間での連続アクセスはご遠慮ください" と表示される場合です。設定に従って**再試行します。**
|
240
245
|
|
241
|
-
|
242
|
-
|
243
|
-
**4. 非公開・権限なし**
|
246
|
+
**サーバ混雑時** `:serverIsBusy`
|
244
247
|
|
245
|
-
|
248
|
+
"大変ご迷惑をおかけいたしますが、しばらく時間をあけてから再度検索いただくようご協力をお願いいたします。" と表示される場合です。**再試行します。**
|
246
249
|
|
247
|
-
**
|
250
|
+
**503** `:serviceUnavailable`
|
248
251
|
|
249
|
-
|
252
|
+
メンテナンス時に限らず、稼働時にも稀に発生します。処理全体を中断することはなく、**再試行します。**
|
250
253
|
|
251
|
-
|
254
|
+
**タイムアウト** `:timedOut`
|
255
|
+
**再試行します。**
|
252
256
|
|
253
|
-
|
257
|
+
再試行するメソッドの場合、ウェイトの`increment`の秒数、次回以降の1リクエスト毎のウェイトを増加させます。
|
254
258
|
|
255
|
-
|
259
|
+
上記のどれにも該当しない場合、つまり取得とパースに成功した場合には`:succeed`を返します。なお、マイリストは有効に存在し取得もできるが、動画は存在しないという場合も`:succeed`であり、@movies配列が空になるだけです。
|
256
260
|
|
257
261
|
###設定方法
|
258
262
|
|
@@ -310,7 +314,7 @@ Mylistクラスのインスタンス
|
|
310
314
|
###要望、バグ報告について
|
311
315
|
以下のどちらかにお願いします。
|
312
316
|
|
313
|
-
+
|
317
|
+
+ hdemon7@gmail.com
|
314
318
|
|
315
319
|
+ http://twitter.com/h_demon
|
316
320
|
|
@@ -334,6 +338,12 @@ GitHubを経由して下さってもいいのですが、まだ慣れていな
|
|
334
338
|
|
335
339
|
###更新履歴
|
336
340
|
|
341
|
+
**v 0.2.13 **
|
342
|
+
|
343
|
+
+ タイトル類似性判定ロジックを、編集距離う使う手法からn-gram法(n=3)に変更。
|
344
|
+
|
345
|
+
+ htmlを用いたより詳細な情報を取得するMylist::getMoreInfoメソッドを試験的に実装。
|
346
|
+
|
337
347
|
**v 0.2.11 0.2.12**
|
338
348
|
|
339
349
|
+ Seacherの各メソッドで、取得結果が配列に累積されてしまうバグを修正。
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.13
|
data/lib/classes/connector.rb
CHANGED
@@ -19,6 +19,7 @@ module Nicos
|
|
19
19
|
:limInCommunity => [],
|
20
20
|
:notFound => [],
|
21
21
|
:deleted => [],
|
22
|
+
:noMovie => [],
|
22
23
|
|
23
24
|
:deniedSeqReq => 0,
|
24
25
|
:serverIsBusy => 0,
|
@@ -64,6 +65,11 @@ module Nicos
|
|
64
65
|
accessDisabled(:notFound)
|
65
66
|
end
|
66
67
|
|
68
|
+
def noMovie
|
69
|
+
puts "This movie/mylist contains no movie."
|
70
|
+
accessDisabled(:noMovie)
|
71
|
+
end
|
72
|
+
|
67
73
|
def deleted # マイリストは削除と404の区別がない?
|
68
74
|
puts "This movie/mylist is deleted."
|
69
75
|
accessDisabled(:deleted)
|
@@ -72,8 +78,8 @@ module Nicos
|
|
72
78
|
# 以下、再試行の可能性のある例外
|
73
79
|
|
74
80
|
# 共通処理
|
75
|
-
def exception(exception
|
76
|
-
if retryCount <= @waitConfig[exception][:retryLimit]
|
81
|
+
def exception(exception)
|
82
|
+
if @retryCount <= @waitConfig[exception][:retryLimit]
|
77
83
|
{ :order => :skip }
|
78
84
|
else
|
79
85
|
sleep @waitConfig[exception][:wait]
|
@@ -82,27 +88,26 @@ module Nicos
|
|
82
88
|
end
|
83
89
|
end
|
84
90
|
|
85
|
-
def deniedSeqReq
|
91
|
+
def deniedSeqReq
|
86
92
|
puts "Denied sequential requests."
|
87
|
-
exception(:deniedSeqReq
|
93
|
+
exception(:deniedSeqReq)
|
88
94
|
end
|
89
95
|
|
90
|
-
def serverIsBusy
|
96
|
+
def serverIsBusy
|
91
97
|
puts "The server is busy."
|
92
|
-
exception(:serverIsBusy
|
98
|
+
exception(:serverIsBusy)
|
93
99
|
end
|
94
100
|
|
95
|
-
def serviceUnavailable
|
101
|
+
def serviceUnavailable
|
96
102
|
puts "Service unavailable."
|
97
|
-
exception(:serviceUnavailable
|
103
|
+
exception(:serviceUnavailable)
|
98
104
|
end
|
99
105
|
|
100
|
-
def timedOut
|
106
|
+
def timedOut
|
101
107
|
puts "Request timed out."
|
102
|
-
exception(:timedOut
|
108
|
+
exception(:timedOut)
|
103
109
|
end
|
104
110
|
|
105
|
-
|
106
111
|
def reachedLast
|
107
112
|
# TagAtom専用。MylistAtomは、allDisabledと結果が被ってしまう。
|
108
113
|
puts "Reached the last page."
|
@@ -156,40 +161,34 @@ module Nicos
|
|
156
161
|
end
|
157
162
|
|
158
163
|
class Xml < Connector
|
159
|
-
def get (host, entity)
|
164
|
+
def get (host, entity, param)
|
160
165
|
response = nil
|
161
|
-
retryCount = 0
|
166
|
+
@retryCount = 0
|
162
167
|
res = {}
|
163
168
|
|
164
169
|
begin
|
165
|
-
@nowAccess = host + entity
|
170
|
+
@nowAccess = host + entity + param
|
166
171
|
puts "Request to " + @nowAccess
|
167
172
|
Net::HTTP.start(host, 80) { |http|
|
168
|
-
response = http.get(entity, HEADER)
|
173
|
+
response = http.get(entity + param, HEADER)
|
169
174
|
}
|
170
|
-
retryCount += 1
|
175
|
+
@retryCount += 1
|
171
176
|
|
172
177
|
rescue => e
|
173
178
|
puts e
|
174
|
-
rescue Timeout::Error => e
|
175
|
-
|
176
|
-
res[:order] = :retry
|
177
|
-
|
179
|
+
rescue Timeout::Error => e
|
180
|
+
timedOut
|
181
|
+
res[:order] = :retry
|
178
182
|
else
|
179
183
|
res = case response
|
180
|
-
when Net::HTTPSuccess
|
184
|
+
when Net::HTTPSuccess then
|
181
185
|
reviewRes( response.body.force_encoding("UTF-8") )
|
182
|
-
# return response.body.force_encoding("UTF-8")
|
183
186
|
# when Net::HTTPRedirection
|
184
187
|
# fetch(response['location'], limit - 1)
|
185
|
-
when Net::HTTPForbidden
|
186
|
-
|
187
|
-
when Net::
|
188
|
-
|
189
|
-
when Net::HTTPServiceUnavailable
|
190
|
-
serviceUnavailable
|
191
|
-
else
|
192
|
-
unknownError
|
188
|
+
when Net::HTTPForbidden then forbidden
|
189
|
+
when Net::HTTPNotFound then notFound
|
190
|
+
when Net::HTTPServiceUnavailable then serviceUnavailable
|
191
|
+
else unknownError
|
193
192
|
end
|
194
193
|
end until res[:order] != :retry
|
195
194
|
|
@@ -257,139 +256,22 @@ module Nicos
|
|
257
256
|
end
|
258
257
|
end
|
259
258
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
# デフォルトのウェイト設定
|
265
|
-
@@waitConfig = {
|
266
|
-
'consec_count' => 10, # 連続してリクエストする回数
|
267
|
-
'consec_wait' => 10, # 連続リクエスト後のウェイト
|
268
|
-
'each' => 10, # 連続リクエスト時の、1リクエスト毎のウェイト
|
269
|
-
|
270
|
-
'200-abnormal' => 300, # アクセス拒絶時(「短時間での連続アクセスは・・・」)の場合の再試行までの時間
|
271
|
-
'unavailable' => 10,
|
272
|
-
'403' => 300, # "403"時の再試行までのウェイト
|
273
|
-
'404' => 300, # "403"時の再試行までのウェイト
|
274
|
-
'increment' => 1, # アクセス拒絶時の、次回以降の1リクエスト毎のウェイトの増加量
|
275
|
-
|
276
|
-
'timeout' => 10, # タイムアウト時の、再試行までのウェイト
|
277
|
-
'500' => 10, # "500"時の再試行までのウェイト
|
278
|
-
'503' => 10, # "503"時の再試行までのウェイト
|
279
|
-
|
280
|
-
'retryLimit' => 3 # 再試行回数の限度
|
281
|
-
}
|
282
|
-
|
283
|
-
# 1つの検索結果画面に表示される動画の数。現時点では32個がデフォルトの模様。
|
284
|
-
@NumOfSearched = 32
|
285
|
-
|
286
|
-
@mech = Mechanize.new
|
287
|
-
# メモリ節約のため、Mechanizeの履歴機能を切る。
|
288
|
-
@mech.max_history = 1
|
289
|
-
|
290
|
-
@consec_count = 0
|
291
|
-
end
|
292
|
-
|
293
|
-
public
|
294
|
-
|
295
|
-
def errorStatus(ex)
|
296
|
-
# 再試行回数が
|
297
|
-
@retryTime += 1
|
298
|
-
if @retryTime >= @wait['allowance_time']
|
299
|
-
return false
|
300
|
-
end
|
301
|
-
|
302
|
-
case ex.response_code
|
303
|
-
when '403' then
|
304
|
-
sleep @wait['403']
|
305
|
-
warn "403"
|
306
|
-
when '500' then
|
307
|
-
sleep @wait['500']
|
308
|
-
warn "500"
|
309
|
-
when '503' then
|
310
|
-
sleep @wait['503']
|
311
|
-
warn "503"
|
312
|
-
else
|
313
|
-
warn "Server error: #{ex.code}"
|
314
|
-
return false
|
315
|
-
end
|
316
|
-
|
317
|
-
@connection = false
|
318
|
-
@failed += 1
|
259
|
+
class MylistHtml < Xml
|
260
|
+
def forbidden
|
261
|
+
# マイリストが非公開の場合、html/Atomのどちらへのリクエストであっても、403が返ってくる。
|
262
|
+
notPublic
|
319
263
|
end
|
320
|
-
|
321
|
-
def
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
eachWait
|
327
|
-
@connection = nil
|
328
|
-
request.call(url)
|
329
|
-
|
330
|
-
# タイムアウト時処理
|
331
|
-
rescue TimeoutError
|
332
|
-
timeOut
|
333
|
-
retry
|
334
|
-
|
335
|
-
# Mechanizeでアクセスし、200以外のステータスが返ってきた時
|
336
|
-
# 実際に該当するコードが返ってきたことがないので、正常に動くか不明
|
337
|
-
rescue Mechanize::ResponseCodeError => ex
|
338
|
-
if errorStatus(ex) then retry
|
339
|
-
else break end
|
340
|
-
|
341
|
-
# HTTP Status:200時の処理
|
264
|
+
|
265
|
+
def reviewRes(resBody)
|
266
|
+
r = resBody.force_encoding("UTF-8")
|
267
|
+
if # アクセス集中時
|
268
|
+
/大変ご迷惑をおかけいたしますが、しばらく時間をあけてから再度検索いただくようご協力をお願いいたします。/ =~ r then
|
269
|
+
serverIsBusy
|
342
270
|
else
|
343
|
-
|
344
|
-
|
345
|
-
# 失敗カウントが指定回数を超えたらループを終わる。
|
346
|
-
if @failed >= @wait['allowance_time'] then
|
347
|
-
puts 'Exceeded the limit of retry time.'
|
348
|
-
@connection = false
|
349
|
-
break
|
350
|
-
end
|
351
|
-
end until @connection
|
352
|
-
|
353
|
-
# 連続アクセスカウント+1
|
354
|
-
@consec_count += 1
|
355
|
-
# 成功 = true / 失敗 = false
|
356
|
-
return @connection
|
357
|
-
end
|
358
|
-
|
359
|
-
def htmlGet (host, entity)
|
360
|
-
htmlReq(
|
361
|
-
host + entity,
|
362
|
-
lambda { |url|
|
363
|
-
t = Thread.new do
|
364
|
-
@mech.get(url)
|
365
|
-
puts "Requesting for " + url
|
366
|
-
end
|
367
|
-
t.join
|
368
|
-
},
|
369
|
-
# HTTP Status:200時の処理
|
370
|
-
lambda {
|
371
|
-
# 連続アクセス拒絶メッセージが返ってきた時
|
372
|
-
if /短時間での連続アクセスはご遠慮ください/ =~ @mech.page.search('/html').text then
|
373
|
-
puts 'Access rejected.'
|
374
|
-
@connection = false
|
375
|
-
@failed += 1
|
376
|
-
|
377
|
-
# ウェイトを置いた後、今後のページ毎のウェイトを増やす。
|
378
|
-
puts 'Waiting for ' + @wait['rejected'] + 's.'
|
379
|
-
sleep @wait['rejected']
|
380
|
-
@wait['each'] += @wait['increment']
|
381
|
-
puts 'Increased each @wait by ' + @wait['increment'] + 'sec.'
|
382
|
-
else
|
383
|
-
@connection = true
|
384
|
-
end
|
385
|
-
}
|
386
|
-
)
|
387
|
-
|
388
|
-
return @mech.page
|
271
|
+
succeeded(resBody)
|
272
|
+
end
|
389
273
|
end
|
390
|
-
|
391
|
-
attr_reader :mech
|
392
274
|
end
|
393
|
-
|
394
|
-
end
|
275
|
+
|
276
|
+
end # end of connector
|
395
277
|
end
|
data/lib/classes/movie.rb
CHANGED
@@ -24,18 +24,18 @@ module Nicos
|
|
24
24
|
|
25
25
|
# 指定されたマイリストに自分が入っていれば、真を返す。
|
26
26
|
#
|
27
|
-
# 内部的にMylist::
|
27
|
+
# 内部的にMylist::getMoreInfoを利用しているため、もし指定したマイリストの他の情報を使いたければ、
|
28
28
|
# ブロック中に処理を記述することで、getInfoの取得結果を共用することができる。
|
29
29
|
# @param [Fixnum] mylistId マイリストID
|
30
30
|
# @return [Boolean]
|
31
31
|
def isBelongsTo (mylistId, &block)
|
32
32
|
isBelongs = false
|
33
33
|
thisMl = Nicos::Mylist.new(mylistId)
|
34
|
-
thisMl.
|
35
|
-
|
36
|
-
thisMl.movies.each
|
34
|
+
thisMl.getMoreInfo
|
35
|
+
|
36
|
+
thisMl.movies.each do |movie|
|
37
37
|
isBelongs = true if movie.video_id == @video_id
|
38
|
-
|
38
|
+
end if thisMl.movies != nil
|
39
39
|
|
40
40
|
if isBelongs
|
41
41
|
puts "\sThis movie is found in mylist/" +
|
@@ -53,42 +53,42 @@ module Nicos
|
|
53
53
|
#
|
54
54
|
# isBelongsは指定されたマイリストとの関係を調べるが、isSeriesOfは動画説明文中のマイリストIDのみを用いる。
|
55
55
|
# @return [Fixnum] マイリストID
|
56
|
-
def
|
56
|
+
def searchSeriesMl(threshold)
|
57
57
|
if !@available then
|
58
58
|
puts "This movie object is not available."
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
59
|
+
"failed"
|
60
|
+
else
|
61
|
+
puts
|
62
|
+
puts "Start to discern the seriality of..."
|
63
|
+
puts "\svideo_id:\s\s#{@video_id}"
|
64
|
+
puts "\stitle:\s\s\s\s\s#{@title}"
|
65
|
+
|
66
|
+
mylistIdAry = extrMylist
|
67
|
+
resultAry = []
|
68
|
+
mlobj = nil
|
69
|
+
similarity = 0.0
|
70
|
+
belongsTo = nil
|
71
|
+
|
72
|
+
mylistIdAry.each { |_mylistId|
|
73
|
+
belongsTo = isBelongsTo(_mylistId) { |mylistObj|
|
74
|
+
similarity = mylistObj.getSimilarity
|
75
|
+
puts "\sSimilarity:\t#{similarity}"
|
76
|
+
mlobj = mylistObj
|
77
|
+
}
|
78
|
+
|
79
|
+
if belongsTo
|
80
|
+
puts "\s#{_mylistId.to_s}\tis perecieved as series mylist."
|
81
|
+
resultAry.push({
|
82
|
+
:mylistObj => mlobj,
|
83
|
+
:similarity => similarity
|
84
|
+
})
|
85
|
+
end
|
78
86
|
}
|
79
|
-
|
80
|
-
|
81
|
-
puts "\s" + _mylistId.to_s + "\tis perecieved as series mylist."
|
82
|
-
sMylistIdAry.push(_mylistId)
|
83
|
-
end
|
84
|
-
}
|
85
|
-
|
86
|
-
sMylistIdAry.each { |mylistId|
|
87
|
-
mlObjAry.push( Nicos::Mylist.new(mylistId) )
|
88
|
-
}
|
87
|
+
|
88
|
+
puts "\sDiscern logic terminated."
|
89
89
|
|
90
|
-
|
91
|
-
|
90
|
+
resultAry
|
91
|
+
end
|
92
92
|
end
|
93
93
|
|
94
94
|
# 動画説明文中からマイリストIDを示す文字列を抽出し、配列として返す。
|
@@ -104,7 +104,7 @@ module Nicos
|
|
104
104
|
extracted.each { |e|
|
105
105
|
id = e.scan(/[0-9]{1,8}/)[0]
|
106
106
|
mylistIdAry.push(id)
|
107
|
-
puts "\sID:\t
|
107
|
+
puts "\sID:\t#{id} is extracted."
|
108
108
|
}
|
109
109
|
else
|
110
110
|
puts "\sMylistId is not found."
|
@@ -123,24 +123,24 @@ module Nicos
|
|
123
123
|
|
124
124
|
con = Nicos::Connector::GetThumbInfo.new()
|
125
125
|
host = 'ext.nicovideo.jp'
|
126
|
-
entity =
|
126
|
+
entity = "/api/getthumbinfo/#{@video_id}"
|
127
127
|
|
128
|
-
result = con.get(host, entity)
|
128
|
+
result = con.get(host, entity, '')
|
129
129
|
status = con.getStatus
|
130
130
|
|
131
131
|
if result[:order] == :afterTheSuccess
|
132
|
-
parsed = Nicos::Parser::getThumbInfo(result[:body])
|
132
|
+
parsed = Nicos::Parser::Xml::getThumbInfo(result[:body])
|
133
133
|
set(parsed)
|
134
134
|
@available = true
|
135
135
|
end
|
136
136
|
|
137
|
-
{
|
138
|
-
:parsed => parsed,
|
137
|
+
{
|
138
|
+
:parsed => parsed,
|
139
139
|
:status => status[:status],
|
140
140
|
:retry => status[:retry]
|
141
141
|
}
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
# インスタンスに対し、任意の情報を入れる。
|
145
145
|
#
|
146
146
|
# @param [HashObj] paramObj getThumbInfo等から手に入れたハッシュ
|
@@ -165,7 +165,8 @@ module Nicos
|
|
165
165
|
when "description",:description then @description = param.to_s
|
166
166
|
when "length", :length then @length = param.to_i
|
167
167
|
when "first_retrieve", :first_retrieve then @first_retrieve = param
|
168
|
-
|
168
|
+
when "group_type",:group_type then @group_type
|
169
|
+
|
169
170
|
# MylistAPI 現在未実装
|
170
171
|
when "item_data"
|
171
172
|
paramObj['item_data'].each_key do |key|
|