narou 1.5.11 → 1.6.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 +4 -4
- data/.gitignore +4 -0
- data/ChangeLog.md +619 -432
- data/Gemfile +9 -0
- data/README.md +101 -76
- data/lib/color.rb +62 -22
- data/lib/command.rb +21 -19
- data/lib/command/alias.rb +9 -9
- data/lib/command/backup.rb +11 -4
- data/lib/command/browser.rb +8 -7
- data/lib/command/convert.rb +25 -77
- data/lib/command/diff.rb +67 -36
- data/lib/command/download.rb +5 -4
- data/lib/command/flag.rb +32 -6
- data/lib/command/folder.rb +7 -5
- data/lib/command/freeze.rb +21 -11
- data/lib/command/help.rb +29 -17
- data/lib/command/init.rb +7 -7
- data/lib/command/inspect.rb +6 -5
- data/lib/command/list.rb +106 -25
- data/lib/command/mail.rb +6 -7
- data/lib/command/remove.rb +9 -7
- data/lib/command/send.rb +6 -5
- data/lib/command/setting.rb +51 -16
- data/lib/command/tag.rb +179 -0
- data/lib/command/update.rb +9 -8
- data/lib/command/version.rb +4 -4
- data/lib/commandbase.rb +79 -8
- data/lib/commandline.rb +14 -8
- data/lib/converterbase.rb +78 -28
- data/lib/database.rb +3 -3
- data/lib/device.rb +26 -13
- data/lib/device/ibooks.rb +116 -0
- data/lib/device/ibunko.rb +45 -0
- data/lib/device/kindle.rb +4 -0
- data/lib/device/kobo.rb +4 -0
- data/lib/device/library/windows.rb +12 -4
- data/lib/device/reader.rb +9 -0
- data/lib/diffviewer.rb +147 -0
- data/lib/downloader.rb +195 -80
- data/lib/extensions/jruby.rb +33 -0
- data/lib/extensions/windows.rb +8 -9
- data/lib/helper.rb +79 -37
- data/lib/illustration.rb +1 -1
- data/lib/inspector.rb +2 -2
- data/lib/inventory.rb +48 -0
- data/lib/logger.rb +28 -4
- data/lib/narou.rb +9 -7
- data/lib/narou/api.rb +7 -2
- data/lib/novelconverter.rb +46 -19
- data/lib/novelinfo.rb +13 -3
- data/lib/novelsetting.rb +17 -9
- data/lib/version.rb +1 -1
- data/narou.gemspec +106 -27
- data/narou.rb +2 -2
- data/spec/convert_spec.rb +102 -0
- data/spec/data/convert_test/auto_indent/correct_test_auto_indent.txt +18 -0
- data/spec/data/convert_test/auto_indent/test_auto_indent.txt +21 -0
- data/spec/data/convert_test/auto_join_bracket/correct_test_auto_join_bracket.txt +12 -0
- data/spec/data/convert_test/auto_join_bracket/test_auto_join_bracket.txt +16 -0
- data/spec/data/convert_test/auto_join_line/correct_test_auto_join_line.txt +36 -0
- data/spec/data/convert_test/auto_join_line/test_auto_join_line.txt +51 -0
- data/spec/data/convert_test/convert_page_break/correct_test_convert_page_break.txt +21 -0
- data/spec/data/convert_test/convert_page_break/setting.ini +5 -0
- data/spec/data/convert_test/convert_page_break/test_convert_page_break.txt +60 -0
- data/spec/data/convert_test/force_indent_special_chapter/correct_test_force_indent_special_chapter.txt +64 -0
- data/spec/data/convert_test/force_indent_special_chapter/test_force_indent_special_chapter.txt +61 -0
- data/spec/data/convert_test/horizontal_ellipsis/correct_test_horizontal_ellipsis.txt +52 -0
- data/spec/data/convert_test/horizontal_ellipsis/test_horizontal_ellipsis.txt +57 -0
- data/spec/data/convert_test/kanji_num/correct_test_kanji_num.txt +49 -0
- data/spec/data/convert_test/kanji_num/test_kanji_num.txt +56 -0
- data/spec/data/convert_test/nonokagi/correct_test_nonokagi.txt +29 -0
- data/spec/data/convert_test/nonokagi/test_nonokagi.txt +34 -0
- data/spec/data/convert_test/replace/correct_test_replace.txt +12 -0
- data/spec/data/convert_test/replace/replace.txt +7 -0
- data/spec/data/convert_test/replace/test_replace.txt +14 -0
- data/spec/data/convert_test/ruby/correct_test_ruby.txt +131 -0
- data/spec/data/convert_test/ruby/test_ruby.txt +170 -0
- data/spec/data/convert_test/ruby_youon/correct_test_ruby_youon.txt +12 -0
- data/spec/data/convert_test/ruby_youon/setting.ini +2 -0
- data/spec/data/convert_test/ruby_youon/test_ruby_youon.txt +14 -0
- data/spec/data/convert_test/sesame/correct_test_sesame.txt +40 -0
- data/spec/data/convert_test/sesame/test_sesame.txt +52 -0
- data/spec/data/convert_test/to_odd_leader/correct_test_to_odd_leader.txt +20 -0
- data/spec/data/convert_test/to_odd_leader/test_to_odd_leader.txt +21 -0
- data/spec/device_spec.rb +3 -3
- data/spec/generator/convert_spec_gen.rb +95 -0
- data/spec/html_spec.rb +9 -8
- data/spec/ini_spec.rb +31 -31
- data/spec/novelinfo_spec.rb +2 -2
- data/spec/num_to_kanji_spec.rb +2 -2
- data/template/diff.txt.erb +5 -2
- data/template/ibunko_novel.txt.erb +2 -1
- data/template/novel.txt.erb +16 -3
- data/template/setting.ini.erb +1 -1
- data/webnovel/ncode.syosetu.com.yaml +7 -7
- data/webnovel/novel18.syosetu.com.yaml +7 -7
- data/webnovel/syosetu.org.yaml +8 -11
- metadata +193 -23
- data/lib/globalsetting.rb +0 -64
- data/lib/localsetting.rb +0 -63
data/lib/command/browser.rb
CHANGED
@@ -3,17 +3,21 @@
|
|
3
3
|
# Copyright 2013 whiteleaf. All rights reserved.
|
4
4
|
#
|
5
5
|
|
6
|
-
require_relative "../
|
6
|
+
require_relative "../inventory"
|
7
7
|
|
8
8
|
module Command
|
9
9
|
class Browser < CommandBase
|
10
|
+
def self.oneline_help
|
11
|
+
"小説の掲載ページをブラウザで開きます"
|
12
|
+
end
|
13
|
+
|
10
14
|
def initialize
|
11
|
-
super("<target> [<target2> ...]")
|
15
|
+
super("<target> [<target2> ...] [options]")
|
12
16
|
@opt.separator <<-EOS
|
13
17
|
|
14
18
|
・指定した小説の掲載ページをブラウザで開きます。
|
15
19
|
|
16
|
-
|
20
|
+
Examples:
|
17
21
|
narou browser n9669bk
|
18
22
|
narou browser musyoku -v
|
19
23
|
narou b 0
|
@@ -32,6 +36,7 @@ module Command
|
|
32
36
|
puts @opt.help
|
33
37
|
return
|
34
38
|
end
|
39
|
+
tagname_to_ids(argv)
|
35
40
|
argv.each do |target|
|
36
41
|
data = Downloader.get_data_by_target(target)
|
37
42
|
unless data
|
@@ -51,9 +56,5 @@ module Command
|
|
51
56
|
puts open_url
|
52
57
|
end
|
53
58
|
end
|
54
|
-
|
55
|
-
def oneline_help
|
56
|
-
"小説の掲載ページをブラウザで開きます"
|
57
|
-
end
|
58
59
|
end
|
59
60
|
end
|
data/lib/command/convert.rb
CHANGED
@@ -4,36 +4,33 @@
|
|
4
4
|
#
|
5
5
|
|
6
6
|
require "fileutils"
|
7
|
-
require_relative "../database"
|
8
7
|
require_relative "../downloader"
|
9
8
|
require_relative "../novelconverter"
|
10
|
-
require_relative "../
|
9
|
+
require_relative "../inventory"
|
11
10
|
require_relative "../kindlestrip"
|
12
11
|
|
13
12
|
module Command
|
14
13
|
class Convert < CommandBase
|
15
|
-
|
16
|
-
|
17
|
-
def oneline_help
|
14
|
+
def self.oneline_help
|
18
15
|
"小説を変換します。管理小説以外にテキストファイルも変換可能"
|
19
16
|
end
|
20
17
|
|
21
18
|
def initialize
|
22
|
-
super("<target> [<target2> ...] [
|
19
|
+
super("<target> [<target2> ...] [options]")
|
23
20
|
@opt.separator <<-EOS
|
24
21
|
|
25
22
|
・指定した小説を縦書き用に整形及びEPUB、MOBIに変換します。
|
26
23
|
・変換したい小説のNコード、URL、タイトルもしくはIDを指定して下さい。
|
27
24
|
IDは #{@opt.program_name} list を参照して下さい。
|
28
25
|
・一度に複数の小説を指定する場合は空白で区切って下さい。
|
29
|
-
※-oオプションがない場合、[
|
26
|
+
※-oオプションがない場合、[作者名] 小説名.txtが小説の保存フォルダに出力されます
|
30
27
|
・管理小説以外にもテキストファイルを変換出来ます。
|
31
28
|
テキストファイルのファイルパスを指定します。
|
32
29
|
※複数指定した場合に-oオプションがあった場合、ファイル名に連番がつきます。
|
33
30
|
・MOBI化する場合は narou setting device=kindle をして下さい。
|
34
31
|
・device=kobo の場合、.kepub.epub を出力します。
|
35
32
|
|
36
|
-
|
33
|
+
Examples:
|
37
34
|
narou convert n9669bk
|
38
35
|
narou convert http://ncode.syosetu.com/n9669bk/
|
39
36
|
narou convert 異世界迷宮で奴隷ハーレムを
|
@@ -68,9 +65,12 @@ module Command
|
|
68
65
|
@opt.on("-i", "--inspect", "小説状態の調査結果を表示する") {
|
69
66
|
@options["inspect"] = true
|
70
67
|
}
|
71
|
-
@opt.on("-v", "--verbose", "AozoraEpub3, kindlegen
|
68
|
+
@opt.on("-v", "--verbose", "AozoraEpub3, kindlegen の標準出力を全て表示する") {
|
72
69
|
@options["verbose"] = true
|
73
70
|
}
|
71
|
+
@opt.on("--ignore-force", "settingコマンドのforce系設定を無視する") {
|
72
|
+
@options["ignore-force"] = true
|
73
|
+
}
|
74
74
|
@opt.separator <<-EOS
|
75
75
|
|
76
76
|
Configuration:
|
@@ -82,7 +82,6 @@ module Command
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def execute(argv)
|
85
|
-
load_local_settings # @opt.on 実行前に設定ロードしたいので super 前で実行する
|
86
85
|
super
|
87
86
|
if argv.empty?
|
88
87
|
puts @opt.help
|
@@ -103,13 +102,13 @@ module Command
|
|
103
102
|
end
|
104
103
|
end
|
105
104
|
@device = Narou.get_device
|
106
|
-
|
107
|
-
|
108
|
-
end
|
105
|
+
self.extend(@device.get_hook_module) if @device
|
106
|
+
hook_call(:change_settings)
|
109
107
|
convert_novels(argv)
|
110
108
|
end
|
111
109
|
|
112
110
|
def convert_novels(argv)
|
111
|
+
tagname_to_ids(argv)
|
113
112
|
argv.each.with_index(1) do |target, i|
|
114
113
|
Helper.print_horizontal_rule if i > 1
|
115
114
|
if @basename
|
@@ -126,17 +125,18 @@ module Command
|
|
126
125
|
error "#{target} は存在しません"
|
127
126
|
next
|
128
127
|
end
|
129
|
-
res = NovelConverter.convert(target,
|
128
|
+
res = NovelConverter.convert(target, {
|
129
|
+
output_filename: @output_filename,
|
130
|
+
display_inspector: @options["inspect"],
|
131
|
+
ignore_force: @options["ignore-force"],
|
132
|
+
})
|
133
|
+
@novel_data = Downloader.get_data_by_target(target)
|
130
134
|
end
|
131
135
|
next unless res
|
132
136
|
@converted_txt_path = res[:converted_txt_path]
|
133
137
|
@use_dakuten_font = res[:use_dakuten_font]
|
134
138
|
|
135
|
-
|
136
|
-
ebook_file = archive_ibunko_zipfile
|
137
|
-
else
|
138
|
-
ebook_file = convert_txt_to_ebook_file
|
139
|
-
end
|
139
|
+
ebook_file = hook_call(:convert_txt_to_ebook_file)
|
140
140
|
next if ebook_file.nil?
|
141
141
|
if ebook_file
|
142
142
|
copied_file_path = copy_to_converted_file(ebook_file)
|
@@ -173,7 +173,12 @@ module Command
|
|
173
173
|
# 直接指定されたテキストファイルを変換する
|
174
174
|
#
|
175
175
|
def convert_txt(target)
|
176
|
-
return NovelConverter.convert_file(target,
|
176
|
+
return NovelConverter.convert_file(target, {
|
177
|
+
encoding: @enc,
|
178
|
+
output_filename: @output_filename,
|
179
|
+
display_inspector: @options["inspect"],
|
180
|
+
ignore_force: @options["ignore-force"],
|
181
|
+
})
|
177
182
|
rescue ArgumentError => e
|
178
183
|
if e.message =~ /invalid byte sequence in UTF-8/
|
179
184
|
error "テキストファイルの文字コードがUTF-8ではありません。" +
|
@@ -231,63 +236,6 @@ module Command
|
|
231
236
|
return mobi_path
|
232
237
|
end
|
233
238
|
|
234
|
-
#
|
235
|
-
# i文庫用にテキストと挿絵ファイルをzipアーカイブ化する
|
236
|
-
#
|
237
|
-
def archive_ibunko_zipfile
|
238
|
-
return false if @options["no-zip"]
|
239
|
-
require "zip"
|
240
|
-
Zip.unicode_names = true
|
241
|
-
dirpath = File.dirname(@converted_txt_path)
|
242
|
-
translate_illust_chuki_to_img_tag
|
243
|
-
zipfile_path = @converted_txt_path.sub(/.txt$/, @device.ebook_file_ext)
|
244
|
-
File.delete(zipfile_path) if File.exists?(zipfile_path)
|
245
|
-
Zip::File.open(zipfile_path, Zip::File::CREATE) do |zip|
|
246
|
-
zip.add(File.basename(@converted_txt_path), @converted_txt_path)
|
247
|
-
illust_dirpath = File.join(dirpath, Illustration::ILLUST_DIR)
|
248
|
-
# 挿絵
|
249
|
-
if File.exists?(illust_dirpath)
|
250
|
-
Dir.glob(File.join(illust_dirpath, "*")) do |img_path|
|
251
|
-
zip.add(File.join(Illustration::ILLUST_DIR, File.basename(img_path)), img_path)
|
252
|
-
end
|
253
|
-
end
|
254
|
-
# 表紙画像
|
255
|
-
cover_name = NovelConverter.get_cover_filename(dirpath)
|
256
|
-
if cover_name
|
257
|
-
zip.add(cover_name, File.join(dirpath, cover_name))
|
258
|
-
end
|
259
|
-
end
|
260
|
-
puts File.basename(zipfile_path) + " を出力しました"
|
261
|
-
puts "<bold><green>#{@device.display_name}用ファイルを出力しました</green></bold>".termcolor
|
262
|
-
return zipfile_path
|
263
|
-
end
|
264
|
-
|
265
|
-
#
|
266
|
-
# i文庫用に設定を強制設定する
|
267
|
-
#
|
268
|
-
def change_settings_for_ibunko
|
269
|
-
settings = LocalSetting.get["local_setting"]
|
270
|
-
modified = false
|
271
|
-
%w(enable_half_indent_bracket enable_dakuten_font).each do |word|
|
272
|
-
name = "force.#{word}"
|
273
|
-
if settings[name].nil? || settings[name] == true
|
274
|
-
settings[name] = false
|
275
|
-
puts "#{name} を#{@device.display_name}用に false に強制変更しました"
|
276
|
-
modified = true
|
277
|
-
end
|
278
|
-
end
|
279
|
-
LocalSetting.get.save_settings("local_setting") if modified
|
280
|
-
end
|
281
|
-
|
282
|
-
#
|
283
|
-
# i文庫用に挿絵注記をimgタグに変換する
|
284
|
-
#
|
285
|
-
def translate_illust_chuki_to_img_tag
|
286
|
-
data = File.read(@converted_txt_path, encoding: Encoding::UTF_8)
|
287
|
-
data.gsub!(/[#挿絵((.+?))入る]/, "<img src=\"\\1\">")
|
288
|
-
File.write(@converted_txt_path, data)
|
289
|
-
end
|
290
|
-
|
291
239
|
#
|
292
240
|
# convert.copy_to で指定されたディレクトリに書籍データをコピーする
|
293
241
|
#
|
data/lib/command/diff.rb
CHANGED
@@ -9,41 +9,46 @@ require "open3"
|
|
9
9
|
require_relative "../downloader"
|
10
10
|
require_relative "../database"
|
11
11
|
require_relative "../template"
|
12
|
-
require_relative "../
|
12
|
+
require_relative "../inventory"
|
13
13
|
require_relative "../helper"
|
14
14
|
|
15
15
|
module Command
|
16
16
|
class Diff < CommandBase
|
17
|
-
def oneline_help
|
18
|
-
"
|
17
|
+
def self.oneline_help
|
18
|
+
"更新された小説の差分を表示します"
|
19
19
|
end
|
20
20
|
|
21
21
|
def initialize
|
22
|
-
super("[<target>] [options
|
22
|
+
super("[<target>] [options]")
|
23
23
|
@opt.separator <<-EOS
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
・指定した小説の更新前後の変更点の差分を表示します。
|
26
|
+
・対象小説を指定しなかった場合は直前に更新した小説の差分を表示します。
|
27
|
+
・もし自分の好きな差分表示プログラムを使いたい場合、difftoolを設定して変更することが出来ます(下記参照)
|
27
28
|
|
28
|
-
|
29
|
-
narou diff #
|
29
|
+
Examples:
|
30
|
+
narou diff # 直前に更新した小説の差分を表示
|
30
31
|
narou diff 6
|
31
32
|
narou diff 6 -n 2 # 最新から2番目の差分との比較
|
32
33
|
narou diff 6 -2 # -n 2 の省略した記述方法
|
33
|
-
narou diff 6 2013.02.21@01
|
34
|
+
narou diff 6 2013.02.21@01.39.46 # 差分を直接指定
|
35
|
+
narou diff 6 -l # 過去にどの話数の差分があるのかを確認
|
34
36
|
|
35
|
-
#
|
36
|
-
narou
|
37
|
+
# 自分の好きな差分表示プログラムを使う場合
|
38
|
+
narou s difftool="C:\\Program Files\\WinMerge\\WinMergeU.exe"
|
39
|
+
narou s difftool=colordiff # コマンドラインツールを指定したり
|
40
|
+
# Narou.rbオリジナルの差分表示に戻す場合は設定を削除する
|
41
|
+
narou s difftool=
|
37
42
|
|
38
43
|
# difftoolに渡す引数(指定しなければ単純に新旧ファイルを引数に呼び出す)
|
39
|
-
# 特殊な変数 %NEW :
|
44
|
+
# 特殊な変数 %NEW : 最新データの差分用ファイルパス
|
40
45
|
# %OLD : 古い方の差分用ファイルパス
|
41
|
-
narou
|
46
|
+
narou s difftool.arg='-e -x -ub -dl "OLD" -dr "NEW" %OLD %NEW'
|
47
|
+
narou s difftool.arg="-u %OLD %NEW"
|
42
48
|
|
43
49
|
Options:
|
44
50
|
EOS
|
45
51
|
|
46
|
-
@options["number"] = 1
|
47
52
|
@opt.on("-n NUM", "--number", "比較する差分を遡って指定する。最新のアップデートと直前のデータを比較するなら-n 1、2個前のアップデートなら-n 2。(デフォルトは-n 1)", Integer) { |number|
|
48
53
|
@options["number"] = number if number > 1
|
49
54
|
}
|
@@ -72,6 +77,7 @@ module Command
|
|
72
77
|
def execute(argv)
|
73
78
|
short_number_option_parse(argv)
|
74
79
|
super
|
80
|
+
@options["number"] = 1 unless @options["number"]
|
75
81
|
if argv.empty?
|
76
82
|
latest = Database.instance.sort_by_last_update.first
|
77
83
|
return unless latest
|
@@ -87,7 +93,7 @@ module Command
|
|
87
93
|
view_diff_version = argv.shift
|
88
94
|
if view_diff_version
|
89
95
|
if invalid_diff_version_string?(view_diff_version)
|
90
|
-
error "差分指定の書式が違います(正しい例:2013.02.21@01
|
96
|
+
error "差分指定の書式が違います(正しい例:2013.02.21@01.39.46)"
|
91
97
|
return
|
92
98
|
end
|
93
99
|
@options["view_diff_version"] = view_diff_version
|
@@ -104,16 +110,18 @@ module Command
|
|
104
110
|
clean_all_diff
|
105
111
|
return
|
106
112
|
end
|
107
|
-
@difftool =
|
113
|
+
@difftool = Inventory.load("global_setting", :global)["difftool"]
|
108
114
|
unless @difftool
|
109
|
-
|
115
|
+
display_diff_on_oneself(id)
|
110
116
|
return
|
117
|
+
#error "difftool が設定されていません。narou setting で difftool を設定して下さい"
|
118
|
+
#return
|
111
119
|
end
|
112
120
|
exec_difftool(id)
|
113
121
|
end
|
114
122
|
|
115
123
|
def invalid_diff_version_string?(str)
|
116
|
-
str !~ /^\d{4}\.\d{2}\.\d{2}@\d{2}
|
124
|
+
str !~ /^\d{4}\.\d{2}\.\d{2}@\d{2}[;.]\d{2}[;.]\d{2}$/
|
117
125
|
end
|
118
126
|
|
119
127
|
def clean_diff(id)
|
@@ -137,26 +145,26 @@ module Command
|
|
137
145
|
%!"#{path}"!
|
138
146
|
})
|
139
147
|
begin
|
140
|
-
res =
|
148
|
+
res = Helper::AsyncCommand.exec(diff_cmd)
|
141
149
|
rescue Errno::ENOENT => e
|
142
150
|
error e.message
|
143
151
|
exit 1
|
144
152
|
ensure
|
145
|
-
temp_paths.
|
153
|
+
temp_paths.map(&:delete)
|
146
154
|
end
|
147
155
|
puts res[0] unless res[0].empty?
|
148
156
|
error res[1] unless res[1].empty?
|
149
157
|
end
|
150
158
|
|
151
|
-
def create_difftool_command_string(
|
152
|
-
diff_arg =
|
159
|
+
def create_difftool_command_string(temp_old_path, temp_new_path)
|
160
|
+
diff_arg = Inventory.load("global_setting", :global)["difftool.arg"]
|
153
161
|
diff_cmd = %!"#{@difftool}" !
|
154
162
|
if diff_arg
|
155
|
-
diff_arg.gsub!("%
|
156
|
-
diff_arg.gsub!("%
|
163
|
+
diff_arg.gsub!("%OLD", temp_old_path)
|
164
|
+
diff_arg.gsub!("%NEW", temp_new_path)
|
157
165
|
diff_cmd += diff_arg
|
158
166
|
else
|
159
|
-
diff_cmd += [
|
167
|
+
diff_cmd += [temp_old_path, temp_new_path].join(" ")
|
160
168
|
end
|
161
169
|
diff_cmd
|
162
170
|
end
|
@@ -176,7 +184,7 @@ module Command
|
|
176
184
|
else
|
177
185
|
nth = @options["number"]
|
178
186
|
list = get_sorted_cache_list(id)
|
179
|
-
cache_dir = list[nth - 1]
|
187
|
+
cache_dir = list ? list[nth - 1] : nil
|
180
188
|
end
|
181
189
|
unless cache_dir
|
182
190
|
puts "差分データがありません"
|
@@ -199,18 +207,28 @@ module Command
|
|
199
207
|
end
|
200
208
|
|
201
209
|
novel_info = Database.instance[id]
|
210
|
+
temp_old = create_temp_by_sections("old", cache_sections, novel_info)
|
211
|
+
temp_new = create_temp_by_sections("new", latest_novel_sections, novel_info)
|
202
212
|
|
203
|
-
|
204
|
-
|
205
|
-
temp_new.write(Template.get("diff.txt", binding))
|
206
|
-
temp_new.close
|
207
|
-
|
208
|
-
sections = cache_sections
|
209
|
-
temp_old = Tempfile.open(["old", ".txt"])
|
210
|
-
temp_old.write(Template.get("diff.txt", binding))
|
211
|
-
temp_old.close
|
213
|
+
[temp_old, temp_new]
|
214
|
+
end
|
212
215
|
|
213
|
-
|
216
|
+
def create_temp_by_sections(temp_prefix, sections, novel_info)
|
217
|
+
html = HTML.new
|
218
|
+
sections.each do |section|
|
219
|
+
element = section["element"]
|
220
|
+
data_type = element.delete("data_type") || "text"
|
221
|
+
element.each do |text_type, elm_text|
|
222
|
+
if data_type == "html"
|
223
|
+
html.string = elm_text
|
224
|
+
element[text_type] = html.to_aozora
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
temp = Tempfile.open([temp_prefix, ".txt"])
|
229
|
+
temp.write(Template.get("diff.txt", binding))
|
230
|
+
temp.close
|
231
|
+
temp
|
214
232
|
end
|
215
233
|
|
216
234
|
def display_diff_list(id)
|
@@ -245,5 +263,18 @@ module Command
|
|
245
263
|
puts "#{data["title"]} の差分を削除しました"
|
246
264
|
end
|
247
265
|
end
|
266
|
+
|
267
|
+
#
|
268
|
+
# diff-lcs を使って自力で差分表示
|
269
|
+
#
|
270
|
+
def display_diff_on_oneself(id)
|
271
|
+
require_relative "../diffviewer"
|
272
|
+
temp_paths = create_temp_files(id) or return
|
273
|
+
title = Database.instance.get_data("id", id)["title"]
|
274
|
+
puts "#{title} の差分を表示します"
|
275
|
+
DiffViewer.new(*temp_paths).view
|
276
|
+
ensure
|
277
|
+
temp_paths.map(&:delete) if temp_paths
|
278
|
+
end
|
248
279
|
end
|
249
280
|
end
|
data/lib/command/download.rb
CHANGED
@@ -8,7 +8,7 @@ require_relative "../downloader"
|
|
8
8
|
|
9
9
|
module Command
|
10
10
|
class Download < CommandBase
|
11
|
-
SUPPORT_NOVEL_SITES = %w(
|
11
|
+
SUPPORT_NOVEL_SITES = %w(小説家になろう(小説を読もう) ノクターンノベルズ ムーンライトノベルズ Arcadia ハーメルン 暁)
|
12
12
|
|
13
13
|
def initialize
|
14
14
|
super("[<target> <target2> ...] [options]")
|
@@ -16,13 +16,13 @@ module Command
|
|
16
16
|
|
17
17
|
・ダウンロードしたい小説のNコードもしくはURLを指定して下さい。
|
18
18
|
・対応サイトは#{SUPPORT_NOVEL_SITES.join("、")}です。
|
19
|
-
|
19
|
+
・ArcadiaのURLを入力するときは" "で囲って下さい。
|
20
20
|
・ダウンロード終了後に変換処理を行います。ダウンロードのみする場合は-nオプションを指定して下さい。
|
21
21
|
・すでにダウンロード済みの小説の場合は何もしません。
|
22
22
|
・--remove オプションをつけてダウンロードすると、ダウンロード(とその後の変換、送信)が終わったあと削除します。データベースのインデックスを外すだけなので、変換した書籍データは残ったままになります。ファイルを全て消す場合は手動で削除する必要があります。
|
23
23
|
・NコードもURLも指定しなかった場合、対話モード移行します。
|
24
24
|
|
25
|
-
|
25
|
+
Examples:
|
26
26
|
narou download n9669bk
|
27
27
|
narou download http://ncode.syosetu.com/n9669bk/
|
28
28
|
narou download n9669bk http://ncode.syosetu.com/n4259s/
|
@@ -95,6 +95,7 @@ module Command
|
|
95
95
|
return if targets.count == 0
|
96
96
|
argv += targets
|
97
97
|
end
|
98
|
+
tagname_to_ids(argv)
|
98
99
|
argv.each.with_index(1) do |target, i|
|
99
100
|
download_target ||= target
|
100
101
|
Helper.print_horizontal_rule if i > 1
|
@@ -131,7 +132,7 @@ module Command
|
|
131
132
|
end
|
132
133
|
end
|
133
134
|
|
134
|
-
def oneline_help
|
135
|
+
def self.oneline_help
|
135
136
|
"指定した小説をダウンロードします"
|
136
137
|
end
|
137
138
|
end
|