mirror of https://github.com/captn3m0/muse-dl.git
Support for passing a list of links
This commit is contained in:
parent
220c1efa8d
commit
5ea33ef7b2
|
@ -9,9 +9,10 @@ module Muse::Dl
|
||||||
VERSION = "0.1.0"
|
VERSION = "0.1.0"
|
||||||
|
|
||||||
class Main
|
class Main
|
||||||
def self.run(args : Array(String))
|
def self.dl(parser : Parser)
|
||||||
parser = Parser.new(args)
|
url = parser.url
|
||||||
thing = Fetch.get_info(parser.url)
|
thing = Fetch.get_info(url) if url
|
||||||
|
return unless thing
|
||||||
|
|
||||||
if thing.is_a? Muse::Dl::Book
|
if thing.is_a? Muse::Dl::Book
|
||||||
# Will have no effect if parser has a custom title
|
# Will have no effect if parser has a custom title
|
||||||
|
@ -44,6 +45,20 @@ module Muse::Dl
|
||||||
puts "Saved final output to #{parser.output}"
|
puts "Saved final output to #{parser.output}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.run(args : Array(String))
|
||||||
|
parser = Parser.new(args)
|
||||||
|
|
||||||
|
input_list = parser.input_list
|
||||||
|
if input_list
|
||||||
|
File.each_line input_list do |url|
|
||||||
|
parser.url = url.strip
|
||||||
|
Main.dl parser
|
||||||
|
end
|
||||||
|
elsif parser.url
|
||||||
|
Main.dl parser
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,15 @@ module Muse::Dl
|
||||||
@tmp : String
|
@tmp : String
|
||||||
@cleanup = true
|
@cleanup = true
|
||||||
@output = DEFAULT_FILE_NAME
|
@output = DEFAULT_FILE_NAME
|
||||||
@url = "INVALID_URL"
|
@url : String | Nil
|
||||||
@input_pdf : String | Nil
|
@input_pdf : String | Nil
|
||||||
@clobber = false
|
@clobber = false
|
||||||
|
@input_list : String | Nil
|
||||||
|
|
||||||
DEFAULT_FILE_NAME = "tempfilename.pdf"
|
DEFAULT_FILE_NAME = "tempfilename.pdf"
|
||||||
|
|
||||||
getter :bookmarks, :tmp, :cleanup, :output, :url, :input_pdf, :clobber
|
getter :bookmarks, :tmp, :cleanup, :output, :url, :input_pdf, :clobber, :input_list
|
||||||
|
setter :url
|
||||||
|
|
||||||
# Update the output filename unless we have a custom one passed
|
# Update the output filename unless we have a custom one passed
|
||||||
def output=(output_file : String)
|
def output=(output_file : String)
|
||||||
|
@ -34,13 +36,19 @@ module Muse::Dl
|
||||||
@input_pdf = nil
|
@input_pdf = nil
|
||||||
|
|
||||||
parser = OptionParser.new
|
parser = OptionParser.new
|
||||||
parser.banner = "Usage: muse-dl [--flags] URL"
|
parser.banner = <<-EOT
|
||||||
|
Usage: muse-dl [--flags] [URL|INPUT_FILE]
|
||||||
|
|
||||||
|
URL: A link to a book on the Project MUSE website, eg https://muse.jhu.edu/book/875
|
||||||
|
INPUT_FILE: Path to a file containing a list of links
|
||||||
|
|
||||||
|
EOT
|
||||||
parser.on(long_flag = "--no-cleanup", description = "Don't cleanup temporary files") { @cleanup = false }
|
parser.on(long_flag = "--no-cleanup", description = "Don't cleanup temporary files") { @cleanup = false }
|
||||||
parser.on(long_flag = "--tmp-dir PATH", description = "Temporary Directory to use") { |path| @tmp = path }
|
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 = "--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 = "--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 = "--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") { @clobber = true }
|
parser.on(long_flag = "--clobber", description = "Overwrite the output file, if it already exists. Not compatible with input-pdf") { @clobber = true }
|
||||||
parser.on("-h", "--help", "Show this help") { puts parser }
|
parser.on("-h", "--help", "Show this help") { puts parser }
|
||||||
|
|
||||||
parser.unknown_args do |args|
|
parser.unknown_args do |args|
|
||||||
|
@ -48,7 +56,12 @@ module Muse::Dl
|
||||||
puts parser
|
puts parser
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
@url = args[0]
|
if File.exists? args[0]
|
||||||
|
@input_list = args[0]
|
||||||
|
@input_pdf = nil
|
||||||
|
else
|
||||||
|
@url = args[0]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.invalid_option do |flag|
|
parser.invalid_option do |flag|
|
||||||
|
|
Loading…
Reference in New Issue