nicoscraper 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,6 @@ require 'parser.rb'
9
9
  require 'mylist.rb'
10
10
  require 'connector.rb'
11
11
 
12
-
13
12
  module Nicos
14
13
  class Movie
15
14
  # @param [video_id] video_id 動画ID
@@ -119,20 +118,27 @@ module Nicos
119
118
  # 内部的にgetThumbInfo APIを利用。
120
119
  # @return [Boolean] 成功すればtrueを返す。
121
120
  def getInfo
121
+ parsed = nil
122
+ @available = false
123
+
122
124
  con = Nicos::Connector::GetThumbInfo.new()
123
125
  host = 'ext.nicovideo.jp'
124
126
  entity = '/api/getthumbinfo/' + @video_id
127
+
125
128
  result = con.get(host, entity)
129
+ status = con.getStatus
126
130
 
127
- if
128
- result["order"] == "afterTheSuccess"
129
- then
130
- parsed = Nicos::Parser::getThumbInfo(result["body"])
131
+ if result[:order] == :afterTheSuccess
132
+ parsed = Nicos::Parser::getThumbInfo(result[:body])
131
133
  set(parsed)
132
134
  @available = true
133
- else
134
- @available = false
135
135
  end
136
+
137
+ {
138
+ :parsed => parsed,
139
+ :status => status[:status],
140
+ :retry => status[:retry]
141
+ }
136
142
  end
137
143
 
138
144
  # インスタンスに対し、任意の情報を入れる。
