🏡 index : github.com/captn3m0/muse-dl.git

author Nemo <me@captnemo.in> 2020-05-14 1:04:15.0 +05:30:00
committer Nemo <me@captnemo.in> 2020-05-14 1:04:15.0 +05:30:00
commit
487b222d797450b3343bd6888e6abe25385a433b [patch]
tree
033ce58929ac0b7d01a41556cf7865acdff0b148
parent
d245538e33af5a3809678b10a968878e0fdbc941
download
487b222d797450b3343bd6888e6abe25385a433b.tar.gz

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(-)

diff --git a/src/fetch.cr b/src/fetch.cr
index eece004..004f9e0 100644
--- a/src/fetch.cr
+++ a/src/fetch.cr
@@ -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
        # Run pdftk and add the bookmark to the file
diff --git a/src/muse-dl.cr b/src/muse-dl.cr
index b954222..9b71f65 100644
--- a/src/muse-dl.cr
+++ a/src/muse-dl.cr
@@ -34,7 +34,7 @@
          # 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 @@
        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
diff --git a/src/parser.cr b/src/parser.cr
index 7d96581..658b23b 100644
--- a/src/parser.cr
+++ a/src/parser.cr
@@ -6,6 +6,8 @@
    @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 @@

    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 @@
      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 }

diff --git a/src/pdftk.cr b/src/pdftk.cr
index 6833b5f..961f439 100644
--- a/src/pdftk.cr
+++ a/src/pdftk.cr
@@ -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