lib/downloader.rb in narou-1.2.6 vs lib/downloader.rb in narou-1.2.7
- old
+ new
@@ -30,11 +30,11 @@
#
# ターゲット(ID、URL、Nコード、小説名)を指定して小説データのダウンロードを開始する
#
# force が true なら全話強制ダウンロード
#
- def self.start(target, force = false)
+ def self.start(target, force = false, from_download = false)
setting = nil
target = Narou.alias_to_id(target)
case type = get_target_type(target)
when :url, :ncode
setting = get_sitesetting_by_target(target)
@@ -58,11 +58,11 @@
else
error "指定の小説(#{target})は存在しません"
return false
end
end
- downloader = Downloader.new(setting, force)
+ downloader = Downloader.new(setting, force, from_download)
result = downloader.start_download
setting.clear
result
end
@@ -269,14 +269,16 @@
end
#
# コンストラクタ
#
- def initialize(site_setting, force = false)
+ def initialize(site_setting, force = false, from_download = false)
@setting = site_setting
@force = force
+ @from_download = from_download
@cache_dir = nil
+ @new_arrivals = false
@id = @@database.get_id("toc_url", @setting["toc_url"]) || @@database.get_new_id
end
#
# 18歳以上か確認する
@@ -373,11 +375,12 @@
"title" => @setting["title"],
"file_title" => @file_title,
"toc_url" => @setting["toc_url"],
"sitename" => @setting["name"],
"novel_type" => @novel_type,
- "last_update" => Time.now
+ "last_update" => Time.now,
+ "new_arrivals_date" => (@new_arrivals ? Time.now : @@database[@id]["new_arrivals_date"])
}
@@database.save_database
end
#
@@ -512,10 +515,19 @@
section_element = a_section_download(subtitle_info)
info = subtitle_info.dup
info["element"] = section_element
section_file_name = "#{index} #{file_subtitle}.yaml"
section_file_path = File.join(SECTION_SAVE_DIR_NAME, section_file_name)
- print " (更新あり)" if @force && different_section?(section_file_path, info)
+ if File.exists?(File.join(get_novel_data_dir, section_file_path))
+ if @force && different_section?(section_file_path, info)
+ print " (更新あり)"
+ end
+ else
+ if !@from_download || (@from_download && @force)
+ print " <bold><magenta>(新着)</magenta></bold>".termcolor
+ end
+ @new_arrivals = true
+ end
move_to_cache_dir(section_file_path)
save_novel_data(section_file_path, info)
save_least_one = true
puts
end