@@ -149,110 +155,65 @@ module Nicos
149
155
  paramObj.each_key { |key|
150
156
  param = paramObj[key]
151
157
  case key
152
- when "available"
153
- @available = param
158
+ when "available", :available then @available = param
154
159
 
155
160
  # common
156
- when "video_id"
157
- @video_id = param.to_s
158
- when "item_id"
159
- @item_id = param.to_i
160
- when "title"
161
- @title = param.to_s
162
- when "mylist_id"
163
- @mylist_id = param.to_i
164
- when "description"
165
- @description = param.to_s
166
- when "length"
167
- @length = param.to_i
168
- when "first_retrieve"
169
- @first_retrieve = param
161
+ when "video_id", :video_id then @video_id = param.to_s
162
+ when "item_id", :item_id then @item_id = param.to_i
163
+ when "title", :title then @title = param.to_s
164
+ when "mylist_id", :mylist_id then @mylist_id = param.to_i
165
+ when "description",:description then @description = param.to_s
166
+ when "length", :length then @length = param.to_i
167
+ when "first_retrieve", :first_retrieve then @first_retrieve = param
170
168
 
171
169
  # MylistAPI 現在未実装
172
170
  when "item_data"
173
- paramObj['item_data'].each_key { |key|
174
- param = paramObj['item_data'][key]
171
+ paramObj['item_data'].each_key do |key|
172
+ param = paramObj['item_data'][key]
175
173
  case key
176
- when "video_id"
177
- @video_id = param.to_s
178
- when "title"
179
- @title = param.to_s
180
- when "thumbnail_url"
181
- @thumbnail_url = param.to_s
182
- when "first_retrieve"
183
- @first_retrieve = param.to_i
184
- when "update_time"
185
- @update_time = param.to_i
186
- when "view_counter"
187
- @view_counter = param.to_i
188
- when "mylist_counter"
189
- @mylist_counter = param.to_i
190
- when "num_res"
191
- @comment_num = param.to_i
192
- when "length_seconds"
193
- @length = param.to_i
194
- when "deleted"
195
- @deleted = param.to_i
196
- when "last_res_body"
197
- @last_res_body = param.to_s
174
+ when "video_id" then @video_id = param.to_s
175
+ when "title" then @title = param.to_s
176
+ when "thumbnail_url" then @thumbnail_url = param.to_s
177
+ when "first_retrieve" then @first_retrieve = param.to_i
178
+ when "update_time" then @update_time = param.to_i
179
+ when "view_counter" then @view_counter = param.to_i
180
+ when "mylist_counter" then @mylist_counter = param.to_i
181
+ when "num_res" then @comment_num = param.to_i
182
+ when "length_seconds" then @length = param.to_i
183
+ when "deleted" then @deleted = param.to_i
184
+ when "last_res_body" then @last_res_body = param.to_s
198
185
  end
199
- }
200
- when "watch"
201
- @watch = param.to_i
202
- when "create_time"
203
- @create_time = param.to_i
204
- when "update_time"
205
- @update_time = param.to_i
186
+ end
187
+ when "watch", :watch then @watch = param.to_i
188
+ when "create_time",:create_time then @create_time = param.to_i
189
+ when "update_time",:update_time then @update_time = param.to_i
206
190
 
207
191
  # Mylist-Atom
208
- when "memo"
209
- @memo = param.to_s
210
- when "published"
211
- @create_time = param.to_i
212
- when "updated"
213
- @update_time = param.to_i
214
- when "view"
215
- @view_counter = param.to_i
216
- when "mylist"
217
- @mylist_counter = param.to_i
218
- when "res"
219
- @comment_num = param.to_i
192
+ when "memo", :memo then @memo = param.to_s
193
+ when "published", :published then @create_time = param.to_i
194
+ when "updated", :updated then @update_time = param.to_i
195
+ when "view", :view then @view_counter = param.to_i
196
+ when "mylist", :mylist then @mylist_counter = param.to_i
197
+ when "res", :res then @comment_num = param.to_i
220
198
 
221
199
  # getThumbInfo
222
- when "thumbnail_url"
223
- @thumbnail_url = param.to_s
224
- when "movie_type"
225
- @movie_type = param.to_s
226
- when "size_high"
227
- @size_high = param.to_i
228
- when "size_low"
229
- @size_low = param.to_i
230
- when "view_counter"
231
- @view_counter = param.to_i
232
- when "mylist_counter"
233
- @mylist_counter = param.to_i
234
- when "comment_num"
235
- @comment_num = param.to_i
236
- when "last_res_body"
237
- @last_res_body = param.to_s
238
- when "watch_url"
239
- @watch_url = param.to_s
240
- when "thumb_type"
241
- @thumb_type = param.to_s
242
- when "embeddable"
243
- @embeddable = param.to_i
244
- when "no_live_play"
245
- @no_live_play = param.to_i
246
- when "tags_jp"
247
- @tags_jp = param
248
- when "tags_tw"
249
- @tags_tw = param
250
- when "tags_de"
251
- @tags_de = param
252
- when "tags_es"
253
- @tags_sp = param
254
- when "user_id"
255
- @user_id = param.to_i
200
+ when "thumbnail_url", :thumbnail_url then @thumbnail_url = param.to_s
201
+ when "movie_type", :movie_type then @movie_type = param.to_s
202
+ when "size_high", :size_high then @size_high = param.to_i
203
+ when "size_low", :size_low then @size_low = param.to_i
204
+ when "view_counter", :view_counter then @view_counter = param.to_i
205
+ when "mylist_counter", :mylist_counter then @mylist_counter = param.to_i
206
+ when "comment_num", :comment_num then @comment_num = param.to_i
207
+ when "last_res_body", :last_res_body then @last_res_body = param.to_s
208
+ when "watch_url", :watch_url then @watch_url = param.to_s
209
+ when "thumb_type", :thumb_type then @thumb_type = param.to_s
210
+ when "embeddable", :embeddable then @embeddable = param.to_i
211
+ when "no_live_play", :no_live_play then @no_live_play = param.to_i
212
+ when "tags_jp", :tags_jp then @tags_jp = param
213
+ when "tags_tw", :tags_tw then @tags_tw = param
214
+ when "tags_de", :tags_de then @tags_de = param
215
+ when "tags_es", :tags_es then @tags_sp = param
216
+ when "user_id", :user_id then @user_id = param.to_i
256
217
  end
257
218
  }
