Class: Downloader

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Narou::Eventable
Defined in:
lib/downloader.rb

Overview

小説サイトからのダウンロード

Defined Under Namespace

Classes: DownloaderForceRedirect, DownloaderNotFoundError, InvalidTarget, SuspendDownload

Constant Summary collapse

SECTION_SAVE_DIR_NAME =

本文を保存するディレクトリ名

"本文"
CACHE_SAVE_DIR_NAME =

差分用キャッシュ保存用ディレクトリ名

"cache"
RAW_DATA_DIR_NAME =

本文の生データを保存するディレクトリ名

"raw"
TOC_FILE_NAME =
"toc.yaml"
STEPS_WAIT_TIME =

数話ごとにかかるwaitの秒数

5
WAIT_TIME_TO_RETRY_NETWORK =

タイムアウト等でリトライするまでの待機時間

10
LIMIT_TO_RETRY_NETWORK =

タイムアウト等でリトライする回数上限

5
NOVEL_TYPE_SERIES =

連載

1
NOVEL_TYPE_SS =

短編

2
DISPLAY_LIMIT_DIGITS =

indexの表示桁数限界

4
DEFAULT_INTERVAL_WAIT =

download.interval のデフォルト値(秒)

0.7
CHOICES =
{
  "1" => "このまま更新する",
  "2" => "更新をキャンセル",
  "3" => "更新をキャンセルして小説を凍結する",
  "4" => "バックアップを作成する",
  "5" => "最新のあらすじを表示する",
  "6" => "小説ページをブラウザで開く",
  "7" => "保存フォルダを開く",
  "8" => "変換する",
  default: "2"
}.freeze
@@database =
Database.instance

Constants included from Narou::Eventable

Narou::Eventable::EVENTS_CONTAINER

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Narou::Eventable

#add_event_listener, included, #one, #remove_event_listener, #trigger_event

Constructor Details

#initialize(target, options = {}) ⇒ Downloader

Returns a new instance of Downloader.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/downloader.rb', line 44

def initialize(target, options = {})
  id = Downloader.get_id_by_target(target)
  options = {
    force: false, from_download: false,
    stream: $stdout
  }.merge(options)
  setting = Downloader.get_sitesetting_by_target(target)

  unless setting
    case type = Downloader.get_target_type(target)
    when :url, :ncode
      raise InvalidTarget, "対応外の#{type}です(#{target})"
    when :id
      raise InvalidTarget, "指定のID(#{target})は存在しません"
    when :other
      raise InvalidTarget, "指定の小説(#{target})は存在しません"
    end
  end

  initialize_variables(id, setting, options)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



39
40
41
# File 'lib/downloader.rb', line 39

def id
  @id
end

#settingObject (readonly)

Returns the value of attribute setting.



39
40
41
# File 'lib/downloader.rb', line 39

def setting
  @setting
end

Class Method Details

.choices_to_string(width: 0) ⇒ Object



461
462
463
464
465
# File 'lib/downloader.rb', line 461

def self.choices_to_string(width: 0)
  CHOICES.dup.tap { |h| h.delete(:default) }.map { |key, summary|
    "#{key.rjust(width)}: #{summary}"
  }.join("\n")
end

.create_subdirecotry_name(title) ⇒ Object

サブディレクトリ名を生成



241
242
243
244
# File 'lib/downloader.rb', line 241

def self.create_subdirecotry_name(title)
  name = title.start_with?("n") ? title[1..2] : title[0..1]
  name.strip
end

.detect_error_message(setting, source) ⇒ Object

HTMLの中から小説が削除されたか非公開なことを示すメッセージを検出する



714
715
716
717
718
# File 'lib/downloader.rb', line 714

def self.detect_error_message(setting, source)
  message = setting["error_message"]
  return false unless message
  source.match(message)
end

.get_cache_list(target) ⇒ Object

差分用キャッシュのディレクトリ一覧取得



230
231
232
233
234
235
236
# File 'lib/downloader.rb', line 230

def self.get_cache_list(target)
  dir = get_cache_root_dir(target)
  if dir
    return Dir.glob("#{dir}/*")
  end
  nil
end

.get_cache_root_dir(target) ⇒ Object

差分用キャッシュの保存ディレクトリ取得



219
220
221
222
223
224
225
# File 'lib/downloader.rb', line 219

def self.get_cache_root_dir(target)
  dir = get_novel_data_dir_by_target(target)
  if dir
    return dir.join(SECTION_SAVE_DIR_NAME, CACHE_SAVE_DIR_NAME)
  end
  nil
end

.get_data_by_target(target) ⇒ Object

target からデータベースのデータを取得



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/downloader.rb', line 133

def self.get_data_by_target(target)
  target = Narou.alias_to_id(target)
  case get_target_type(target)
  when :url
    setting = SiteSetting.find(target)
    if setting
      toc_url = setting["toc_url"]
      return @@database.get_data_by_toc_url(toc_url, setting)
    end
  when :ncode
    @@database.each_value do |data|
      return data if data["toc_url"] =~ %r!#{target}/$!
    end
  when :id
    data = @@database[target.to_i]
    return data if data
  when :other
    data = @@database.get_data("title", target)
    return data if data
  end
  nil
end

.get_id_by_target(target) ⇒ Object

target のIDを取得



125
126
127
128
# File 'lib/downloader.rb', line 125

def self.get_id_by_target(target)
  data = get_data_by_target(target)
  data && data["id"]
end

.get_novel_data_dir_by_target(target) ⇒ Object

指定されたIDとかから小説の保存ディレクトリを取得



107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/downloader.rb', line 107

def self.get_novel_data_dir_by_target(target)
  data = get_data_by_target(target) or return nil
  id = data["id"]
  file_title = data["file_title"] || data["title"]   # 互換性維持のための処理
  use_subdirectory = data["use_subdirectory"] || false
  subdirectory = use_subdirectory ? create_subdirecotry_name(file_title) : ""
  path = Database.archive_root_path.join(data["sitename"], subdirectory, file_title)
  return path if path.exist?
  @@database.delete(id)
  @@database.save_database
  error "#{path} が見つかりません。\n" \
        "保存フォルダが消去されていたため、データベースのインデックスを削除しました。"
  nil
