narou 2.9.5 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of narou might be problematic. Click here for more details.

Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -0
  3. data/.reek +34 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +9 -1
  6. data/ChangeLog.md +90 -0
  7. data/Gemfile +4 -0
  8. data/README.md +85 -8
  9. data/lib/command/convert.rb +1 -1
  10. data/lib/command/list.rb +59 -73
  11. data/lib/command/list/novel_decorator.rb +107 -0
  12. data/lib/command/send.rb +23 -13
  13. data/lib/command/setting.rb +5 -1
  14. data/lib/command/update.rb +104 -138
  15. data/lib/command/update/general_lastup_updater.rb +105 -0
  16. data/lib/command/update/interval.rb +29 -0
  17. data/lib/command/web.rb +1 -1
  18. data/lib/commandbase.rb +24 -17
  19. data/lib/converterbase.rb +10 -5
  20. data/lib/database.rb +16 -5
  21. data/lib/device.rb +5 -1
  22. data/lib/device/library/linux.rb +68 -8
  23. data/lib/downloader.rb +24 -23
  24. data/lib/extension.rb +16 -3
  25. data/lib/helper.rb +26 -3
  26. data/lib/html.rb +1 -1
  27. data/lib/inspector.rb +9 -0
  28. data/lib/inventory.rb +20 -6
  29. data/lib/logger.rb +8 -2
  30. data/lib/mailer.rb +2 -1
  31. data/lib/narou.rb +28 -18
  32. data/lib/narou/api.rb +62 -31
  33. data/lib/novelconverter.rb +8 -1
  34. data/lib/novelinfo.rb +8 -7
  35. data/lib/novelsetting.rb +1 -0
  36. data/lib/progressbar.rb +6 -2
  37. data/lib/sitesetting.rb +2 -1
  38. data/lib/version.rb +1 -1
  39. data/lib/web/appserver.rb +72 -9
  40. data/lib/web/public/resources/narou.library.js +130 -13
  41. data/lib/web/public/resources/narou.ui.js +96 -9
  42. data/lib/web/settingmessages.rb +2 -1
  43. data/lib/web/views/_about.haml +15 -2
  44. data/lib/web/views/index.haml +12 -3
  45. data/lib/web/views/layout.haml +2 -1
  46. data/lib/web/views/style.scss +12 -0
  47. data/narou.gemspec +88 -11
  48. data/narou.rb +7 -1
  49. data/preset/mail_setting.yaml +40 -6
  50. data/webnovel/kakuyomu.jp.yaml +8 -8
  51. metadata +95 -139
  52. data/spec/README.txt +0 -4
  53. data/spec/convert_spec.rb +0 -119
  54. data/spec/converterbase_spec.rb +0 -298
  55. data/spec/data/convert_test/auto_indent/correct_test_auto_indent.txt +0 -28
  56. data/spec/data/convert_test/auto_indent/test_auto_indent.txt +0 -32
  57. data/spec/data/convert_test/auto_join_bracket/correct_test_auto_join_bracket.txt +0 -24
  58. data/spec/data/convert_test/auto_join_bracket/test_auto_join_bracket.txt +0 -28
  59. data/spec/data/convert_test/auto_join_line/correct_test_auto_join_line.txt +0 -43
  60. data/spec/data/convert_test/auto_join_line/test_auto_join_line.txt +0 -59
  61. data/spec/data/convert_test/convert_page_break/correct_test_convert_page_break.txt +0 -22
  62. data/spec/data/convert_test/convert_page_break/setting.ini +0 -5
  63. data/spec/data/convert_test/convert_page_break/test_convert_page_break.txt +0 -60
  64. data/spec/data/convert_test/double_dash_to_image/correct_test_double_dash_to_image.txt +0 -14
  65. data/spec/data/convert_test/double_dash_to_image/setting.ini +0 -1
  66. data/spec/data/convert_test/double_dash_to_image/test_double_dash_to_image.txt +0 -12
  67. data/spec/data/convert_test/english/correct_test_english.txt +0 -27
  68. data/spec/data/convert_test/english/test_english.txt +0 -27
  69. data/spec/data/convert_test/force_indent_special_chapter/correct_test_force_indent_special_chapter.txt +0 -64
  70. data/spec/data/convert_test/force_indent_special_chapter/test_force_indent_special_chapter.txt +0 -61
  71. data/spec/data/convert_test/horizontal_ellipsis/correct_test_horizontal_ellipsis.txt +0 -53
  72. data/spec/data/convert_test/horizontal_ellipsis/test_horizontal_ellipsis.txt +0 -57
  73. data/spec/data/convert_test/insert_separator/correct_test_insert_separator.txt +0 -13
  74. data/spec/data/convert_test/insert_separator/setting.ini +0 -3
  75. data/spec/data/convert_test/insert_separator/test_insert_separator.txt +0 -12
  76. data/spec/data/convert_test/insert_separator_and_replace_txt/correct_test_insert_separator_and_replace_txt.txt +0 -12
  77. data/spec/data/convert_test/insert_separator_and_replace_txt/setting.ini +0 -3
  78. data/spec/data/convert_test/insert_separator_and_replace_txt/test_insert_separator_and_replace_txt.txt +0 -11
  79. data/spec/data/convert_test/kanji_num/correct_test_kanji_num.txt +0 -50
  80. data/spec/data/convert_test/kanji_num/test_kanji_num.txt +0 -56
  81. data/spec/data/convert_test/nonokagi/correct_test_nonokagi.txt +0 -30
  82. data/spec/data/convert_test/nonokagi/test_nonokagi.txt +0 -34
  83. data/spec/data/convert_test/replace/correct_test_replace.txt +0 -13
  84. data/spec/data/convert_test/replace/test_replace.txt +0 -14
  85. data/spec/data/convert_test/ruby/correct_test_ruby.txt +0 -161
  86. data/spec/data/convert_test/ruby/test_ruby.txt +0 -205
  87. data/spec/data/convert_test/ruby_youon/correct_test_ruby_youon.txt +0 -13
  88. data/spec/data/convert_test/ruby_youon/setting.ini +0 -2
  89. data/spec/data/convert_test/ruby_youon/test_ruby_youon.txt +0 -14
  90. data/spec/data/convert_test/sesame/correct_test_sesame.txt +0 -41
  91. data/spec/data/convert_test/sesame/test_sesame.txt +0 -52
  92. data/spec/data/convert_test/to_odd_leader/correct_test_to_odd_leader.txt +0 -21
  93. data/spec/data/convert_test/to_odd_leader/test_to_odd_leader.txt +0 -21
  94. data/spec/data/html_test.html +0 -5
  95. data/spec/data/html_test.txt +0 -4
  96. data/spec/data/test.ini +0 -10
  97. data/spec/device_spec.rb +0 -39
  98. data/spec/downloader_spec.rb +0 -37
  99. data/spec/eventable_spec.rb +0 -172
  100. data/spec/exit_code_spec.rb +0 -67
  101. data/spec/generator/convert_spec_gen.rb +0 -96
  102. data/spec/generator/num_to_kanji_test_gen.rb +0 -33
  103. data/spec/helper_spec.rb +0 -90
  104. data/spec/html_spec.rb +0 -83
  105. data/spec/ini_spec.rb +0 -145
  106. data/spec/input_spec.rb +0 -76
  107. data/spec/logger_spec.rb +0 -92
  108. data/spec/novelinfo_spec.rb +0 -15
  109. data/spec/novelsetting_spec.rb +0 -35
  110. data/spec/num_to_kanji_spec.rb +0 -2482
  111. data/spec/spec_helper.rb +0 -16
  112. data/spec/worker_spec.rb +0 -75