258
219
  end
@@ -275,7 +236,7 @@ module Nicos
275
236
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
276
237
  # {Nicos::Movie#getInfo Mylist::getInfo}
277
238
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
278
- attr_accessor :video_id
239
+ attr_accessor :video_id
279
240
 
280
241
  # この動画が属するマイリストのID
281
242
  #
@@ -285,7 +246,7 @@ module Nicos
285
246
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
286
247
  # {Nicos::Movie#getInfo Mylist::getInfo}
287
248
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
288
- attr_accessor :mylist_id
249
+ attr_accessor :mylist_id
289
250
 
290
251
  # 動画に与えられるもう一つの一意なIDであり、投稿日時と同じか非常に近いUNIX時間になっている。
291
252
  #
@@ -297,7 +258,7 @@ module Nicos
297
258
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
298
259
  # {Nicos::Movie#getInfo Mylist::getInfo}
299
260
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
300
- attr_accessor :item_id
261
+ attr_accessor :item_id
301
262
 
302
263
  # 投稿者が記述した動画の説明文
303
264
  #
@@ -307,7 +268,7 @@ module Nicos
307
268
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
308
269
  # {Nicos::Movie#getInfo Mylist::getInfo}
309
270
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
310
- attr_accessor :description
271
+ attr_accessor :description
311
272
 
312
273
  # 動画のタイトル
313
274
  #
@@ -317,7 +278,7 @@ module Nicos
317
278
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
318
279
  # {Nicos::Movie#getInfo Mylist::getInfo}
319
280
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
320
- attr_accessor :title
281
+ attr_accessor :title
321
282
 
322
283
  # サムネイルのURL
323
284
  #
@@ -327,7 +288,7 @@ module Nicos
327
288
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
328
289
  # {Nicos::Movie#getInfo Mylist::getInfo}
329
290
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
330
- attr_accessor :thumbnail_url
291
+ attr_accessor :thumbnail_url
331
292
 
332
293
  # 動画の投稿日
333
294
  #
@@ -337,7 +298,7 @@ module Nicos
337
298
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
338
299
  # {Nicos::Movie#getInfo Mylist::getInfo}
339
300
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
340
- attr_accessor :first_retrieve
301
+ attr_accessor :first_retrieve
341
302
 
342
303
  # 取得時の再生数
343
304
  #
@@ -347,7 +308,7 @@ module Nicos
347
308
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
348
309
  # {Nicos::Movie#getInfo Mylist::getInfo}
349
310
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
350
- attr_accessor :view_counter
311
+ attr_accessor :view_counter
351
312
 
352
313
  # 取得時のマイリスト数
353
314
  #
@@ -357,7 +318,7 @@ module Nicos
357
318
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
358
319
  # {Nicos::Movie#getInfo Mylist::getInfo}
359
320
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
360
- attr_accessor :mylist_counter
321
+ attr_accessor :mylist_counter
361
322
 
362
323
  # 取得時のコメント数
363
324
  #
@@ -367,7 +328,7 @@ module Nicos
367
328
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
368
329
  # {Nicos::Movie#getInfo Mylist::getInfo}
369
330
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
370
- attr_accessor :comment_num
331
+ attr_accessor :comment_num
371
332
 
372
333
  # 動画の長さ(秒)
373
334
  #
@@ -377,7 +338,7 @@ module Nicos
377
338
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
378
339
  # {Nicos::Movie#getInfo Mylist::getInfo}
379
340
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
380
- attr_accessor :length
341
+ attr_accessor :length
381
342
 
382
343
  # 削除されたかどうか。削除済みの場合は1、そうでなければ0。
383
344
  #
@@ -387,7 +348,7 @@ module Nicos
387
348
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
388
349
  # {Nicos::Movie#getInfo Mylist::getInfo}
