Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion lib/novelconverter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def convert_main_for_novel(subtitles = nil, is_hotentry = false)
end
if is_hotentry == false && @setting.slice_size > 0 && subtitles.length > @setting.slice_size
stream_io.puts "#{@setting.slice_size}話ごとに分割して変換します"
array_of_subtitles = subtitles.each_slice(@setting.slice_size).to_a
array_of_subtitles = slice_subtitles(subtitles, @setting.slice_size)
else
array_of_subtitles = [subtitles]
end
Expand Down Expand Up @@ -685,6 +685,30 @@ def cut_subtitles(subtitles)
result
end

#
# subtitleをslice_sizeごとに分割する
# 分割先頭のchapter/subchapterが空なら更新する
#
def slice_subtitles(subtitles, slice_size)
result = subtitles.each_slice(slice_size).to_a

last_chapter = ''
last_subchapter = ''

result.each do |sliced_subtitles|
sliced_subtitles[0]['chapter'] = last_chapter if ! last_chapter.empty?
sliced_subtitles[0]['subchapter'] = last_subchapter if ! last_subchapter.empty?

sliced_subtitles.each do |chapter|
last_chapter = chapter['chapter'] if ! chapter['chapter'].empty?
last_subchapter = chapter['subchapter'] if ! chapter['subchapter'].empty?
end
end

result

end

#
# subtitle info から変換処理をする
#
Expand All @@ -700,6 +724,8 @@ def subtitles_to_sections(subtitles, html)
section = load_novel_section(subinfo, section_save_dir)
if section["chapter"].length > 0
section["chapter"] = @converter.convert(section["chapter"], "chapter")
elsif ! subinfo["chapter"].empty?
section["chapter"] = @converter.convert(subinfo["chapter"], "chapter")
end

@inspector.subtitle = section["subtitle"]
Expand Down