diff --git a/src/fetch.cr b/src/fetch.cr index 9a437de..240ab8b 100644 --- a/src/fetch.cr +++ b/src/fetch.cr @@ -16,6 +16,11 @@ module Muse::Dl "#{tmp_path}/chapter-#{id}.pdf" end + def self.cleanup(tmp_path : String, id : String) + fns = chapter_file_name(id, tmp_path) + File.delete(fns) if File.exists?(fns) + end + def self.save_chapter(tmp_path : String, chapter_id : String, chapter_title : String, cookie : String | Nil = nil, add_bookmark = true) final_pdf_file = chapter_file_name chapter_id, tmp_path tmp_pdf_file = "#{final_pdf_file}.tmp" diff --git a/src/muse-dl.cr b/src/muse-dl.cr index aec1394..a9d244a 100644 --- a/src/muse-dl.cr +++ b/src/muse-dl.cr @@ -47,6 +47,13 @@ module Muse::Dl temp_stitched_file.delete if temp_stitched_file puts "Saved final output to #{parser.output}" + + # Cleanup the chapter files + if parser.cleanup + thing.chapters.each do |c| + Fetch.cleanup(parser.tmp, c[0]) + end + end end end