389
350
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
390
- attr_accessor :deleted
351
+ attr_accessor :deleted
391
352
 
392
353
  # 最新のコメント
393
354
  #
@@ -397,7 +358,7 @@ module Nicos
397
358
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
398
359
  # {Nicos::Movie#getInfo Mylist::getInfo}
399
360
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
400
- attr_accessor :last_res_body
361
+ attr_accessor :last_res_body
401
362
 
402
363
  # ?
403
364
  #
@@ -407,7 +368,7 @@ module Nicos
407
368
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
408
369
  # {Nicos::Movie#getInfo Mylist::getInfo}
409
370
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
410
- attr_accessor :watch
371
+ attr_accessor :watch
411
372
 
412
373
  # 動画の投稿日に近いが、若干こちらの方が遅い。詳細不明。
413
374
  #
@@ -417,7 +378,7 @@ module Nicos
417
378
  # <b>取得可能なメソッド</b>
418
379
  # {Nicos::Movie#getInfo Mylist::getInfo}
419
380
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
420
- attr_accessor :create_time
381
+ attr_accessor :create_time
421
382
 
422
383
  # 動画の更新日?
423
384
  #
@@ -448,35 +409,35 @@ module Nicos
448
409
  # @return [String]
449
410
  # <b>取得可能なメソッド</b>
450
411
  # {Nicos::Movie#getInfo Movie::getInfo}
451
- attr_accessor :movie_type
412
+ attr_accessor :movie_type
452
413
 
453
414
  # 高画質時の動画サイズ?
454
415
  #
455
416
  # @return [Fixnum]
456
417
  # <b>取得可能なメソッド</b>
457
418
  # {Nicos::Movie#getInfo Movie::getInfo}
458
- attr_accessor :size_high
419
+ attr_accessor :size_high
459
420
 
460
421
  # 低画質時の動画サイズ?
461
422
  #
462
423
  # @return [Fixnum]
463
424
  # <b>取得可能なメソッド</b>
464
425
  # {Nicos::Movie#getInfo Movie::getInfo}
465
- attr_accessor :size_low
426
+ attr_accessor :size_low
466
427
 
467
428
  # 動画の閲覧URL
468
429
  #
469
430
  # @return [String]
470
431
  # <b>取得可能なメソッド</b>
471
432
  # {Nicos::Movie#getInfo Movie::getInfo}
472
- attr_accessor :watch_url
433
+ attr_accessor :watch_url
473
434
 
474
435
  # ?
475
436
  #
476
437
  # @return [String]
477
438
  # <b>取得可能なメソッド</b>
478
439
  # {Nicos::Movie#getInfo Movie::getInfo}
479
- attr_accessor :thumb_type
440
+ attr_accessor :thumb_type
480
441
 
481
442
  # ブログ等に埋め込み、ログインなしでも閲覧できるかどうか。可能なら1。
482
443
  #
@@ -499,14 +460,14 @@ module Nicos
499
460
  # <b>取得可能なメソッド</b>
500
461
  # {Nicos::Movie#getInfo Movie::getInfo}
501
462
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
502
- attr_accessor :tags_jp
463
+ attr_accessor :tags_jp
503
464
 
504
465
  # 台湾タグ
505
466
  #
506
467
  # @return [Array<String>]
507
468
  # <b>取得可能なメソッド</b>
508
469
  # {Nicos::Movie#getInfo Movie::getInfo}
509
- attr_accessor :tags_tw
470
+ attr_accessor :tags_tw
510
471
 
511
472
  # ユーザID
512
473
  #
@@ -514,7 +475,7 @@ module Nicos
514
475
  # <b>取得可能なメソッド</b>
515
476
  # {Nicos::Movie#getInfo Movie::getInfo}
516
477
  # {Nicos::Movie#getInfo Movie::getHtmlInfo}
517
- attr_accessor :user_id
478
+ attr_accessor :user_id
518
479
  end