@@ -0,0 +1,107 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright 2013 whiteleaf. All rights reserved.
4
+ #
5
+
6
+ module Command
7
+ class List < CommandBase
8
+ class NovelDecorator
9
+ attr_accessor(*%i(id frozen novel_type novel options parent))
10
+
11
+ def initialize(novel, parent)
12
+ self.id = novel["id"]
13
+ self.frozen = Narou.novel_frozen?(id)
14
+ self.novel_type = novel["novel_type"].to_i
15
+ self.novel = novel
16
+ self.options = parent.options
17
+ self.parent = parent
18
+ end
19
+
20
+ def decorate_id
21
+ disp_id = ((frozen ? "*" : "") + id.to_s).rjust(4)
22
+ if frozen
23
+ disp_id.sub("*", "<bold><cyan>*</cyan></bold>")
24
+ else
25
+ disp_id
26
+ end
27
+ end
28
+
29
+ def decorate_date
30
+ date = novel[parent.view_date_type].strftime("%y/%m/%d")
31
+ new_arrivals_date = novel["new_arrivals_date"]
32
+ last_update = novel["last_update"]
33
+ if new_arrivals_date && new_arrivals_date >= last_update &&
34
+ new_arrivals_date + ANNOTATION_COLOR_TIME_LIMIT >= now
35
+ # 新着表示色
36
+ "<bold><magenta>#{date}</magenta></bold>"
37
+ elsif last_update + ANNOTATION_COLOR_TIME_LIMIT >= now
38
+ # 更新だけあった色
39
+ "<bold><green>#{date}</green></bold>"
40
+ else
41
+ date
42
+ end
43
+ end
44
+
45
+ def decorate_kind
46
+ options["kind"] ? NOVEL_TYPE_LABEL[novel_type] : nil
47
+ end
48
+
49
+ def decorate_author
50
+ options["author"] ? novel["author"].escape : nil
51
+ end
52
+
53
+ def decorate_site
54
+ options["site"] ? novel["sitename"].escape : nil
55
+ end
56
+
57
+ def decorate_title
58
+ if !options["kind"] && novel_type == 2
59
+ type = " <bold><black>(#{NOVEL_TYPE_LABEL[novel_type]})</black></bold>"
60
+ end
61
+ the_end = "<bold><black>(完結)</black></bold>" if tags.include?("end")
62
+ delete = "<bold><black>(削除)</black></bold>" if tags.include?("404")
63
+ [
64
+ novel["title"].escape,
65
+ type,
66
+ the_end,
67
+ delete
68
+ ].compact.join(" ")
69
+ end
70
+
71
+ def decorate_url
72
+ options["url"] ? novel["toc_url"].escape : nil
73
+ end
74
+
75
+ def decorate_tags
76
+ return nil unless options["tags"] || options["all-tags"]
77
+ tags.empty? ? nil : tags.map { |tag|
78
+ color = Tag.get_color(tag)
79
+ "<bold><#{color}>#{tag.escape}</#{color}></bold>"
80
+ }.join(",")
81
+ end
82
+
83
+ def decorate_line
84
+ [
85
+ decorate_id,
86
+ decorate_date,
87
+ decorate_kind,
88
+ decorate_author,
89
+ decorate_site,
90
+ decorate_title,
91
+ decorate_url,
92
+ decorate_tags
93
+ ].compact.join(" | ")
94
+ end
95
+
96
+ private
97
+
98
+ def tags
99
+ @__tags ||= novel["tags"] || []
100
+ end
101
+
102
+ def now
103
+ parent.now
104
+ end
105
+ end
106
+ end
107
+ end
@@ -21,7 +21,8 @@ module Command
21
21
  ・<device>には現在 #{Device::DEVICES.keys.join(", ")} が指定出来ます
