Adds support for --dont-strip-first-page

master
Nemo 3 years ago
parent d245538e33
commit 487b222d79
  1. 4
      src/fetch.cr
  2. 3
      src/muse-dl.cr
  3. 5
      src/parser.cr
  4. 3
      src/pdftk.cr

@ -23,7 +23,7 @@ module Muse::Dl
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 @@ module Muse::Dl
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
# Run pdftk and add the bookmark to the file

@ -34,7 +34,7 @@ module Muse::Dl
# Save each chapter
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 @@ module Muse::Dl
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}"
# Cleanup the chapter files

@ -6,6 +6,8 @@ module Muse::Dl
@bookmarks = true
@tmp : String
@cleanup = true
# Whether to strip the first page
@strip_first = true
@output = DEFAULT_FILE_NAME
@url : String | Nil
@input_pdf : String | Nil
@ -16,7 +18,7 @@ module Muse::Dl
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
# Update the output filename unless we have a custom one passed
@ -56,6 +58,7 @@ module Muse::Dl
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 @@ module Muse::Dl
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

Loading…
Cancel
Save