Removes input_pdf and initial work on article download

This commit is contained in:
Nemo 2020-06-30 14:18:16 +05:30
parent 04a2fe52ec
commit f04e9b799e
5 changed files with 32 additions and 29 deletions

View File

@ -1,18 +1,18 @@
version: 1.0
version: 2.0
shards:
crest:
github: mamantoha/crest
git: https://github.com/mamantoha/crest.git
version: 0.25.1
http-client-digest_auth:
github: mamantoha/http-client-digest_auth
git: https://github.com/mamantoha/http-client-digest_auth.git
version: 0.4.0
myhtml:
github: kostya/myhtml
git: https://github.com/kostya/myhtml.git
version: 1.5.1
webmock:
github: manastech/webmock.cr
commit: bb3eab30f6c7d1fdc0a7ff14cd136d68e860d1a7
git: https://github.com/manastech/webmock.cr.git
version: 0.13.0+git.commit.bb3eab30f6c7d1fdc0a7ff14cd136d68e860d1a7

View File

@ -3,5 +3,11 @@ require "./issue.cr"
module Muse::Dl
class Article
@id : String
def initialize(id : String)
@id = id
@url = "https://muse.jhu.edu/article/#{id}"
end
end
end

View File

@ -98,7 +98,7 @@ module Muse::Dl
end
def self.get_info(url : String)
match = /https:\/\/muse.jhu.edu\/(book|journal)\/(\d+)/.match url
match = /https:\/\/muse.jhu.edu\/(book|journal|issue|article)\/(\d+)/.match url
if match
begin
response = Crest.get(url).to_s
@ -107,6 +107,10 @@ module Muse::Dl
return Muse::Dl::Book.new response
when "journal"
return Muse::Dl::Journal.new response
when "issue"
return Muse::Dl::Issue.new response
when "article"
return Muse::Dl::Article.new match[2]
end
rescue ex : Crest::NotFound
raise Muse::Dl::Errors::InvalidLink.new("Error - could not download url: #{url}")

View File

@ -30,7 +30,6 @@ module Muse::Dl
temp_stitched_file = nil
pdf_builder = Pdftk.new(parser.tmp)
unless parser.input_pdf
# Save each chapter
thing.chapters.each do |chapter|
begin
@ -45,10 +44,6 @@ module Muse::Dl
# Stitch the PDFs together
temp_stitched_file = pdf_builder.stitch chapter_ids
pdf_builder.add_metadata(temp_stitched_file, parser.output, thing)
else
x = parser.input_pdf
pdf_builder.add_metadata(File.open(x), parser.output, thing) if x
end
temp_stitched_file.delete if temp_stitched_file
puts "--dont-strip-first-page was on. Please validate PDF file for any errors." if parser.strip_first
@ -60,6 +55,8 @@ module Muse::Dl
Fetch.cleanup(parser.tmp, c[0])
end
end
elsif thing.is_a? Muse::Dl::Article
puts(thing)
end
end

View File

@ -10,7 +10,6 @@ module Muse::Dl
@strip_first = true
@output = DEFAULT_FILE_NAME
@url : String | Nil
@input_pdf : String | Nil
@clobber = false
@input_list : String | Nil
@cookie : String | Nil
@ -18,7 +17,7 @@ module Muse::Dl
DEFAULT_FILE_NAME = "tempfilename.pdf"
getter :bookmarks, :tmp, :cleanup, :output, :url, :input_pdf, :clobber, :input_list, :cookie, :strip_first
getter :bookmarks, :tmp, :cleanup, :output, :url, :clobber, :input_list, :cookie, :strip_first
setter :url
# Update the output filename unless we have a custom one passed
@ -41,7 +40,6 @@ module Muse::Dl
def initialize(arg : Array(String) = [] of String)
@tmp = Dir.tempdir
@input_pdf = nil
parser = OptionParser.new
parser.banner = <<-EOT
@ -56,7 +54,6 @@ module Muse::Dl
parser.on(long_flag = "--tmp-dir PATH", description = "Temporary Directory to use") { |path| @tmp = path }
parser.on(long_flag = "--output FILE", description = "Output Filename") { |file| @output = file }
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 }
@ -70,7 +67,6 @@ module Muse::Dl
end
if File.exists? args[0]
@input_list = args[0]
@input_pdf = nil
else
@url = args[0]
end