end

.get_novel_section_save_dir(archive_path) ⇒ Object

本文格納用ディレクトリを取得



81
82
83
# File 'lib/downloader.rb', line 81

def self.get_novel_section_save_dir(archive_path)
  Pathname(File.join(archive_path, SECTION_SAVE_DIR_NAME))
end

.get_sitesetting_by_target(target) ⇒ Object

小説サイト設定を取得する



69
70
71
72
73
74
75
76
# File 'lib/downloader.rb', line 69

def self.get_sitesetting_by_target(target)
  toc_url = get_toc_url(target)
  setting = nil
  if toc_url
    setting = SiteSetting.find(toc_url)
  end
  setting
end

.get_target_type(target) ⇒ Object

target の種別を判別する

ncodeの場合、targetを破壊的に変更する



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/downloader.rb', line 90

def self.get_target_type(target)
  case target
  when URI.regexp
    :url
  when /^n\d+[a-z]+$/i
    target.downcase!
    :ncode
  when /^\d+$/, Integer
    :id
  else
    :other
  end
end

.get_toc_by_target(target) ⇒ Object



163
164
165
166
# File 'lib/downloader.rb', line 163

def self.get_toc_by_target(target)
  dir = Downloader.get_novel_data_dir_by_target(target)
  get_toc_data(dir)
end

.get_toc_data(archive_path) ⇒ Object

toc 読込



159
160
161
# File 'lib/downloader.rb', line 159

def self.get_toc_data(archive_path)
  YAML.load_file(File.join(archive_path, TOC_FILE_NAME))
end

.get_toc_url(target) ⇒ Object

指定の小説の目次ページのURLを取得する

targetがURLかNコードの場合、実際には小説が存在しないURLが返ってくることがあるのを留意する



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/downloader.rb', line 173

def self.get_toc_url(target)
  target = Narou.alias_to_id(target)
  case get_target_type(target)
  when :url
    setting = SiteSetting.find(target)
    return setting["toc_url"] if setting
  when :ncode
    @@database.each_value do |data|
      if data["toc_url"] =~ %r!#{target}/$!
        return data["toc_url"]
      end
    end
    return "#{SiteSetting.narou["top_url"]}/#{target}/"
  when :id
    data = @@database[target.to_i]
    return data["toc_url"] if data
  when :other
    data = @@database.get_data("title", target)
    return data["toc_url"] if data
  end
  nil
end

.novel_exists?(target) ⇒ Boolean

Returns:

  • (Boolean)


196
197
198
199
# File 'lib/downloader.rb', line 196

def self.novel_exists?(target)
  id = get_id_by_target(target) or return nil
  @@database.novel_exists?(id)
end

.remove_novel(target, with_file = false) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/downloader.rb', line 201

def self.remove_novel(target, with_file = false)
  data = get_data_by_target(target) or return nil
  data_dir = get_novel_data_dir_by_target(target)
  if with_file
    FileUtils.remove_entry_secure(data_dir, true)
    puts "#{data_dir} を完全に削除しました"
  else
    # TOCは消しておかないと再DL時に古いデータがあると誤認する
    data_dir.join(TOC_FILE_NAME).delete
  end
  @@database.delete(data["id"])
  @@database.save_database
  data["title"]
end

Instance Method Details

#__search_index_in_subtitles(subtitles, index) ⇒ Object



814
815
816
817
818
# File 'lib/downloader.rb', line 814

def __search_index_in_subtitles(subtitles, index)
  subtitles.index { |item|
    item["index"] == index
  }
end

#__search_latest_update_time(key, subtitles, subkey: nil) ⇒ Object



554
555
556
557
558
559
560
561
562
563
564
565
# File 'lib/downloader.rb', line 554

def __search_latest_update_time(key, subtitles, subkey: nil)
  latest = Time.new(0)
  subtitles.each do |subtitle|
    value = subtitle[key]
    if value.to_s.empty? && subkey
      value = subtitle[subkey]
    end
    time = Helper.date_string_to_time(value)
    latest = time if time && latest < time
  end
  latest
end

#__strdate_to_ymd(date) ⇒ Object



820
821
822
# File 'lib/downloader.rb', line 820

def __strdate_to_ymd(date)
  Date.parse(date.to_s.tr("年月日時分秒", "///:::")).strftime("%Y%m%d")
end

#a_section_download(subtitle_info) ⇒ Object

指定された話数の本文をダウンロード



1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# File 'lib/downloader.rb', line 1080

def a_section_download(subtitle_info)
  index = subtitle_info["index"]
  return @section_download_cache[index] if @section_download_cache[index]
  sleep_for_download
  href = subtitle_info["href"]
  subtitle_url =
    if href&.start_with?("/")
      "#{@setting["top_url"]}#{href}"
    else
      "#{@setting["toc_url"]}#{href}"
    end
  raw = download_raw_data(subtitle_url)
  save_raw_data(raw, subtitle_info, ".html")
  %w(introduction postscript body).each { |type| @setting[type] = nil }
  @setting.multi_match(raw, "body_pattern", "introduction_pattern", "postscript_pattern")
  element = { "data_type" => "html" }
  %w(introduction postscript body).each { |type|
    element[type] = @setting[type].to_s
  }
  subtitle_info["download_time"] = Time.now
  @section_download_cache[index] = element
  element
end

#confirm_over18?Boolean

18歳以上か確認する

Returns:

  • (Boolean)


314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/downloader.rb', line 314

def confirm_over18?
  global_setting = Inventory.load("global_setting", :global)
  if global_setting.include?("over18")
    return global_setting["over18"]
  end
  if Narou::Input.confirm("年齢認証:あなたは18歳以上ですか")
    global_setting["over18"] = true
    global_setting.save
    return true
  else
    return false
  end