22
22
  ・narou setting device=<device>としておけば、<device>の入力を省略できます
23
23
  また、convertコマンドで変換時に(端末がPCに接続されていれば)自動でデータを送信するようになります
24
- ・<target>を省略した場合、管理している小説全てのファイルのタイムスタンプを端末のものと比べて新しければ送信します
24
+ ・送信時はファイルのタイムスタンプを端末のものと比べて新しければ送信します
25
+ ・<target>を省略した場合、管理している小説全てが送信対象になります
25
26
  ・<target>にhotentryを指定した場合、最新のhotnetryを送信します
26
27
 
27
28
  Examples:
@@ -39,9 +40,12 @@ module Command
39
40
  Options:
40
41
  EOS
41
42
 
42
- @opt.on("--without-freeze", "一括送信時に凍結された小説は対象外にする") {
43
+ @opt.on("-w", "--without-freeze", "送信時に凍結された小説は対象外にする") {
43
44
  @options["without-freeze"] = true
44
45
  }
46
+ @opt.on("-f", "--force", "タイムスタンプを比較せずに必ず送信する") {
47
+ @options["force"] = true
48
+ }
45
49
  @opt.on("-b", "--backup-bookmark", "端末の栞データを手動でバックアップする(KindlePW系用)") {
46
50
  @options["command-backup-bookmark"] = true
47
51
  }
@@ -81,7 +85,6 @@ module Command
81
85
  if argv.empty?
82
86
  send_all = true
83
87
  Database.instance.each do |id, data|
84
- next if @options["without-freeze"] && Narou.novel_frozen?(id)
85
88
  argv << id
86
89
  titles[id] = data["title"]
87
90
  end
@@ -102,6 +105,13 @@ module Command
102
105
 
103
106
  tagname_to_ids(argv)
104
107
  argv.each do |target|
108
+ # WEB UI 使用時は、send.without-freeze を設定して使うことを想定していて、
109
+ # コマンドのようにオプションを付けたり外したりするのが容易ではないため、
110
+ # 個別送信時はオプションに関わらず凍結済みでも送信出来るようにする
111
+ if @options["without-freeze"] && Narou.novel_frozen?(target) &&
112
+ (!Narou.web? || (Narou.web? && send_all))
113
+ next
114
+ end
105
115
  if target == "hotentry"
106
116
  ebook_path = Update.get_newest_hotentry_file_path(device)
107
117
  else
@@ -115,18 +125,18 @@ module Command
115
125
  error "まだファイル(#{File.basename(ebook_path)})が無いようです" unless send_all
116
126
  next
117
127
  end
118
- if send_all
119
- if device.ebook_file_old?(ebook_path)
120
- if target == "hotentry"
121
- display_target = target
122
- else
123
- display_target = "ID:#{target} #{TermColorLight.escape(titles[target])}"
124
- end
125
- puts "<bold><green>#{display_target}</green></bold>".termcolor
128
+
129
+ if !@options["force"] && !device.ebook_file_old?(ebook_path)
130
+ next
131
+ end
132
+ display_target =
133
+ if target == "hotentry"
134
+ target
126
135
  else
127
- next
136
+ "ID:#{target} #{TermColorLight.escape(titles[target])}"
128
137
  end
129
- end
138
+ puts "<bold><green>#{display_target}</green></bold>".termcolor
139
+
130
140
  print "#{device.name}へ送信しています"
131
141
  exit_copy = false
132
142
  copy_to_path = nil
@@ -452,7 +452,7 @@ module Command
452
452
  tab: :detail
453
453
  },
