From c347d8c8c0255e54bfa726980fc9bdd2386a23f5 Mon Sep 17 00:00:00 2001 From: ljoaruma Date: Sun, 19 Apr 2026 12:57:32 +0900 Subject: [PATCH] =?UTF-8?q?slice=5Fsize=E6=8C=87=E5=AE=9A=E6=99=82?= =?UTF-8?q?=E3=80=81=E4=B8=AD=E8=A6=8B=E5=87=BA=E3=81=97=E3=81=8B=E3=82=89?= =?UTF-8?q?=E5=A7=8B=E3=81=BE=E3=82=8B=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/novelconverter.rb | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/novelconverter.rb b/lib/novelconverter.rb index 1c12a469..ec75cae9 100644 --- a/lib/novelconverter.rb +++ b/lib/novelconverter.rb @@ -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 @@ -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 から変換処理をする # @@ -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"]