end

#create_cache_dirObject

差分用キャッシュ保存ディレクトリ作成



538
539
540
541
542
543
544
545
# File 'lib/downloader.rb', line 538

def create_cache_dir
  return nil if @nosave_diff
  now = Time.now
  name = now.strftime("%Y.%m.%d@%H.%M.%S")
  cache_dir = get_novel_data_dir.join(SECTION_SAVE_DIR_NAME, CACHE_SAVE_DIR_NAME, name)
  FileUtils.mkdir_p(cache_dir)
  cache_dir
end

#create_short_story_subtitles(info) ⇒ Object

短編用の情報を生成



961
962
963
964
965
966
967
968
969
970
971
972
# File 'lib/downloader.rb', line 961

def create_short_story_subtitles(info)
  subtitle = {
    "index" => "1",
    "href" => @setting.replace_group_values("href", "index" => "1"),
    "chapter" => "",
    "subtitle" => slim_subtitle(@setting["title"]),
    "file_subtitle" => title_to_filename(@setting["title"]),
    "subdate" => info["general_firstup"],
    "subupdate" => info["novelupdated_at"] || info["general_lastup"] || info["general_firstup"]
  }
  [subtitle]
end

#databaseObject



275
276
277
# File 'lib/downloader.rb', line 275

def database
  @@database
end

#different_section?(old_relative_path, new_subtitle_info) ⇒ Boolean

すでに保存されている内容とDLした内容が違うかどうか

Returns:

  • (Boolean)


1042
1043
1044
1045
1046
# File 'lib/downloader.rb', line 1042

def different_section?(old_relative_path, new_subtitle_info)
  path = get_novel_data_dir.join(old_relative_path)
  return true unless path.exist?
  YAML.load_file(path)["element"] != new_subtitle_info["element"]
end

#display_hintObject



1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
# File 'lib/downloader.rb', line 1104

def display_hint
  @stream.puts <<~HINT
    ヒント:
    503 がでた場合はしばらくアクセスが規制される場合があります。
    設定を変更してサーバーに対する負荷を軽減させましょう。(下記参照)
    小説家になろう系列の場合、10分程度時間を置く必要があります。
    (メンテナンス等でも503になる場合があります。公式サイトを確認してください)

    下記の設定のどれか、もしくは全てを変更することで調整できます。
    (download.interval が最重要設定。1話ごとの間隔が短すぎると規制されやすい)

    # 1話ごとに入るウェイトを変更する(単位:秒)
    narou s download.interval=1.0

    # 10話ごとに通常より長いウェイトを入れる
    narou s download.wait-steps=10

    # Update時の作品間の待機時間を変更する(単位:秒)
    narou s update.interval=3.0
  HINT
end

#download_raw_data(url) ⇒ Object

指定したURLからデータをダウンロード



1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
# File 'lib/downloader.rb', line 1129

def download_raw_data(url)
  raw = nil
  retry_count = LIMIT_TO_RETRY_NETWORK
  cookie = @setting["cookie"] || ""
  begin
    open_uri_options = make_open_uri_options("Cookie" => cookie, allow_redirections: :safe)
    open(url, "r:#{@setting["encoding"]}", open_uri_options) do |fp|
      raw = Helper.pretreatment_source(fp.read, @setting["encoding"])
    end
  rescue OpenURI::HTTPError, Errno::ECONNRESET, Errno::ETIMEDOUT, Net::OpenTimeout => e
    case e.message
    when /^503/
      # 503 はアクセス規制やメンテ等でリトライしてもほぼ意味がないことが多いため一度で諦める
      @stream.error "server message: #{e.message}"
      display_hint
      raise SuspendDownload
    when /^404/
      @stream.error "server message: #{e.message}"
      @stream.puts "#{url} がダウンロード出来ませんでした。時間をおいて再度試してみてください"
      raise SuspendDownload
    else
      if retry_count == 0
        @stream.error "上限までリトライしましたがファイルがダウンロード出来ませんでした"
        raise SuspendDownload
      end
      retry_count -= 1
      @stream.puts <<~MSG
        server message: #{e.message}
        リトライ待機中...
      MSG
      sleep(WAIT_TIME_TO_RETRY_NETWORK)
      retry
    end
  end
  raw
end

#extract_elements_in_section(section, subtitle) ⇒ Object

本文を解析して前書き・本文・後書きの要素に分解する

本文に含まれるタイトルは消す



1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
# File 'lib/downloader.rb', line 1192

def extract_elements_in_section(section, subtitle)
  lines = section.lstrip.lines.map(&:rstrip)
  introduction = slice_introduction(lines)
  postscript = slice_postscript(lines)
  if lines[0] == subtitle.strip
    if lines[1] == ""
      lines.slice!(0, 2)
    else
      lines.slice!(0, 1)
    end
  end
  {
    "data_type" => "text",
    "introduction" => introduction,
    "postscript" => postscript,
    "body" => lines.join("\n")
  }
end

#get_file_titleObject

小説を格納するためのディレクトリ名を取得する



680
681
682
683
684
685
686
687
688
# File 'lib/downloader.rb', line 680

def get_file_title
  # すでにデータベースに登録されているならそれを引き続き使うようにする
  file_title = record&.dig("file_title")
  return file_title if file_title
  ncode = @setting["ncode"]
  return ncode unless @setting["append_title_to_folder_name"]
  scrubbed_title = Helper.replace_filename_special_chars(get_title, true).strip
  Helper.truncate_folder_title("#{ncode} #{scrubbed_title}")
end

#get_general_lastupObject

小説の最新掲載日をTime型で取得

小説家になろう、ハーメルンは小説情報ページの最終話掲載日などから取得した日付 その他サイトは一番新しい話の投稿日(更新日ではない)



585
586
587
588
589
590
591
592
# File 'lib/downloader.rb', line 585

