narou 1.4.6 → 1.5.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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d079914379ec269516a611594fe4cebaadcea73
4
- data.tar.gz: de5f4483ab9aadf522695ad3380a763611d3668a
3
+ metadata.gz: bce2031dceba922fca9fc843088ff77c43ff0dd4
4
+ data.tar.gz: 501d6dac5cfa8c43d9304c8fd5e159a7bf12e15b
5
5
  SHA512:
6
- metadata.gz: 3239e1395b68e9f02b081900161b5043bb8add531dbf6a29e7c0db9b14aa741cf0ffb6f436b2e331446ac7e80ea917f5a0e86c0c5e37b527d7aa4592ddb9a21b
7
- data.tar.gz: 4e461284c9a64d97c94df6b793114faa33585d2f3ed52b2a01bfe50109ce85acddd84059cb5e3ff8cb51ba9976a1100767ead44aa250fe973dca338cd2ffe45e
6
+ metadata.gz: daef334a677d5781a3a6c1925510b7fcfe6f36fb17700d6b1948774c8db4f01474d6ab9dbe96abb2d91c30d3fc0eff1cf7cb7ae504f96a1fde05cee2c11bfc98
7
+ data.tar.gz: ae20ca9af18deb976959dba564a24640e3c4b90cc14962315ccd65446843d703c525155672add03546baa55a1704cdb0e6b5e7c50f2c52307d4da0da1d6cfd56
@@ -2,6 +2,20 @@
2
2
  更新履歴 - ChangeLog
3
3
  --------------------
4
4
 