454
454
  "send.without-freeze" => {
455
- type: :boolean, help: "一括送信時に凍結された小説は対象外にする",
455
+ type: :boolean, help: "送信時に凍結された小説は対象外にする",
456
456
  tab: :general
457
457
  },
458
458
  "send.backup-bookmark" => {
@@ -485,6 +485,10 @@ module Command
485
485
  select_summaries: Narou.get_theme_names,
486
486
  tab: :general
487
487
  },
488
+ "normalize-filename" => {
489
+ type: :boolean, help: "ファイル名の文字列をNFCで正規化する。※既存データとの互換性が無くなる可能性があるので、バックアップを取った上で機能を理解の上有効にして下さい",
490
+ tab: :detail,
491
+ },
488
492
  },
489
493
  global: {
490
494
  "aozoraepub3dir" => {
@@ -9,32 +9,13 @@ require_relative "../database"
9
9
  require_relative "../downloader"
10
10
  require_relative "../template"
11
11
  require_relative "../novelconverter"
12
+ require_relative "update/interval"
13
+ require_relative "update/general_lastup_updater"
12
14
 
13
15
  module Command
14
16
  class Update < CommandBase
15
17
  extend Memoist
16
18
 
17
- class Interval
18
- MIN = 2.5 # 作品間ウェイトの最低秒数(処理時間含む)
19
- FORCE_WAIT_TIME = 2.0 # 強制待機時間
20
-
21
- def initialize(interval)
22
- @time = Time.now - MIN
23
- interval = interval.to_f
24
- @interval_time = interval >= MIN ? interval : MIN
25
- end
26
-
27
- def wait
28
- wait_time = Time.now - @time
29
- sleep(@interval_time - wait_time) if wait_time < @interval_time
30
- @time = Time.now
31
- end
32
-
33
- def force_wait
34
- sleep(FORCE_WAIT_TIME)
35
- end
36
- end
37
-
38
19
  LOG_DIR_NAME = "log"
39
20
  LOG_NUM_LIMIT = 30 # ログの保存する上限数
40
21
  LOG_FILENAME_FORMAT = "update_log_%s.txt"
@@ -66,6 +47,13 @@ module Command
66
47
  narou update n9669bk 異世界迷宮で奴隷ハーレムを
67
48
  narou update http://ncode.syosetu.com/n9669bk/
68
49
 
50
+ # foo タグが付いた小説と bar タグが付いた小説を更新(タグのOR指定)
51
+ narou u foo bar
52
+
53
+ # foo タグ及び bar タグが両方付いた小説のみ更新(タグのAND指定)
54
+ narou tag foo bar | narou u
55
+ narou l -t "foo bar" | narou # こっちでも同じ(覚えやすい方を使う)
56
+
69
57
  Options:
70
58
  EOS
71
59
  @opt.on("-n", "--no-convert", "変換をせずアップデートのみ実行する") {
@@ -81,8 +69,18 @@ module Command
81
69
  view_log
82
70
  exit 0
83
71
  }
84
- @opt.on("--gl", "データベースに最新話掲載日を反映させる") {
85
- update_general_lastup
72
+ @opt.on("--gl [OPT]", <<-EOS) { |option|
73
+ データベースに最新話掲載日を反映させる
74
+ | OPT | 概要
75
+ | 指定なし | 全ての小説を対象にする
76
+ | narou | なろうAPIを使える小説のみ対象
77
+ | other | なろうAPIが使えない小説のみ対象
78
+ EOS
79
+ if option && !["narou", "other"].include?(option)
80
+ error "--gl で指定可能なオプションではありません。詳細は narou u -h を参照"
81
+ exit Narou::EXIT_ERROR_CODE
82
+ end
83
+ update_general_lastup(option)
86
84
  exit 0
87
85
  }
88
86
  @opt.on("-f", "--force", "凍結済みも更新する") {
@@ -91,6 +89,9 @@ module Command
91
89
  @opt.on("-s", "--sort-by KEY", "アップデートする順番を変更する\n#{Narou.update_sort_key_summaries}") { |key|
92
90
  @options["sort-by"] = key
93
91
  }
92
+ @opt.on("-i", "--ignore-all", "<target>を省略した場合の全件更新処理を無効化する") {
93
+ @options["ignore-all"] = true
94
+ }
94
95
  end
95
96
 
96
97
  def get_data_value(target, key)
@@ -131,15 +132,15 @@ module Command
131
132
  Narou::UPDATE_SORT_KEYS.keys.include?(key)
132
133
  end
133
134
 
135
+ # rubocop:disable Metrics/BlockLength
134
136
  def execute(argv)
135
137
  super
136
138
  mistook_count = 0
137
139
  update_target_list = argv.dup
138
140
  @options["no-open"] = false
139
141
  if update_target_list.empty?
140
- Database.instance.each_key do |id|
141
- update_target_list << id
142
- end
142
+ exit 0 if @options["ignore-all"]
143
+ update_target_list += Database.instance.get_object.keys
143
144
  @options["no-open"] = true
144
145
  end
145
146
  tagname_to_ids(update_target_list)
@@ -162,83 +163,90 @@ module Command
162
163
 
163
164
  interval = Interval.new(@options["interval"])
164
165
 
165
- update_log = $stdout.capture(quiet: false) do
166
- sort_by_key(sort_key, update_target_list).each_with_index do |target, i|
167
- display_message = nil
168
- data = Downloader.get_data_by_target(target)
169
- if !data
170
- display_message = "<bold><red>[ERROR]</red></bold> #{target} は管理小説の中に存在しません".termcolor
171
- elsif Narou.novel_frozen?(target) && !@options["force"]
172
- if argv.length > 0
166
+ begin
167
+ update_log = $stdout.capture(quiet: false) do
168
+ sort_by_key(sort_key, update_target_list).each_with_index do |target, i|
169
+ display_message = nil
170
+ data = Downloader.get_data_by_target(target)
171
+ if !data
172
+ display_message = "<bold><red>[ERROR]</red></bold> #{target} は管理小説の中に存在しません".termcolor
173
+ elsif Narou.novel_frozen?(target) && !@options["force"]
174
+ next if argv.empty?
173
175
  display_message = "ID:#{data["id"]} #{data["title"]} は凍結中です"
174
- else
176
+ end
177
+ Helper.print_horizontal_rule if i > 0
178
+ if display_message
179
+ puts display_message
180
+ mistook_count += 1
175
181
  next
176
182
  end
177
- end
178
- Helper.print_horizontal_rule if i > 0
179
- if display_message
180
- puts display_message
181
- mistook_count += 1
182
- next
183
- end
184
- interval.wait
185
- downloader = Downloader.new(target)
183
+ interval.wait
184
+ downloader = Downloader.new(target)
185
+
186
+ if @options["hotentry"]
187
+ downloader.on(:newarrival) do |hash|
188
+ entry = hotentry[hash[:id]] ||= []
189
+ entry << hash[:subtitle_info]
190
+ end
191
+ end
186
192
 
187
- if @options["hotentry"]
188
- downloader.on(:newarrival) do |hash|
189
- entry = hotentry[hash[:id]] ||= []
190
- entry << hash[:subtitle_info]
193
+ delete_modified_tag = -> do
194
+ tags = data["tags"] || []
195
+ data["tags"] = tags - [Narou::MODIFIED_TAG] if tags.include?(Narou::MODIFIED_TAG)
196
+ data["last_check_date"] = Time.now
191
197
  end
192
- end
193
198
 
194
- result = downloader.start_download
195
- case result.status
196
- when :ok
197
- if @options["no-convert"] ||
198
- (@options["convert-only-new-arrival"] && !result.new_arrivals)
199
- interval.force_wait
199
+ result = downloader.start_download
200
+ case result.status
201
+ when :ok
202
+ delete_modified_tag.call
203
+ if @options["no-convert"] ||
204
+ (@options["convert-only-new-arrival"] && !result.new_arrivals)
205
+ interval.force_wait
206
+ next
207
+ end
208
+ when :failed
209
+ puts "ID:#{data["id"]} #{data["title"]} の更新は失敗しました"
210
+ mistook_count += 1
211
+ next
212
+ when :canceled
213
+ puts "ID:#{data["id"]} #{data["title"]} の更新はキャンセルされました"
214
+ mistook_count += 1
200
215
  next
216
+ when :none
217
+ delete_modified_tag.call
218
+ puts "#{data["title"]} に更新はありません"
219
+ next unless data["_convert_failure"]
201
220
  end
202
- when :failed
203
- puts "ID:#{data["id"]} #{data["title"]} の更新は失敗しました"
204
- mistook_count += 1
205
- next
206
- when :canceled
207
- puts "ID:#{data["id"]} #{data["title"]} の更新はキャンセルされました"
208
- mistook_count += 1
209
- next
210
- when :none
211
- puts "#{data["title"]} に更新はありません"
212
- next unless data["_convert_failure"]
213
- end
214
221
 
215
- if data["_convert_failure"]
216
- puts "<yellow>前回変換できなかったので再変換します</yellow>".termcolor
217
- end
218
- convert_argv = [target]
219
- convert_argv << "--no-open" if @options["no-open"]
220
- convert_status = Convert.execute!(convert_argv)
221
- if convert_status > 0
222
- # 変換が失敗したか、中断された
223
- data["_convert_failure"] = true
224
- # 中断された場合には残りのアップデートも中止する
225
- raise Interrupt if convert_status == Narou::EXIT_INTERRUPT
226
- else
227
- # 変換に成功した
228
- data.delete("_convert_failure")
222
+ if data["_convert_failure"]
223
+ puts "<yellow>前回変換できなかったので再変換します</yellow>".termcolor
224
+ end
225
+ convert_argv = [target]
226
+ convert_argv << "--no-open" if @options["no-open"]
227
+ convert_status = Convert.execute!(convert_argv)
228
+ if convert_status > 0
229
+ # 変換が失敗したか、中断された
230
+ data["_convert_failure"] = true
231
+ # 中断された場合には残りのアップデートも中止する
232
+ raise Interrupt if convert_status == Narou::EXIT_INTERRUPT
233
+ else
234
+ # 変換に成功した
235
+ data.delete("_convert_failure")
236
+ end
229
237
  end
230
- end
231
238
 
232
- process_hotentry(hotentry)
239
+ process_hotentry(hotentry)
240
+ end
241
+ ensure
242
+ save_log(update_log)
243
+ Database.instance.save_database
233
244
  end
234
245
 
235
246
  exit mistook_count if mistook_count > 0
236
247
  rescue Interrupt
237
248
  puts "アップデートを中断しました"
238
249
  exit Narou::EXIT_INTERRUPT
239
- ensure
240
- save_log(update_log)
241
- Database.instance.save_database
242
250
  end
243
251
 
244
252
  def get_log_paths
@@ -284,60 +292,18 @@ module Command
284
292
  end
285
293
  end
286
294
 
287
- def update_general_lastup(through_frozen_novel: true)
288
- completed = false
289
- database = Database.instance
290
- puts "最新話掲載日を更新しています..."
291
- progressbar = ProgressBar.new(database.get_object.size - 1)
292
- interval = Interval.new(@options["interval"])
293
- database.each.with_index do |(id, data), i|
294
- progressbar.output(i)
295
- if through_frozen_novel
296
- next if Narou.novel_frozen?(id)
297
- end
298
- setting = Downloader.get_sitesetting_by_target(id)
299
- interval.wait
300
- begin
301
- info = NovelInfo.load(setting)
302
- rescue OpenURI::HTTPError, Errno::ECONNRESET => e
303
- setting.clear
304
- next
305
- end
306
- if info
307
- dates = {
308
- "general_firstup" => info["general_firstup"],
309
- "novelupdated_at" => info["novelupdated_at"],
310
- "general_lastup" => info["general_lastup"]
311
- }
312
- else
313
- # 小説情報ページがない場合は目次から取得する
314
- begin
315
- dates = get_latest_dates(id)
316
- rescue OpenURI::HTTPError, Errno::ECONNRESET => e
317
- setting.clear
318
- next
319
- end
320
- end
321
- database[id].merge!(dates)
322
- setting.clear
295
+ def update_general_lastup(option = nil)
296
+ puts "最新話掲載日を確認しています..."
297
+
298
+ updater = GeneralLastupUpdater.new(@options)
299
+ updater.update_narou_novels if !option || option == "narou"
300
+ if !option || option == "other"
301
+ sleep Narou::API::REQUEST_INTERVAL unless option
302
+ updater.update_other_novels
323
303
  end
324
- database.save_database
325
- completed = true
326
- ensure
327
- progressbar.clear if progressbar
328
- puts "更新が完了しました" if completed
329
- end
304
+ updater.save
330
305
 
331
- # オンラインの目次からgeneral_lastupを取得する
332
- # ただし、toc.yaml に最新話が存在し、かつsubdateが設定されていたらそれを使う
333
- def get_latest_dates(target)
334
- downloader = Downloader.new(target)
335
- old_toc = downloader.load_toc_file
336
- latest_toc = downloader.get_latest_table_of_contents(old_toc, through_error: true)
337
- {
338
- "novelupdated_at" => downloader.get_novelupdated_at,
339
- "general_lastup" => downloader.get_general_lastup
340
- }
306
+ puts "確認が完了しました"
341
307
  end
342
308
 
343
309
  #