def get_general_lastup
  info = @setting["info"] || {}
  if info["general_lastup"]
    info["general_lastup"]
  else
    __search_latest_update_time("subdate", @setting["subtitles"])
  end
end

#get_latest_table_of_contents(old_toc, through_error: false) ⇒ Object

目次データを取得する



762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
# File 'lib/downloader.rb', line 762

def get_latest_table_of_contents(old_toc, through_error: false)
  toc_source = get_toc_source
  return nil unless toc_source
  @setting.multi_match(toc_source, "tcode")
  info = NovelInfo.load(@setting, toc_source: toc_source)
  if info
    raise DownloaderNotFoundError unless info["title"]
    @setting["title"] = info["title"]
    @setting["author"] = info["writer"]
    @setting["story"] = info["story"]
  else
    # 小説情報ページがないサイトの場合は目次ページから取得する
    @setting.multi_match(toc_source, "title", "author", "story")
    raise DownloaderNotFoundError unless @setting.matched?("title")
    story_html = HTML.new(@setting["story"])
    story_html.strip_decoration_tag = true
    @setting["story"] = story_html.to_aozora
  end
  @setting["info"] = info

  @setting["title"] = get_title
  if series_novel?
    # 連載小説
    subtitles = get_subtitles(toc_source, old_toc)
  else
    # 短編小説
    subtitles = create_short_story_subtitles(info)
  end
  @setting["subtitles"] = subtitles

  toc_objects = {
    "title" => get_title,
    "author" => @setting["author"],
    "toc_url" => @setting["toc_url"],
    "story" => @setting["story"],
    "subtitles" => subtitles
  }
  toc_objects