5
+ 2014/03/06 : **1.5.0**
6
+ * 追加機能もしくは仕様変更
7
+ - 小説投稿サイト **[ハーメルン](http://syosetu.org/)** に対応しました
8
+ - 小説投稿サイト **[Arcadia](http://www.mai-net.net/)** に対応しました
9
+ + Arcadiaは `narou d "http://www.mai-net.net/bbs/sst/sst.php?~略~&n=0&count=1"` のように
10
+ URLを " で囲まないとコマンドがきちんと通りませんのでご注意下さい
11
+ - このバージョン以降ダウンロードした小説の保存フォルダ名には、タイトルの前にIDが付加されるようになりました
12
+ - アラビア数字を漢数字に変換しないパターンを追加(%や単位系)
13
+ - `setting.ini` の項目、 `enable_narou_illust` が `enable_illust` に変更になりました
14
+ * Bug Fix
15
+ - `narou browser --vote` コマンドがなろうのレイアウト変更に対応していなかったので修正
16
+ - 半角カナを全角カナに変換するように修正 #36
17
+ - 小説のタイトルにはルビをふれないように修正 #37
18
+
5
19
  2014/02/28 : **1.4.6**
6
20
  * 追加機能もしくは仕様変更
7
21
  - `narou diff` コマンドに(凍結済を除く)全ての小説の差分データを削除する `--all-clean` オプションが追加されました
@@ -17,7 +31,7 @@
17
31
  - 検索除外されている小説が全て短編小説と認識されてしまう問題を修正
18
32
  - WinMerge2.14で `narou diff` コマンドが使えなかった問題を修正
19
33
  - Ruby1.9.3で動かなくなっていたのを修正
20
- - issues #35 行頭に三点リーダーの代わりに連続中黒(・・・)が来た時自動字下げがされていなかったのを修正
34
+ - 行頭に三点リーダーの代わりに連続中黒(・・・)が来た時自動字下げがされていなかったのを修正 #35
21
35
  - 連続で小説をダウンロードする時に 503 エラーがでてしまう場合がある問題を修正
22
36
 
23
37
  2014/02/26 : **1.4.4**
data/README.md CHANGED
@@ -21,6 +21,20 @@ Narou.rb ― 「小説家になろう」「小説を読もう!」ダウンロ
21
21
  更新履歴 - ChangeLog
22
22
  --------------------
23
23
 
24
+ 2014/03/06 : **1.5.0**
25
+ * 追加機能もしくは仕様変更
26
+ - 小説投稿サイト **[ハーメルン](http://syosetu.org/)** に対応しました
27
+ - 小説投稿サイト **[Arcadia](http://www.mai-net.net/)** に対応しました
28
+ + Arcadiaは `narou d "http://www.mai-net.net/bbs/sst/sst.php?~略~&n=0&count=1"` のように
29
+ URLを " で囲まないとコマンドがきちんと通りませんのでご注意下さい
30
+ - このバージョン以降ダウンロードした小説の保存フォルダ名には、タイトルの前にIDが付加されるようになりました
31
+ - アラビア数字を漢数字に変換しないパターンを追加(%や単位系)
32
+ - `setting.ini` の項目、 `enable_narou_illust` が `enable_illust` に変更になりました
33
+ * Bug Fix
34
+ - `narou browser --vote` コマンドがなろうのレイアウト変更に対応していなかったので修正
35
+ - 半角カナを全角カナに変換するように修正 #36
36
+ - 小説のタイトルにはルビをふれないように修正 #37
37
+
24
38
  2014/02/28 : **1.4.6**
25
39
  * 追加機能もしくは仕様変更
26
40
  - `narou diff` コマンドに(凍結済を除く)全ての小説の差分データを削除する `--all-clean` オプションが追加されました
@@ -59,23 +73,6 @@ Narou.rb ― 「小説家になろう」「小説を読もう!」ダウンロ
59
73
  * Bug Fix
60
74
  - 検索除外設定されている小説がダウンロード出来ない問題を修正
61
75
 
62
- 2014/02/24 : **1.4.3**
63
- * 追加機能もしくは仕様変更
64
- - **i文庫** に対応しました。専用のzipアーカイブを生成出来るようになります(txtと表紙、挿絵をzipで固めたもの)
65
- + `narou s device=ibunko` で切り替えることが出来ます
66
- + Drobbox等と連携をするために、 `narou s convert.copy_to=フォルダのパス` を設定することで、
67
- zipファイルがコピーされるようになります
68
- + i文庫専用レイアウトテンプレート、ibunko_novel.txt.erb が追加されました
69
- + `narou convert` コマンドに `--no-zip` オプションが追加されました
70
- - `setting.ini` に濁点フォントの埋め込みを制御できる `enable_dakuten_font` が追加されました
71
- - あらすじ及び章も変換処理を施すように変更しました
72
- + `converter#before` 及び `after` メソッドの text_type に、 `story` `chapter` が渡されるようになりました
73
- * Bug Fix
74
- - Windowsにおいて、タイトル及び作者名にCP392外の文字が使われていた場合に変換がエラーになる問題を修正
75
- + 変換時にエラーになった小説において、まだエラーが出る場合は一度削除( `narou remove --with-file 小説ID` )
76
- して再ダウンロードをお願いします
77
- - 章タイトルが※で終わる小説をEPUB変換時に警告が出ていたのを修正
78
-
79
76
  ----
80
77
 
81
78
  「小説家になろう」は株式会社ヒナプロジェクトの登録商標です
data/Rakefile CHANGED
@@ -1 +1,12 @@
1
- require "bundler/gem_tasks"
1
+ # -*- mode: ruby -*-
2
+ # -*- coding: utf-8 -*-
3
+
4
+ task :default => [:spec]
5
+ begin
6
+ require "rspec/core/rake_task"
7
+ RSpec::Core::RakeTask.new(:spec) do |spec|
8
+ spec.pattern = 'spec/**/*_spec.rb'
9
+ spec.rspec_opts = ['-cr spec_helper']
10
+ end
11
+ rescue LoadError => e
12
+ end
@@ -15,12 +15,13 @@ module Command
15
15
 
16
16
  Example:
17
17
  narou browser n9669bk
18
- narou browser musyoku
18
+ narou browser musyoku -v
19
+ narou b 0
19
20
 
20
21
  Options:
21
22
  EOS
22
23
 
23
- @opt.on("-v", "--vote", "指定した小説の投票・感想を投稿するページを表示する") {
24
+ @opt.on("-v", "--vote", "小説の投票・感想を投稿するページを表示する(なろうのみ)") {
24
25
  @options["vote"] = true
25
26
  }
26
27
  end
@@ -42,7 +43,7 @@ module Command
42
43
  # TODO: 最新話の場所をAPIで取得する
43
44
  data_dir = Downloader.get_novel_data_dir_by_target(data["id"])
44
45
  latest_index = YAML.load_file(File.join(data_dir, Downloader::TOC_FILE_NAME))["subtitles"].last["index"]
45
- open_url = "#{toc_url + latest_index}/#f_cr"
46
+ open_url = "#{toc_url + latest_index}/#my_novelpoint"
46
47
  else
47
48
  open_url = toc_url
48
49
  end
@@ -16,6 +16,7 @@ module Command
16
16
  Example:
17
17
  narou folder n9669bk
18
18
  narou folder musyoku
19
+ narou f 0
19
20
  EOS
20
21
  end
21
22
 
@@ -6,7 +6,9 @@
6
6
  require "stringio"
7
7
  require "date"
8
8
  require "uri"
9
+ require "nkf"
9
10
  require_relative "progressbar"
11
+ require_relative "inspector"
10
12
 
11
13
  class ConverterBase
12
14
  KANJI_NUM = "〇一二三四五六七八九"
@@ -214,6 +216,8 @@ class ConverterBase
214
216
  end
215
217
  end
216
218
 
219
+ RECONVERT_KANJI_TO_NUM_PATTERN_UNIT = "%㎜㎝㎞㎎㎏㏄㎡㎥"
220
+
217
221
  #
218
222
  # アラビア数字を使うべきところはアラビア数字に戻す
219
223
  #
@@ -222,7 +226,7 @@ class ConverterBase
222
226
  data.gsub!(/([A-Za-z])([#{KANJI_NUM}・~]+)/) do # ver1・01 のようなパターンも許容する
223
227
  $1 + $2.tr(KANJI_NUM, "0-9")
224
228
  end
225
- data.gsub!(/([#{KANJI_NUM}・~]+)([A-Za-z])/) do
229
+ data.gsub!(/([#{KANJI_NUM}・~]+)([A-Za-z#{RECONVERT_KANJI_TO_NUM_PATTERN_UNIT}])/) do
226
230
  $1.tr(KANJI_NUM, "0-9") + $2
227
231
  end
228
232
  end
@@ -308,6 +312,7 @@ class ConverterBase
308
312
  # 特定の表現・記号を変換していく
309
313
  #
310
314
  def convert_special_characters(data)
315
+ stash_komejirushi(data)
311
316
  convert_aozora_special_charactoers(data)
312
317
  symbols_to_zenkaku(data)
313
318
  convert_tatechuyoko(data)
@@ -316,14 +321,21 @@ class ConverterBase
316
321
  end
317
322
 
318
323
  #
319
- # 記号を全角に変換
324
+ # 半角カナと 「」。、・ 等を全角に変換
325
+ #
326
+ def hankakukana_to_zenkakukana(data)
327
+ data.replace(NKF.nkf("-w -X", data))
328
+ end
329
+
330
+ #
331
+ # 半角記号を全角に変換
320
332
  #
321
333
  def symbols_to_zenkaku(data)
322
334
  data.tr!("“”‘’〝〟", %!""''""!)
323
335
  data.gsub!(/"([^"\n]+)"/, "〝\\1〟")
324
336
  data.gsub!(/'([^'\n]+)'/, "〝\\1〟") # MEMO: シングルミュート(ノノカギ)を表示出来るフォントはほとんど無い
325
- data.tr!("-=+/*《》'\"%$#&!?、<><>()|‐,._;:[]",
326
- "-=+/*≪≫’”%$#&!?、〈〉〈〉()|-,._;:[]")
337
+ data.tr!("-=+/*《》'\"%$#&!?<><>()|‐,._;:[]",
338
+ "-=+/*≪≫’”%$#&!?〈〉〈〉()|-,._;:[]")
327
339
  data.gsub!("\\", "¥")
328
340
  end
329
341
 
@@ -385,11 +397,18 @@ class ConverterBase
385
397
  end
386
398
  end
387
399
 
400
+ #
401
+ # 単独※をあとあと外字注記化するために一時的に変換
402
+ # 外字注記表記だと border_symbol? 等で困るのであとで外字注記化する
403
+ #
404
+ def stash_komejirushi(data)
405
+ data.gsub!("※", "※※")
406
+ end
407
+
388
408
  #
389
409
  # 特殊な記号を外字注記に変換
390
410
  #
391
411
  def convert_aozora_special_charactoers(data)
392
- data.gsub!("※", "※※") # 外字注記表記だと border_symbol? 等で困るのであとで外字注記化する
393
412
  data.gsub!("≪", "※[#始め二重山括弧]")
394
413
  data.gsub!("≫", "※[#終わり二重山括弧]")
395
414
  end
@@ -397,9 +416,9 @@ class ConverterBase
397
416
  #
398
417
  # ※の外字注記化
399
418
  #
400
- # convert_aozora_special_charactoers で2つにしておいた※を外字注記化する
419
+ # stash_komejirushi で2つにしておいた※を外字注記化する
401
420
  #
402
- def rebuild_kome_to_gaiji(data)
421
+ def rebuild_komejirushi_to_gaiji(data)
403
422
  data.gsub!("※※", "※[#米印、1-2-8]")
404
423
  end
405
424
 
@@ -776,12 +795,12 @@ class ConverterBase
776
795
  # 小説家になろうのルビ対策
777
796
  #
778
797
  def narou_ruby(data)
779
- # 《》なルビの対処
780
- data.gsub!(/(.+?)≪(.+?)≫/) do |match|
781
- to_ruby(match, $1, $2, ["≪", "≫"])
782
- end
783
- # ()なルビの対処
784
- if @text_type != "subtitle"
798
+ if @text_type != "subtitle" && @text_type != "chapter"
799
+ # 《》なルビの対処
800
+ data.gsub!(/(.+?)≪(.+?)≫/) do |match|
801
+ to_ruby(match, $1, $2, ["≪", "≫"])
802
+ end
803
+ # ()なルビの対処
785
804
  data.gsub!(/(.+?)(([ぁ-んァ-ヶーゝゞ・A-Za-zA-Za-z ]{,20}))/) do |match|
786
805
  to_ruby(match, $1, $2, ["(", ")"])
787
806
  end
@@ -869,19 +888,14 @@ class ConverterBase
869
888
  end
870
889
 
871
890
  #
872
- # なろうの挿絵タグを挿絵注釈に変換
891
+ # 挿絵タグやimgタグ等を挿絵注釈に変換
873
892
  # 挿絵画像が存在しなければダウンロードして保存する
874
893
  #
875
894
  def replace_illust_tag(data)
876
- data.gsub!(/^(<i[0-9]+\|[0-9]+>)\n?/m) do
877
- next "" unless @setting.enable_narou_illust
878
- chuki = @illustration.get($1)
879
- if chuki
880
- @illust_chuki_list << chuki
881
- "[#挿絵=#{@illust_chuki_list.count - 1}]\n"
882
- else
883
- ""
884
- end
895
+ @illustration.scanner(data) do |chuki|
896
+ next "" unless @setting.enable_illust
897
+ @illust_chuki_list << chuki
898
+ "[#挿絵=#{@illust_chuki_list.count - 1}]\n"
885
899
  end
886
900
  end
887
901
 
@@ -988,6 +1002,7 @@ class ConverterBase
988
1002
  # 小説データ全体に対して施す変換
989
1003
  #
990
1004
  def convert_for_all_data(data)
1005
+ hankakukana_to_zenkakukana(data)
991
1006
  auto_join_in_brackets(data)
992
1007
  auto_join_line(data) if @setting.enable_auto_join_line
993
1008
  erase_comments_block(data)
@@ -998,7 +1013,7 @@ class ConverterBase
998
1013
  alphabet_to_zenkaku(data, @setting.enable_alphabet_force_zenkaku)
999
1014
  convert_numbers(data)
1000
1015
  exception_reconvert_kanji_to_num(data)
1001
- if @setting.enable_convert_num_to_kanji && @text_type != "subtitle" \
1016
+ if @setting.enable_convert_num_to_kanji && @text_type != "subtitle" && @text_type != "chapter" \
1002
1017
  && @setting.enable_kanji_num_with_units
1003
1018
  convert_kanji_num_with_unit(data, @setting.kanji_num_with_units_lower_digit_zero)
1004
1019
  end
@@ -1035,7 +1050,8 @@ class ConverterBase
1035
1050
  #
1036
1051
  # 変換処理本体
1037
1052
  #
1038
- # @text_type: 渡されるテキストの種類。subtitle, introduction, body, postscript, textfile のどれか
1053
+ # @text_type: 渡されるテキストの種類。
1054
+ # subtitle, introduction, body, postscript, textfile, chapter, story
1039
1055
  #
1040
1056
  def convert_main(io)
1041
1057
  @write_fp = StringIO.new
@@ -1102,12 +1118,14 @@ class ConverterBase
1102
1118
  rebuild_url(data)
1103
1119
  rebuild_english_sentences(data)
1104
1120
  rebuild_hankaku_num_and_comma(data)
1105
- rebuild_kome_to_gaiji(data)
1121
+ rebuild_komejirushi_to_gaiji(data)
1122
+ convert_aozora_special_charactoers(data)
1106
1123
  # 再構築された文章にルビがふられる可能性を考慮して、
1107
1124
  # この位置でルビの処理を行う
1108
1125
  narou_ruby(data) if @setting.enable_ruby
1109
1126
  # 三点リーダーの変換は、ルビで圏点として・・・を使っている場合を考慮して、ルビ処理後にする
1110
1127
  convert_horizontal_ellipsis(data)
1128
+ convert_aozora_special_charactoers(data)
1111
1129
  data.strip!
1112
1130
  progressbar.clear if @text_type == "textfile"
1113
1131
  @write_fp
@@ -11,6 +11,7 @@ require_relative "template"
11
11
  require_relative "database"
12
12
  require_relative "localsetting"
13
13
  require_relative "narou/api"
14
+ require_relative "html"
14
15
 
15
16
  #
16
17
  # 小説サイトからのダウンロード
@@ -23,6 +24,8 @@ class Downloader
23
24
  TOC_FILE_NAME = "toc.yaml"
24
25
  WAITING_TIME_FOR_503 = 20 # 503 のときに待機する秒数
25
26
  RETRY_MAX_FOR_503 = 5 # 503 のときに何回再試行するか
27
+ NOVEL_TYPE_SERIES = 1 # 連載
28
+ NOVEL_TYPE_SS = 2 # 短編
26
29
 
27
30
  attr_reader :id
28
31
 
@@ -213,7 +216,7 @@ class Downloader
213
216
  def self.get_sitesetting_by_sitename(sitename)
214
217
  setting = @@settings.find { |s| s["name"] == sitename }
215
218
  return setting if setting
216
- error "#{data["sitename"]} の設定ファイルが見つかりません"
219
+ error "#{sitename} の設定ファイルが見つかりません"
217
220
  exit 1
218
221
  end
219
222
 
@@ -221,7 +224,8 @@ class Downloader
221
224
  # 小説サイトの定義ファイルを全部読み込む
222
225
  #
223
226
  def self.load_settings
224
- settings = []
227
+ settings = @@__settings_cache ||= []
228
+ return settings unless settings.empty?
225
229
  Dir.glob(File.join(Narou.get_script_dir, NOVEL_SITE_SETTING_DIR, "*.yaml")) do |path|
226
230
  setting = SiteSetting.load_file(path)
227
231
  if setting["name"] == "小説家になろう"
@@ -271,12 +275,15 @@ class Downloader
271
275
  # コンストラクタ
272
276
  #
273
277
  def initialize(site_setting, force = false, from_download = false)
278
+ @title = nil
279
+ @file_title = nil
274
280
  @setting = site_setting
275
281
  @force = force
276
282
  @from_download = from_download
277
283
  @cache_dir = nil
278
284
  @new_arrivals = false
279
285
  @novel_type = nil
286
+ @novel_data_dir = nil
280
287
  @id = @@database.get_id("toc_url", @setting["toc_url"]) || @@database.get_new_id
281
288
  end
282
289
 
@@ -420,8 +427,8 @@ class Downloader
420
427
  @@database[@id] = {
421
428
  "id" => @id,
422
429
  "author" => @setting["author"],
423
- "title" => @setting["title"],
424
- "file_title" => @file_title,
430
+ "title" => get_title,
431
+ "file_title" => get_file_title,
425
432
  "toc_url" => @setting["toc_url"],
426
433
  "sitename" => @setting["name"],
427
434
  "novel_type" => get_novel_type,
@@ -432,22 +439,53 @@ class Downloader
432
439
  end
433
440
 
434
441
  def get_novel_type
435
- @novel_type ||= @@database[@id]["novel_type"] || 1
442
+ return @novel_type if @novel_type
443
+ @novel_type = @@database[@id] ? @@database[@id]["novel_type"] : nil
444
+ unless @novel_type
445
+ if @setting["narou_api_url"]
446
+ info = Narou::API.new(@setting, "nt")
447
+ else
448
+ info = NovelInfo.load(@setting)
449
+ @novel_type = info ? info["novel_type"] : NOVEL_TYPE_SERIES
450
+ end
451
+ end
452
+ @novel_type
436
453
  end
437
454
 
438
455
  #
439
456
  # 連載小説かどうか調べる
440
457
  #
441
458
  def series_novel?
442
- unless @novel_type
443
- if @@database[@id]
444
- @novel_type = get_novel_type
445
- else
446
- api = Narou::API.new(@setting, "nt")
447
- @novel_type = api["novel_type"]
448
- end
459
+ get_novel_type == NOVEL_TYPE_SERIES
460
+ end
461
+
462
+ #
463
+ # 小説を格納するためのディレクトリ名を取得する
464
+ #
465
+ def get_file_title
466
+ return @file_title if @file_title
467
+ # すでにデータベースに登録されているならそれを引き続き使うようにする
468
+ if @@database[@id] && @@database[@id]["file_title"]
469
+ @file_title = @@database[@id]["file_title"]
470
+ return @file_title
471
+ end
472
+ @file_title = @setting["ncode"]
473
+ if @setting["append_title_to_folder_name"]
474
+ @file_title += " " + Helper.replace_filename_special_chars(get_title, true).strip
475
+ end
476
+ @file_title
477
+ end
478
+
479
+ #
480
+ # 小説のタイトルを取得する
481
+ #
482
+ def get_title
483
+ return @title if @title
484
+ @title = @setting["title"]
485
+ if @setting["title_strip_pattern"]
486
+ @title = @title.gsub(/#{@setting["title_strip_pattern"]}/, "").gsub(/^[ \s]*(.+?)[ \s]*?$/, "\\1")
449
487
  end
450
- @novel_type == 1
488
+ @title
451
489
  end
452
490
 
453
491
  #
@@ -478,20 +516,24 @@ class Downloader
478
516
  end
479
517
  end
480
518
  @setting.multi_match(toc_source, "title", "author", "story", "tcode")
481
- if @setting["narou_api_url"] && series_novel?
519
+ @setting["title"] = get_title
520
+ if series_novel?
482
521
  # 連載小説
483
522
  subtitles = get_subtitles(toc_source)
484
523
  else
485
524
  # 短編小説
486
- api = Narou::API.new(@setting, "s-gf-nu")
487
- @setting["story"] = api["story"]
488
- subtitles = create_short_story_subtitles(api)
525
+ if @setting["narou_api_url"]
526
+ info = Narou::API.new(@setting, "s-gf-nu-w")
527
+ else
528
+ info = NovelInfo.load(@setting)
529
+ end
530
+ @setting["story"] = info["story"]
531
+ @setting["author"] = info["writer"]
532
+ subtitles = create_short_story_subtitles(info)
489
533
  end
490
- @title = @setting["title"]
491
- @file_title = Helper.replace_filename_special_chars(@title, true).strip
492
- @setting["story"] = @setting["story"].gsub("<br />", "")
534
+ @setting["story"] = HTML.new(@setting["story"]).to_aozora
493
535
  toc_objects = {
494
- "title" => @title,
536
+ "title" => get_title,
495
537
  "author" => @setting["author"],
496
538
  "toc_url" => @setting["toc_url"],
497
539
  "story" => @setting["story"],
@@ -529,10 +571,14 @@ class Downloader
529
571
  # 更新日チェック
530
572
  old_subupdate = old["subupdate"]
531
573
  latest_subupdate = latest["subupdate"]
532
- if old_subupdate == ""
533
- next latest_subupdate != ""
574
+ if old_subupdate
575
+ if old_subupdate == ""
576
+ next latest_subupdate != ""
577
+ end
578
+ latest_subupdate > old_subupdate
579
+ else
580
+ latest["subdate"] > old["subdate"]
534
581
  end
535
- latest_subupdate > old_subupdate
536
582
  end
537
583
  end
538
584
 
@@ -562,15 +608,15 @@ class Downloader
562
608
  #
563
609
  # 短編用の情報を生成
564
610
  #
565
- def create_short_story_subtitles(api)
611
+ def create_short_story_subtitles(info)
566
612
  subtitle = {
567
613
  "index" => "1",
568
- "href" => "/",
614
+ "href" => @setting.replace_group_values("href", "index" => "1"),
569
615
  "chapter" => "",
570
616
  "subtitle" => @setting["title"],
571
617
  "file_subtitle" => Helper.replace_filename_special_chars(@setting["title"]),
572
- "subdate" => api["general_firstup"],
573
- "subupdate" => api["novelupdated_at"]
618
+ "subdate" => info["general_firstup"],
619
+ "subupdate" => info["novelupdated_at"]
574
620
  }
575
621
  [subtitle]
576
622
  end
@@ -585,7 +631,7 @@ class Downloader
585
631
  @@__narou_last_download_time ||= Time.now - 20
586
632
  max = subtitles.count
587
633
  return if max == 0
588
- puts ("<bold><green>" + TermColor.escape("ID:#{@id} #{@title} のDL開始") + "</green></bold>").termcolor
634
+ puts ("<bold><green>" + TermColor.escape("ID:#{@id} #{get_title} のDL開始") + "</green></bold>").termcolor
589
635
  interval_sleep_time = LocalSetting.get["local_setting"]["download.interval"] || 0
590
636
  interval_sleep_time = 0 if interval_sleep_time < 0
591
637
  save_least_one = false
@@ -593,7 +639,7 @@ class Downloader
593
639
  @@__narou_wait_counter = 0
594
640
  end
595
641
  subtitles.each_with_index do |subtitle_info, i|
596
- if @setting["domain"] =~ /syosetu.com/ && (@@__narou_wait_counter % 10 == 0 && @@__narou_wait_counter >= 10)
642
+ if @setting["is_narou"] && (@@__narou_wait_counter % 10 == 0 && @@__narou_wait_counter >= 10)
597
643
  # MEMO:
598
644
  # 小説家になろうは連続DL規制があるため、ウェイトを入れる必要がある。
599
645
  # 10話ごとに規制が入るため、10話ごとにウェイトを挟む。
@@ -610,7 +656,7 @@ class Downloader
610
656
  unless chapter.empty?
611
657
  puts "#{chapter}"
612
658
  end
613
- if @novel_type == 1
659
+ if get_novel_type == NOVEL_TYPE_SERIES
614
660
  print "第#{index}部分"
615
661
  else
616
662
  print "短編"
@@ -666,16 +712,26 @@ class Downloader
666
712
  #
667
713
  def a_section_download(subtitle_info)
668
714
  href = subtitle_info["href"]
669
- if @setting["tcode"]
715
+ if @setting["is_narou"]
670
716
  subtitle_url = @setting.replace_group_values("txtdownload_url", subtitle_info)
671
717
  elsif href[0] == "/"
672
718
  subtitle_url = @setting["top_url"] + href
673
719
  else
674
720
  subtitle_url = @setting["toc_url"] + href
675
721
  end
676
- section = download_raw_data(subtitle_url)
677
- save_raw_data(section, subtitle_info)
678
- element = extract_elements_in_section(section, subtitle_info["subtitle"])
722
+ raw = download_raw_data(subtitle_url)
723
+ if @setting["is_narou"]
724
+ save_raw_data(raw, subtitle_info)
725
+ element = extract_elements_in_section(raw, subtitle_info["subtitle"])
726
+ element["data_type"] = "text"
727
+ else
728
+ save_raw_data(raw, subtitle_info, ".html")
729
+ @setting.multi_match(raw, "text_body", "introduction", "postscript")
730
+ element = { "data_type" => "html" }
731
+ %w(introduction body postscript).each { |type|
732
+ element[type] = @setting[type]
733
+ }
734
+ end
679
735
  element
680
736
  end
681
737
 
@@ -709,7 +765,7 @@ class Downloader
709
765
  end
710
766
 
711
767
  def get_raw_dir
712
- File.join(get_novel_data_dir, RAW_DATA_DIR_NAME)
768
+ @raw_dir ||= File.join(get_novel_data_dir, RAW_DATA_DIR_NAME)
713
769
  end
714
770
 
715
771
  def init_raw_dir
@@ -720,10 +776,10 @@ class Downloader
720
776
  #
721
777
  # テキストデータの生データを保存
722
778
  #
723
- def save_raw_data(raw_data, subtitle_info)
779
+ def save_raw_data(raw_data, subtitle_info, ext = ".txt")
724
780
  index = subtitle_info["index"]
725
781
  file_subtitle = subtitle_info["file_subtitle"]
726
- path = File.join(get_raw_dir, "#{index} #{file_subtitle}.txt")
782
+ path = File.join(get_raw_dir, "#{index} #{file_subtitle}#{ext}")
727
783
  File.write(path, raw_data)
728
784
  end
729
785
 
@@ -773,8 +829,10 @@ class Downloader
773
829
  #
774
830
  # 小説データの格納ディレクトリパス
775
831
  def get_novel_data_dir
776
- raise "小説名がまだ設定されていません" unless @file_title
777
- File.join(Database.archive_root_path, @setting["name"], @file_title)
832
+ return @novel_data_dir if @novel_data_dir
833
+ raise "小説名がまだ設定されていません" unless get_file_title
834
+ @novel_data_dir = File.join(Database.archive_root_path, @setting["name"], get_file_title)
835
+ @novel_data_dir
778
836
  end
779
837
 
780
838
  #