Adds support for --dont-strip-first-page
Diff
src/fetch.cr | 4 ++--
src/muse-dl.cr | 3 ++-
src/parser.cr | 5 +++++
src/pdftk.cr | 3 ++-
4 files changed, 10 insertions(+), 5 deletions(-)
@@ -23,7 +23,7 @@
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)
def self.save_chapter(tmp_path : String, chapter_id : String, chapter_title : String, cookie : String | Nil = nil, add_bookmark = true, strip_first_page = true)
final_pdf_file = chapter_file_name chapter_id, tmp_path
tmp_pdf_file = "#{final_pdf_file}.tmp"
@@ -86,7 +86,7 @@
pdftk = Muse::Dl::Pdftk.new tmp_path
pdftk.strip_first_page tmp_pdf_file
pdftk.strip_first_page tmp_pdf_file if strip_first_page
if add_bookmark
@@ -34,7 +34,7 @@
thing.chapters.each do |chapter|
begin
Fetch.save_chapter(parser.tmp, chapter[0], chapter[1], parser.cookie, parser.bookmarks)
Fetch.save_chapter(parser.tmp, chapter[0], chapter[1], parser.cookie, parser.bookmarks, parser.strip_first)
rescue e : Muse::Dl::Errors::MuseCorruptPDF
STDERR.puts "Got a 'Unable to construct chapter PDF' error from MUSE, skipping: #{url}"
return
@@ -51,6 +51,7 @@
end
temp_stitched_file.delete if temp_stitched_file
puts "--dont-strip-first-page was on. Please validate PDF file for any errors."
puts "DL: #{url}. Saved final output to #{parser.output}"
@@ -6,6 +6,8 @@
@bookmarks = true
@tmp : String
@cleanup = true
@strip_first = true
@output = DEFAULT_FILE_NAME
@url : String | Nil
@input_pdf : String | Nil
@@ -16,7 +18,7 @@
DEFAULT_FILE_NAME = "tempfilename.pdf"
getter :bookmarks, :tmp, :cleanup, :output, :url, :input_pdf, :clobber, :input_list, :cookie
getter :bookmarks, :tmp, :cleanup, :output, :url, :input_pdf, :clobber, :input_list, :cookie, :strip_first
setter :url
@@ -56,6 +58,7 @@
parser.on(long_flag = "--no-bookmarks", description = "Don't add bookmarks in the PDF") { @bookmarks = false }
parser.on(long_flag = "--input-pdf INPUT", description = "Input Stitched PDF. Will not download anything") { |input| @input_pdf = input }
parser.on(long_flag = "--clobber", description = "Overwrite the output file, if it already exists. Not compatible with input-pdf") { @clobber = true }
parser.on(long_flag = "--dont-strip-first-page", description = "Disables first page from being stripped. Use carefully") { @strip_first = false }
parser.on(long_flag = "--cookie COOKIE", description = "Cookie-header") { |cookie| @cookie = cookie }
parser.on("-h", "--help", "Show this help") { @h = true; puts parser }
@@ -42,7 +42,8 @@
if is_success
File.rename output_pdf.path, input_file
else
raise Muse::Dl::Errors::PDFOperationError.new("Error stripping first page of chapter.")
puts ("Error stripping first page of chapter. Maybe try using --dont-strip-first-page")
exit 1
end
end