519
480
  end
520
481
 
@@ -2,7 +2,6 @@
2
2
  $:.unshift File.dirname(__FILE__)
3
3
 
4
4
  require 'rubygems'
5
- require 'ruby-debug'
6
5
  require 'kconv'
7
6
 
8
7
  require 'parser.rb'
@@ -17,7 +16,7 @@ module Nicos
17
16
  @movies = []
18
17
  @available = false
19
18
  end
20
-
19
+
21
20
  # 自分に含まれている動画のタイトルをすべての組み合わせにおいて比較し、
22
21
  # 類似度の平均を返す。
23
22
  #
@@ -59,159 +58,152 @@ module Nicos
59
58
  return similarity
60
59
  end
61
60
 
62
- # 自分に含まれている動画のタイトルをすべての組み合わせにおいて比較し、
63
- def getInfoHtml
64
- con = Nicos::Connector::Html.new('mech')
65
- reqUrl = 'http://www.nicovideo.jp' +
66
- '/mylist/' + @mylist_id.to_s
67
- mechPage = con.mechGet(reqUrl)
68
- result = []
61
+ =begin
62
+ # 自分に含まれている動画のタイトルをすべての組み合わせにおいて比較し、
63
+ def getInfoHtml
64
+ con = Nicos::Connector::Html.new('mech')
65
+ reqUrl = 'http://www.nicovideo.jp' +
66
+ '/mylist/' + @mylist_id.to_s
67
+ mechPage = con.mechGet(reqUrl)
68
+ result = []
69
69
 