rescue OpenURI::HTTPError, Errno::ECONNRESET, Errno::ETIMEDOUT, Net::OpenTimeout => e
  raise if through_error   # エラー処理はしなくていいからそのまま例外を受け取りたい時用
  if e.message.include?("404")
    @stream.error "小説が削除されているか非公開な可能性があります"
    if database.novel_exists?(@id)
      Command::Tag.execute!(%W(#{@id} --add 404 --color white --no-overwrite-color), io: Narou::NullIO.new)
      Command::Freeze.execute!(@id, "--on")
    end
  else
    @stream.error "何らかの理由により目次が取得できませんでした(#{e.message})"
  end
  false
end

#get_novel_data_dirObject

小説データの格納ディレクトリパス



1234
1235
1236
1237
1238
# File 'lib/downloader.rb', line 1234

def get_novel_data_dir
  raise "小説名がまだ設定されていません" unless get_file_title
  subdirectory = @download_use_subdirectory ? Downloader.create_subdirecotry_name(get_file_title) : ""
  Database.archive_root_path.join(sitename, subdirectory, get_file_title)
end

#get_novel_statusObject



636
637
638
639
640
641
642
643
644
# File 'lib/downloader.rb', line 636

def get_novel_status
  novel_status = NovelInfo.load(@setting, of: "nt-e-sitename")
  novel_status ||= {
    "novel_type" => NOVEL_TYPE_SERIES,
    "end" => nil, # nil で完結状態が定義されていなかったことを示す(扱いとしては未完結と同じ)
    "sitename" => @setting["sitename"]
  }
  novel_status
end

#get_novel_typeObject

小説の種別を取得(連載か短編)



650
651
652
# File 'lib/downloader.rb', line 650

def get_novel_type
  get_novel_status["novel_type"]
end

#get_novelupdated_atObject

小説が更新された日をTime型で取得



570
571
572
573
574
575
576
577
# File 'lib/downloader.rb', line 570

def get_novelupdated_at
  info = @setting["info"] || {}
  if info["novelupdated_at"]
    info["novelupdated_at"]
  else
    __search_latest_update_time("subupdate", @setting["subtitles"], subkey: "subdate")
  end
end

#get_section_file_timestamp(old_subtitles_info, latest_subtitles_info) ⇒ Object

対象話数のタイムスタンプを取得



903
904
905
906
907
908
909
910
# File 'lib/downloader.rb', line 903

def get_section_file_timestamp(old_subtitles_info, latest_subtitles_info)
  download_time = old_subtitles_info["download_time"]
  unless download_time
    download_time = File.mtime(section_file_path(old_subtitles_info))
  end
  latest_subtitles_info["download_time"] = download_time
  download_time
end

#get_subtitles(toc_source, old_toc) ⇒ Object

各話の情報を取得



923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
# File 'lib/downloader.rb', line 923

def get_subtitles(toc_source, old_toc)
  subtitles = []
  toc_post = toc_source.dup
  old_subtitles = old_toc ? old_toc["subtitles"] : nil
  loop do
    match_data = @setting.multi_match(toc_post, "subtitles")
    break unless match_data
    toc_post = match_data.post_match
    @setting["subtitle"] = @setting["subtitle"].gsub("\t", "")
    subdate = @setting["subdate"].tap { |sd|
      # subdate(初回掲載日)がない場合、最初に取得した時のsubupdateで代用する
      # subdateが取得出来ないのは暁とArcadia
      unless sd
        old_index = old_subtitles ? __search_index_in_subtitles(old_subtitles, @setting["index"]) : nil
        if !old_index || !old_subtitles[old_index]["subdate"]
          break @setting["subupdate"]
        end
        # || 以降は subupdate を取得していない古い(2.4.0以前)toc.yamlがあるためsubdateを使う
        break old_subtitles[old_index]["subupdate"] || old_subtitles[old_index]["subdate"]
      end
    }
    subtitles << {
      "index" => @setting["index"],
      "href" => @setting["href"],
      "chapter" => @setting["chapter"].to_s,
      "subchapter" => @setting["subchapter"].to_s,
      "subtitle" => slim_subtitle(@setting["subtitle"]),
      "file_subtitle" => title_to_filename(@setting["subtitle"]),
      "subdate" => subdate,
      "subupdate" => @setting["subupdate"]
    }
  end
  subtitles
end

#get_titleObject

小説のタイトルを取得する



694
695
696
697
698
699
700
701
# File 'lib/downloader.rb', line 694

def get_title
  return @title if @title
  @title = @setting["title"] || record["title"]
  if @setting["title_strip_pattern"]
    @title = @title.gsub(/#{@setting["title_strip_pattern"]}/, "").gsub(/^[ \s]*(.+?)[ \s]*?$/, "\\1")
  end
  @title
end

#get_toc_sourceObject



720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
# File 'lib/downloader.rb', line 720

def get_toc_source
  toc_url = @setting["toc_url"]
  return nil unless toc_url
  max_retry = 5
  toc_source = ""
  cookie = @setting["cookie"] || ""
  open_uri_options = make_open_uri_options("Cookie" => cookie, allow_redirections: :safe)
  begin
    open(toc_url, open_uri_options) do |toc_fp|
      if toc_fp.base_uri.to_s != toc_url
        # リダイレクトされた場合。
        # ノクターン・ムーンライトのNコードを ncode.syosetu.com に渡すと、年齢認証のクッションページに飛ばされる
        # 転送先を取得し再度ページを取得し直す
        uri = URI.parse(toc_fp.base_uri.to_s)
        if uri.host == "nl.syosetu.com"
          decode = Hash[URI.decode_www_form(uri.query)]
          toc_url = decode["url"]   # 年齢認証確認ページからの転送先
          raise DownloaderForceRedirect
        end
        s = Downloader.get_sitesetting_by_target(toc_fp.base_uri.to_s)
        raise DownloaderNotFoundError unless s   # 非公開や削除等でトップページへリダイレクトされる場合がある
        @setting.clear   # 今まで使っていたのは一旦クリア
        @setting = s
        toc_url = @setting["toc_url"]
      end
      toc_source = Helper.restore_entity(Helper.pretreatment_source(toc_fp.read, @setting["encoding"]))
      raise DownloaderNotFoundError if Downloader.detect_error_message(@setting, toc_source)
    end
  rescue DownloaderForceRedirect
    max_retry -= 1
    if max_retry >= 0
      retry
    else
      raise
    end
  end
  toc_source
end

#init_novel_dirObject

小説データの格納ディレクトリを初期設定する



1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
# File 'lib/downloader.rb', line 1278

def init_novel_dir
  novel_dir_path = get_novel_data_dir
  file_title = novel_dir_path.basename.to_s
  FileUtils.mkdir_p(novel_dir_path) unless novel_dir_path.exist?
  original_settings = NovelSetting.get_original_settings
  default_settings = NovelSetting.load_default_settings
  novel_setting = NovelSetting.new(@id, true, true)
  special_preset_dir = Narou.preset_dir.join(@setting["domain"], @setting["ncode"])
  exists_special_preset_dir = special_preset_dir.exist?
  templates = [
    [NovelSetting::INI_NAME, NovelSetting::INI_ERB_BINARY_VERSION],
    ["converter.rb", 1.0],
    [NovelSetting::REPLACE_NAME, 1.0]
  ]
  templates.each do |(filename, binary_version)|
    if exists_special_preset_dir
      preset_file_path = special_preset_dir.join(filename)
      if preset_file_path.exist?
        unless novel_dir_path.join(filename).exist?
          FileUtils.cp(preset_file_path, novel_dir_path)
        end
        next
      end
    end
    Template.write(filename, novel_dir_path, binding, binary_version)
  end
end

#init_raw_dirObject



1170
1171
1172
1173
1174
# File 'lib/downloader.rb', line 1170

def init_raw_dir
  return if @nosave_raw
  path = raw_dir
  FileUtils.mkdir_p(path) unless path.exist?
end

#initialize_variables(id, setting, options) ⇒ Object

変数初期化



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/downloader.rb', line 253

def initialize_variables(id, setting, options)
  @id = id || database.create_new_id
  @title = nil
  @setting = setting
  @force = options[:force]
  @stream = options[:stream]
  @cache_dir = nil
  @new_arrivals = false
  @new_novel = record.!
  @from_download = options[:from_download]
  @section_download_cache = {}
  @download_wait_steps = Inventory.load("local_setting")["download.wait-steps"] || 0
  @download_use_subdirectory = use_subdirectory?
  if @setting["is_narou"] && (@download_wait_steps > 10 || @download_wait_steps == 0)
    @download_wait_steps = 10
  end
  @nosave_diff = Narou.economy?("nosave_diff")
  @nosave_raw = Narou.economy?("nosave_raw")
  @gurad_spoiler = Inventory.load("local_setting")["guard-spoiler"]
  initialize_wait_counter
end

#initialize_wait_counterObject

ウェイト関係初期化



286
287
288
289
290
291
292
293
294
295
296
# File 'lib/downloader.rb', line 286

def initialize_wait_counter
  @@__run_once ||= false
  unless @@__run_once
    @@__run_once = true
    @@__wait_counter = 0
    @@__last_download_time = Time.now - 20
  end
  @@interval_sleep_time = Inventory.load("local_setting")["download.interval"] || DEFAULT_INTERVAL_WAIT
  @@interval_sleep_time = 0 if @@interval_sleep_time < 0
  @@max_steps_wait_time = [STEPS_WAIT_TIME, @@interval_sleep_time].max
end

#load_novel_data(filename) ⇒ Object

小説データの格納ディレクトリから読み込む



1269
1270
1271
1272
1273
# File 'lib/downloader.rb', line 1269

def load_novel_data(filename)
  YAML.load_file(get_novel_data_dir.join(filename))
rescue Errno::ENOENT
  nil
end

#load_toc_fileObject



340
341
342
# File 'lib/downloader.rb', line 340

def load_toc_file
  load_novel_data(TOC_FILE_NAME)
end

#move_to_cache_dir(relative_path) ⇒ Object

差分用のキャッシュとして保存



1051
1052
1053
1054
1055
1056
1057
# File 'lib/downloader.rb', line 1051

def move_to_cache_dir(relative_path)
  return if @nosave_diff
  path = get_novel_data_dir.join(relative_path)
  if path.exist? && @cache_dir
    FileUtils.mv(path, @cache_dir)
  end
end

#novel_end?Boolean

小説が完結しているか調べる

Returns:

  • (Boolean)


657
658
659
# File 'lib/downloader.rb', line 657

def novel_end?
  get_novel_status["end"]
end

#novel_lengthObject

小説の文字数

小説情報から取得するため、実際に計算するわけではない。 情報から取得出来ない(記載がない)場合は無視する



600
601
602
603
# File 'lib/downloader.rb', line 600

def novel_length
  info = @setting["info"] || {}
  info["length"]
end

#process_digest(old_toc, latest_toc) ⇒ Object

ダイジェスト化に関する処理

Returns:

  • true = 更新をキャンセル、false = 更新する



472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# File 'lib/downloader.rb', line 472

def process_digest(old_toc, latest_toc)
  return false unless old_toc["subtitles"]
  latest_subtitles_count = latest_toc["subtitles"].size
  old_subtitles_count = old_toc["subtitles"].size
  if latest_subtitles_count < old_subtitles_count
    title = latest_toc["title"]
    message = <<-EOS
更新後の話数が保存されている話数より減少していることを検知しました。
ダイジェスト化されている可能性があるので、更新に関しての処理を選択して下さい。

保存済み話数: #{old_subtitles_count}
更新後の話数: #{latest_subtitles_count}

    EOS

    auto_choices = Inventory.load("local_setting")["download.choices-of-digest-options"]
    auto_choices &&= auto_choices.split(",")

    loop do
      if auto_choices
        # 自動入力
        choice = auto_choices.shift || CHOICES[:default]
        puts title
        puts message
        puts self.class.choices_to_string
        puts "> #{choice}"
      else
        choice = Narou::Input.choose(title, message, CHOICES)
      end

      case choice
      when "1"
        return false
      when "2"
        return true
      when "3"
        Command::Freeze.execute!(latest_toc["toc_url"])
        return true
      when "4"
        Command::Backup.execute!(latest_toc["toc_url"])
      when "5"
        if Narou.web?
          message = "あらすじ\n#{latest_toc["story"]}\n"
        else
          puts "あらすじ"
          puts latest_toc["story"]
        end
      when "6"
        Helper.open_browser(latest_toc["toc_url"])
      when "7"
        Helper.open_directory(Downloader.get_novel_data_dir_by_target(latest_toc["toc_url"]))
      when "8"
        Command::Convert.execute!(latest_toc["toc_url"], sync: true)
      end
      unless Narou.web?
        message = ""   # 長いので二度は表示しない
      end
    end
  else
    return false
  end
end

#raw_dirObject



1166
1167
1168
# File 'lib/downloader.rb', line 1166

def raw_dir
  @raw_dir ||= get_novel_data_dir.join(RAW_DATA_DIR_NAME)
end

#recordObject



279
280
281
# File 'lib/downloader.rb', line 279

def record
  database[@id]
end

#remove_cache_dirObject

差分用キャッシュ保存ディレクトリを削除



550
551
552
# File 'lib/downloader.rb', line 550

def remove_cache_dir
  FileUtils.remove_entry_secure(@cache_dir, true) if @cache_dir
end

#run_downloadObject

ダウンロード処理本体



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/downloader.rb', line 347

def run_download
  old_toc = @new_novel ? nil : load_toc_file
  latest_toc = get_latest_table_of_contents(old_toc)
  unless latest_toc
    @stream.error @setting["toc_url"] + " の目次データが取得出来ませんでした"
    return :failed
  end
  latest_toc_subtitles = latest_toc["subtitles"]
  if @setting["confirm_over18"]
    unless confirm_over18?
      @stream.puts "18歳以上のみ閲覧出来る小説です。ダウンロードを中止しました"
      return :canceled
    end
  end
  unless old_toc
    init_novel_dir
    old_toc = {}
    @new_arrivals = true
  end
  init_raw_dir
  if old_toc.empty? || @force
    update_subtitles = latest_toc_subtitles
  else
    update_subtitles = update_body_check(old_toc["subtitles"], latest_toc_subtitles)
  end

  if old_toc.empty? && update_subtitles.size.zero?
    @stream.error "#{@setting['title']} の目次がありません"
    return :failed
  end

  unless @force
    if process_digest(old_toc, latest_toc)
      return :canceled
    end
  end

  id_and_title = "ID:#{@id} #{@title}"

  return_status =
    case
    when update_subtitles.size > 0
      @cache_dir = create_cache_dir if old_toc.length > 0
      sections_download_and_save(update_subtitles)
      if @cache_dir && @cache_dir.glob("*").count == 0
        remove_cache_dir
      end
      update_database
      :ok
    when old_toc["subtitles"].size > latest_toc_subtitles.size
      # 削除された節がある(かつ更新がない)場合
      @stream.puts "#{id_and_title} は一部の話が削除されています"
      :ok
    when old_toc["title"] != latest_toc["title"]
      # タイトルが更新されている場合
      @stream.puts "#{id_and_title} のタイトルが更新されています"
      update_database
      :ok
    when old_toc["story"] != latest_toc["story"]
      # あらすじが更新されている場合
      @stream.puts "#{id_and_title} のあらすじが更新されています"
      :ok
    when old_toc["author"] != latest_toc["author"]
      # 作者名が更新されている場合
      @stream.puts "#{id_and_title} の作者名が更新されています"
      update_database
    else
      :none
    end

  record["general_all_no"] = latest_toc_subtitles.size

  save_toc_once(latest_toc)
  tags = @new_novel ? [] : record["tags"] || []
  case novel_end?
  when true
    unless tags.include?("end")
      update_database if update_subtitles.count == 0
      Command::Tag.execute!(%W(#{id} --add end --color white --no-overwrite-color), io: Narou::NullIO.new)
      msg = old_toc.empty? ? "完結しているようです" : "完結したようです"
      @stream.puts "<cyan>#{id_and_title.escape}#{msg}</cyan>".termcolor
      return_status = :ok
    end
  when false
    if tags.include?("end")
      update_database if update_subtitles.size == 0
      Command::Tag.execute!(@id, "--delete", "end", io: Narou::NullIO.new)
      @stream.puts "<cyan>#{id_and_title.escape} は連載を再開したようです</cyan>".termcolor
      return_status = :ok
    end
  end
  return_status
rescue Interrupt, SuspendDownload
  if latest_toc.present?
    save_toc_once(latest_toc)
    update_database(suspend: true)
  end
  raise Interrupt
ensure
  @setting.clear
end

#save_novel_data(filename, object) ⇒ Object

小説データの格納ディレクトリに保存



1258
1259
1260
1261
1262
1263
1264
1265
# File 'lib/downloader.rb', line 1258

def save_novel_data(filename, object)
  path = get_novel_data_dir.join(filename)
  dir_path = path.dirname
  unless dir_path.exist?
    FileUtils.mkdir_p(dir_path)
  end
  File.write(path, YAML.dump(object))
end

#save_raw_data(raw_data, subtitle_info, ext = ".txt") ⇒ Object

テキストデータの生データを保存



1179
1180
1181
1182
1183
1184
1185
# File 'lib/downloader.rb', line 1179

def save_raw_data(raw_data, subtitle_info, ext = ".txt")
  return if @nosave_raw
  index = subtitle_info["index"]
  file_subtitle = subtitle_info["file_subtitle"]
  path = raw_dir.join("#{index} #{file_subtitle}#{ext}")
  File.write(path, raw_data)
end

#save_toc_once(toc) ⇒ Object



1249
1250
1251
1252
1253
# File 'lib/downloader.rb', line 1249

def save_toc_once(toc)
  return if @save_toc_once
  save_novel_data(TOC_FILE_NAME, toc)
  @save_toc_once = true
end

#section_file_path(subtitle_info) ⇒ Object

小説本文の保存パスを生成



1244
1245
1246
1247
# File 'lib/downloader.rb', line 1244

def section_file_path(subtitle_info)
  filename = "#{subtitle_info["index"]} #{subtitle_info["file_subtitle"]}.yaml"
  get_novel_data_dir.join(SECTION_SAVE_DIR_NAME, filename)
end

#sections_download_and_save(subtitles) ⇒ Object

小説本文をまとめてダウンロードして保存

subtitles にダウンロードしたいものをまとめた subtitle info を渡す



983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
# File 'lib/downloader.rb', line 983

def sections_download_and_save(subtitles)
  max = subtitles.size
  return if max == 0
  @stream.puts "<bold><green>#{"ID:#{@id} #{get_title}".escape} のDL開始</green></bold>".termcolor
  save_least_one = false
  subtitles.each_with_index do |subtitle_info, i|
    index, subtitle, file_subtitle, chapter, subchapter =
      %w(index subtitle file_subtitle chapter subchapter).map { |k|
        subtitle_info[k]
      }
    info = subtitle_info.dup
    info["element"] = a_section_download(subtitle_info)

    @stream.puts "#{chapter}" unless chapter.to_s.empty?
    @stream.puts "#{subchapter}" unless subchapter.to_s.empty?

    if get_novel_type == NOVEL_TYPE_SERIES
      if index.to_s.length <= DISPLAY_LIMIT_DIGITS
        # indexの数字がでかいと見た目がみっともないので特定の桁以内だけ表示する
        @stream.print "#{index}部分 "
      end
    else
      @stream.print "短編 "
    end
    printable_subtitle = @gurad_spoiler ? Helper.to_unprintable_words(subtitle) : subtitle
    @stream.print "#{HTML.new(printable_subtitle).delete_ruby_tag} (#{i + 1}/#{max})"

    section_file_name = "#{index} #{file_subtitle}.yaml"
    section_file_relative_path = File.join(SECTION_SAVE_DIR_NAME, section_file_name)
    section_file_full_path = get_novel_data_dir.join(section_file_relative_path)
    if section_file_full_path.exist?
      if @force
        if different_section?(section_file_relative_path, info)
          @stream.print " (更新あり)"
          move_to_cache_dir(section_file_relative_path)
        end
      else
        move_to_cache_dir(section_file_relative_path)
      end
    else
      if !@from_download || (@from_download && @force)
        @stream.print " <bold><magenta>(新着)</magenta></bold>".termcolor
        trigger(:newarrival, {
          id: @id,
          subtitle_info: subtitle_info
        })
      end
      @new_arrivals = true
    end
    save_novel_data(section_file_relative_path, info)
    save_least_one = true
    @stream.puts
  end
  remove_cache_dir unless save_least_one
end

#series_novel?Boolean

連載小説かどうか調べる

Returns:

  • (Boolean)


673
674
675
# File 'lib/downloader.rb', line 673

def series_novel?
  get_novel_type == NOVEL_TYPE_SERIES
end

#sitenameObject

掲載サイト名

すでにレコードに登録されている場合はそちらを優先する



666
667
668
# File 'lib/downloader.rb', line 666

def sitename
  record&.dig("sitename") || get_novel_status["sitename"]
end

#sleep_for_downloadObject



1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
# File 'lib/downloader.rb', line 1059

def sleep_for_download
  if Time.now - @@__last_download_time > @@max_steps_wait_time
    @@__wait_counter = 0
  end
  if @download_wait_steps > 0 && @@__wait_counter % @download_wait_steps == 0 \
    && @@__wait_counter >= @download_wait_steps
    # MEMO:
    # 小説家になろうは連続DL規制があるため、ウェイトを入れる必要がある。
    # 10話ごとに規制が入るため、10話ごとにウェイトを挟む。
    # 1話ごとに1秒待機を10回繰り返そうと、11回目に規制が入るため、ウェイトは必ず必要。
    sleep(@@max_steps_wait_time)
  else
    sleep(@@interval_sleep_time) if @@__wait_counter > 0
  end
  @@__wait_counter += 1
  @@__last_download_time = Time.now
end

#slice_introduction(lines) ⇒ Object



1211
1212
1213
1214
1215
1216
1217
1218
1219
# File 'lib/downloader.rb', line 1211

def slice_introduction(lines)
  lines.each_with_index do |line, lineno|
    if line =~ ConverterBase::AUTHOR_INTRODUCTION_SPLITTER
      lines.slice!(lineno, 1)
      return lines.slice!(0...lineno).join("\n")
    end
  end
  ""
end

#slice_postscript(lines) ⇒ Object



1221
1222
1223
1224
1225
1226
1227
1228
1229
# File 'lib/downloader.rb', line 1221

def slice_postscript(lines)
  lines.each_with_index do |line, lineno|
    if line =~ ConverterBase::AUTHOR_POSTSCRIPT_SPLITTER
      lines.slice!(lineno, 1)
      return lines.slice!(lineno..-1).join("\n")
    end
  end
  ""
end

#slim_subtitle(string) ⇒ Object



974
975
976
# File 'lib/downloader.rb', line 974

def slim_subtitle(string)
  HTML.new(string).delete_ruby_tag.delete("\n")
end

#start_downloadObject

ダウンロードを処理本体を起動



331
332
333
334
335
336
337
338
# File 'lib/downloader.rb', line 331

def start_download
  @status = run_download
  OpenStruct.new(
    :id => @id,
    :new_arrivals => @new_arrivals,
    :status => @status
    ).freeze
end

#title_to_filename(title) ⇒ Object



912
913
914
915
916
917
918
# File 'lib/downloader.rb', line 912

def title_to_filename(title)
  Helper.truncate_path(
    Helper.replace_filename_special_chars(
      HTML.new(title).delete_ruby_tag
    )
  )
end

#update_body_check(old_subtitles, latest_subtitles) ⇒ Object

本文更新チェック

更新された subtitle だけまとまった配列を返す



829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
# File 'lib/downloader.rb', line 829

def update_body_check(old_subtitles, latest_subtitles)
  strong_update = Inventory.load("local_setting")["update.strong"]
  latest_subtitles.select do |latest|
    index = latest["index"]
    index_in_old_toc = __search_index_in_subtitles(old_subtitles, index)
    next true unless index_in_old_toc
    old = old_subtitles[index_in_old_toc]
    # タイトルチェック
    if old["subtitle"] != latest["subtitle"]
      next true
    end
    # 章チェック
    if old["chapter"] != latest["chapter"]
      next true
    end
    # 前回ダウンロードしたはずの本文ファイルが存在するか
    section_file_name = "#{index} #{old["file_subtitle"]}.yaml"
    section_file_relative_path = File.join(SECTION_SAVE_DIR_NAME, section_file_name)
    unless get_novel_data_dir.join(section_file_relative_path).exist?
      # あるはずのファイルが存在しなかったので、再ダウンロードが必要
      next true
    end
    # 更新日チェック
    # subdate : 初稿投稿日
    # subupdate : 改稿日
    old_subdate = old["subdate"]
    latest_subdate = latest["subdate"]
    old_subupdate = old["subupdate"]
    latest_subupdate = latest["subupdate"]
    # oldにsubupdateがなくても、latestのほうにsubupdateがある場合もある
    old_subupdate = old_subdate if latest_subupdate && !old_subupdate
    different_check = nil
    latest["download_time"] = old["download_time"]
    if strong_update
       = __strdate_to_ymd(get_section_file_timestamp(old, latest))
      different_check = lambda do
        latest_info_dummy = latest.dup
        latest_info_dummy["element"] = a_section_download(latest)
        deffer = different_section?(section_file_relative_path, latest_info_dummy)
        unless deffer
          # 差分がある場合はこのあと保存されて更新されるので、差分がない場合のみ
          # タイムスタンプを更新しておく
          FileUtils.touch(get_novel_data_dir.join(section_file_relative_path))
        end
        deffer
      end
    end
    if old_subupdate && latest_subupdate
      if old_subupdate == ""
        next latest_subupdate != ""
      end
      if strong_update
        if __strdate_to_ymd(old_subupdate) == 
          next different_check.call
        end
      end
      latest_subupdate > old_subupdate
    else
      # 古いバージョンだと old_subdate が nil なので判定出来ないため
      next true unless old_subdate

      if strong_update
        if __strdate_to_ymd(old_subdate) == 
          next different_check.call
        end
      end
      latest_subdate > old_subdate
    end
  end
end

#update_database(suspend: false) ⇒ Object

データベース更新



608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
# File 'lib/downloader.rb', line 608

def update_database(suspend: false)
  info = @setting["info"] || {}
  data = {
    "id" => @id,
    "author" => @setting["author"],
    "title" => get_title,
    "file_title" => get_file_title,
    "toc_url" => @setting["toc_url"],
    "sitename" => sitename,
    "novel_type" => get_novel_type,
    "end" => novel_end?,
    "last_update" => Time.now,
    "new_arrivals_date" => (@new_arrivals ? Time.now : record["new_arrivals_date"]),
    "use_subdirectory" => @download_use_subdirectory,
    "general_firstup" => info["general_firstup"],
    "novelupdated_at" => get_novelupdated_at,
    "general_lastup" => get_general_lastup,
    "length" => novel_length,
    "suspend" => suspend
  }
  if record
    database[@id].merge!(data)
  else
    database[@id] = data
  end
  database.save_database
end

#use_subdirectory?Boolean

サブディレクトリに保存してあるかどうか

Returns:

  • (Boolean)


301
302
303
304
305
306
307
308
309
# File 'lib/downloader.rb', line 301

def use_subdirectory?
  if @new_novel
    # 新規DLする小説
    Inventory.load("local_setting")["download.use-subdirectory"] || false
  else
    # すでにDL済みの小説
    record["use_subdirectory"] || false
  end
end