70
- # Mylist自身の情報を取得
71
- jsonStr = mechPage.search(
72
- "/html/body/div[2]" +
73
- "/div/div[2]/script[7]"
74
- ).to_html
75
-
76
- reg = /MylistGroup\.preloadSingle.{1,}?Mylist\.preload\(/m
77
- mlJson = jsonStr.scan(reg)[0]
78
-
79
- id = mlJson.scan(/\sid:[^\n]{1,}/)[0]
80
- .scan(/[0-9]{1,}/)[0]
81
- user_id = mlJson.scan(/\suser_id:[^\n]{1,}/)[0]
82
- .scan(/[0-9]{1,}/)[0]
83
- name = mlJson.scan(/\sname:[^\n]{1,}/)[0]
84
- name = name.slice(
85
- " name: \"".length,
86
- name.length - " name: \"".length - "\",\n".length
87
- )
88
- desc = mlJson.scan(/\sdescription:.{1,}/)[0]
89
- desc = desc.slice(
90
- " description: \"".length,
91
- desc.length - " description: \"".length - "\",\npublic".length
92
- )
93
- public = mlJson.scan(/\spublic:[^,]{1,}/)[0]
94
- .scan(/[0-9]{1,}/)[0]
95
- default_sort = mlJson.scan(/\sdefault_sort:[^\n]{1,}/)[0]
96
- .scan(/[0-9]{1,}/)[0]
97
- create_time = mlJson.scan(/\screate_time:[^\n]{1,}/)[0]
98
- .scan(/[0-9]{1,}/)[0]
99
- update_time = mlJson.scan(/\supdate_time:[^\n]{1,}/)[0]
100
- .scan(/[0-9]{1,}/)[0]
101
- icon_id = mlJson.scan(/\sicon_id:[^\n]{1,}/)[0]
102
- .scan(/[0-9]{1,}/)[0]
103
-
104
- # mlJson = mlJson.scan(/[^\r\n ]{1,}/).join('')
105
- #mlJson = mlJson.scan(/{.+/)[0].split(',')
106
-
107
- # 説明文が空欄だった時の措置。
108
- desc = mlJson[3].scan(/\".+\"/)[0]
109
- if desc != nil then desc = desc.scan(/[^\"]{1,}/)[0] end
70
+ # Mylist自身の情報を取得
71
+ jsonStr = mechPage.search(
72
+ "/html/body/div[2]" +
73
+ "/div/div[2]/script[7]"
74
+ ).to_html
75
+
76
+ reg = /MylistGroup\.preloadSingle.{1,}?Mylist\.preload\(/m
77
+ mlJson = jsonStr.scan(reg)[0]
78
+
79
+ id = mlJson.scan(/\sid:[^\n]{1,}/)[0]
80
+ .scan(/[0-9]{1,}/)[0]
81
+ user_id = mlJson.scan(/\suser_id:[^\n]{1,}/)[0]
82
+ .scan(/[0-9]{1,}/)[0]
83
+ name = mlJson.scan(/\sname:[^\n]{1,}/)[0]
84
+ name = name.slice(
85
+ " name: \"".length,
86
+ name.length - " name: \"".length - "\",\n".length
87
+ )
88
+ desc = mlJson.scan(/\sdescription:.{1,}/)[0]
89
+ desc = desc.slice(
90
+ " description: \"".length,
91
+ desc.length - " description: \"".length - "\",\npublic".length
92
+ )
93
+ public = mlJson.scan(/\spublic:[^,]{1,}/)[0]
94
+ .scan(/[0-9]{1,}/)[0]
95
+ default_sort = mlJson.scan(/\sdefault_sort:[^\n]{1,}/)[0]
96
+ .scan(/[0-9]{1,}/)[0]
97
+ create_time = mlJson.scan(/\screate_time:[^\n]{1,}/)[0]
98
+ .scan(/[0-9]{1,}/)[0]
99
+ update_time = mlJson.scan(/\supdate_time:[^\n]{1,}/)[0]
100
+ .scan(/[0-9]{1,}/)[0]
101
+ icon_id = mlJson.scan(/\sicon_id:[^\n]{1,}/)[0]
102
+ .scan(/[0-9]{1,}/)[0]
110
103
 
111
- paramObj = {
112
- "id" => id,
113
- "user_id" => user_id,
114
- "name" => name,
115
- "description" => description,
116
- "public" => public,
117
- "default_sort" => default_sort,
118
- "create_time" => create_time,
119
- "update_time" => update_time,
120
- "icon_id" => icon_id
121
- # "sort_order" => ,
122
- }
123
- set(paramObj)
124
-
125
- # 自分に含まれる動画の情報を取得
126
- jsonStr = mechPage.search(
127
- "/html/body/div[2]" +
128
- "/div/div[2]/script[7]"
129
- ).to_html
104
+ # mlJson = mlJson.scan(/[^\r\n ]{1,}/).join('')
105
+ #mlJson = mlJson.scan(/{.+/)[0].split(',')
106
+
107
+ # 説明文が空欄だった時の措置。
108
+ desc = mlJson[3].scan(/\".+\"/)[0]
109
+ if desc != nil then desc = desc.scan(/[^\"]{1,}/)[0] end
130
110
 
131
- mvJson = jsonStr.scan(/Mylist.preload.+/)[0]
132
- mvJson = mvJson.scan(/\".{1,}/)[0]
133
- mvJson = mvJson.slice(0, mvJson.length - 5)
134
- #mvJson = mvJson.split('},{')
135
- mvJson = Nicos::Unicode.unescape(mvJson).split('},{')
136
-
137
- mvJson.each { |e|
138
- e = "{" + e + "}"
139
- param = JSON.parse(e)
140
- movie = Nicos::Movie.new(param['item_data']['video_id'])
141
- movie.set(param)
142
-
143
- @movies.push(movie)
144
- }
145
- end
111
+ paramObj = {
112
+ :id => id,
113
+ :user_id => user_id,
114
+ :name => name,
115
+ :description => description,
116
+ :public => public,
117
+ :default_sort => default_sort,
118
+ :create_time => create_time,
119
+ :update_time => update_time,
120
+ :icon_id => icon_id
121
+ # "sort_order" => ,
122
+ }
123
+ set(paramObj)
124
+
125
+ # 自分に含まれる動画の情報を取得
126
+ jsonStr = mechPage.search(
127
+ "/html/body/div[2]" +
128
+ "/div/div[2]/script[7]"
129
+ ).to_html
130
+
131
+ mvJson = jsonStr.scan(/Mylist.preload.+/)[0]
132
+ mvJson = mvJson.scan(/\".{1,}/)[0]
133
+ mvJson = mvJson.slice(0, mvJson.length - 5)
134
+ #mvJson = mvJson.split('},{')
135
+ mvJson = Nicos::Unicode.unescape(mvJson).split('},{')
136
+
137
+ mvJson.each { |e|
138
+ e = "{" + e + "}"
139
+ param = JSON.parse(e)
140
+ movie = Nicos::Movie.new(param['item_data']['video_id'])
141
+ movie.set(param)
142
+
143
+ @movies.push(movie)
144
+ }
145
+ end
146
+ =end
146
147
 
147
148
  # マイリストのAtomフィードから、マイリストとそれに含まれる動画の情報を取得する。
148
149
  #
149
150
  # @return [Fixnum] 編集距離に基づく類似度。上限は1、下限はなし。
150
151
  def getInfo
152
+ parsed = nil
153
+ @available = false
154
+
151
155
  con = Nicos::Connector::MylistAtom.new()
152
156
  host = 'www.nicovideo.jp'
153
- puts @mylist_id
154
157
  entity = '/mylist/' + @mylist_id.to_s + '?rss=atom&numbers=1'
158
+
155
159
  result = con.get(host, entity)
156
-
157
- if result["order"] == "afterTheSuccess"
158
- parsed = Nicos::Parser::mylistAtom(result["body"])
160
+ status = con.getStatus
161
+
162
+ if result[:order] == :afterTheSuccess
163
+ parsed = Nicos::Parser::mylistAtom(result[:body])
159
164
 
160
- parsed["entry"].each { |e|
161
- movie = Nicos::Movie.new(e["video_id"])
162
- e["available"] = true
165
+ parsed[:entry].each { |e|
166
+ movie = Nicos::Movie.new(e[:video_id])
167
+ e[:available] = true
163
168
  movie.set(e)
164
169
  @movies.push(movie)
165
170
  }
166
171
 
172
+ set(parsed[:mylist])
167
173
  @available = true
168
- set(parsed["mylist"])
169
- else
170
- @available = false
171
174
  end
175
+
176
+ {
177
+ :parsed => parsed,
178
+ :status => status[:status],
179
+ :retry => status[:retry]
180
+ }
172
181
  end
173
182
 
174
183
  # {Movie#set} を参照。
175
184
  def set(paramObj)
176
- paramObj.each_key { |key|
185
+ paramObj.each_key do |key|
177
186
  param = paramObj[key]
178
187
  case key
179
- when "mylist_id"
180
- @mylist_id = param
181
- when "id"
182
- @mylist_id = param
183
- when "user_id"
184
- @user_id = param
185
- when "title"
186
- @title = param
187
- when "description"
188
- @description = param
189
- when "public"
190
- @public = param
191
- when "default_sort"
192
- @default_sort = param
193
- when "create_time"
194
- @create_time = param
195
- when "update_time"
196
- @update_time = param
197
- when "icon_id"
198
- @icon_id = param
199
- when "sort_order"
200
- @sort_order = param
201
- when "movies"
202
- @movies = param
203
-
204
- when "updated"
205
- @update_time = param
206
- when "author"
207
- @author = param
188
+ when "mylist_id", :mylist_id then @mylist_id = param
189
+ when "user_id", :user_id then @user_id = param
190
+ when "title", :title then @title = param
191
+ when "description",:description then @description = param
192
+ when "public", :public then @public = param
193
+ when "default_sort",:default_sort then @default_sort = param
194
+ when "create_time",:create_time then @create_time = param
195
+ when "update_time",:updated_time then @update_time = param
196
+ when "icon_id", :icon_id then @icon_id = param
197
+ when "sort_order", :sort_order then @sort_order = param
198
+ when "movies", :movies then @movies = param
199
+ when "updated", :updated then @update_time = param
200
+ when "author", :author then @author = param
208
201
  end
209
- }
202
+ end
210
203
  end
211
204
 
212
205
  include Nicos::Connector::SetWait
213
206
 
214
-
215
207
  # このインスタンスがgetInfo等によって正常に情報を取得できている場合、trueとなる。
216
208
  # 各種メソッドの実行には、これがtrueであることが要求される。
217
209
  #
@@ -231,23 +223,23 @@ module Nicos
231
223
  # @return [Fixnum]
232
224
  # <b>取得可能なメソッド</b>
233
225
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
234
- attr_accessor :user_id
226
+ attr_accessor :user_id
235
227
 
236
228
  # マイリストのタイトル
237
229
  #
238
- # @return [Fixnum]
230
+ # @return [String]
239
231
  # <b>取得可能なメソッド</b>
240
232
  # {Nicos::Movie#getInfo Mylist::getInfo}
241
233
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
242
- attr_accessor :title
234
+ attr_accessor :title
243
235
 
244
236
  # マイリストの説明文
245
237
  #
246
- # @return [Fixnum]
238
+ # @return [String]
247
239
  # <b>取得可能なメソッド</b>
248
240
  # {Nicos::Movie#getInfo Mylist::getInfo}
249
241
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
250
- attr_accessor :description
242
+ attr_accessor :description
251
243
 
252
244
  # 公開設定
253
245
  #
@@ -256,7 +248,7 @@ module Nicos
256
248
  # <b>取得可能なメソッド</b>
257
249
  # {Nicos::Movie#getInfo Mylist::getInfo}
258
250
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
259
- attr_accessor :public
251
+ attr_accessor :public
260
252
 
261
253
  # ソート順の設定
262
254
  #
@@ -265,7 +257,7 @@ module Nicos
265
257
  # <b>取得可能なメソッド</b>
266
258
  # {Nicos::Movie#getInfo Mylist::getInfo}
267
259
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
268
- attr_accessor :default_sort
260
+ attr_accessor :default_sort
269
261
 
270
262
  # マイリスト作成日時
271
263
  #
@@ -273,7 +265,7 @@ module Nicos
273
265
  # <b>取得可能なメソッド</b>
274
266
  # {Nicos::Movie#getInfo Mylist::getInfo}
275
267
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
276
- attr_accessor :create_time
268
+ attr_accessor :create_time
277
269
 
278
270
  # マイリストの更新日時
279
271
  #
@@ -281,7 +273,7 @@ module Nicos
281
273
  # <b>取得可能なメソッド</b>
282
274
  # {Nicos::Movie#getInfo Mylist::getInfo}
283
275
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
284
- attr_accessor :update_time
276
+ attr_accessor :update_time
285
277
 
286
278
  # アイコンの色?
287
279
  #
@@ -289,7 +281,7 @@ module Nicos
289
281
  # <b>取得可能なメソッド</b>
290
282
  # {Nicos::Movie#getInfo Mylist::getInfo}
291
283
  # {Nicos::Movie#getInfo Mylist::getHtmlInfo}
292
- attr_accessor :icon_id
284
+ attr_accessor :icon_id
293
285
 
294
286
  # 現在のソート順
295
287
  #
@@ -301,7 +293,7 @@ module Nicos
301
293
 
302
294
  # 作成者の名前
303
295
  #
304
- # @return [Fixnum]
296
+ # @return [String]
305
297
  # <b>取得可能なメソッド</b>
306
298
  # {Nicos::Movie#getInfo Mylist::getInfo}
307
299
  attr_accessor :author