mirror of https://github.com/captn3m0/muse-dl.git
Adds a skip-open-access flag
This commit is contained in:
parent
62e6a21c84
commit
3a2d45fb6e
|
@ -10,5 +10,10 @@ module Muse::Dl
|
|||
@id = id
|
||||
@url = "https://muse.jhu.edu/article/#{id}"
|
||||
end
|
||||
|
||||
# TODO: Fix this
|
||||
def open_access
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,6 +24,13 @@ module Muse::Dl
|
|||
@info = Hash(String, String).new
|
||||
end
|
||||
|
||||
def open_access
|
||||
if @info.has_key? "Open Access"
|
||||
return @info["Open Access"] == "Yes"
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
def parse(html : String)
|
||||
h = Myhtml::Parser.new html
|
||||
@info = InfoParser.infobox(h)
|
||||
|
|
|
@ -19,6 +19,13 @@ module Muse::Dl
|
|||
parse_volumes(h)
|
||||
end
|
||||
|
||||
def open_access
|
||||
if @info.has_key? "Open Access"
|
||||
return @info["Open Access"] == "Yes"
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
def parse_volumes(myhtml : Myhtml::Parser)
|
||||
myhtml.css("#available_issues_list_text a").each do |a|
|
||||
link = a.attribute_by("href").to_s
|
||||
|
|
|
@ -15,6 +15,11 @@ module Muse::Dl
|
|||
thing = Fetch.get_info(url) if url
|
||||
return unless thing
|
||||
|
||||
if (thing.open_access) && (parser.skip_oa)
|
||||
STDERR.puts "Skipping #{url}, available under Open Access"
|
||||
return
|
||||
end
|
||||
|
||||
if thing.is_a? Muse::Dl::Book
|
||||
unless thing.formats.includes? :pdf
|
||||
STDERR.puts "Book not available in PDF format, skipping: #{url}"
|
||||
|
|
|
@ -14,10 +14,11 @@ module Muse::Dl
|
|||
@input_list : String | Nil
|
||||
@cookie : String | Nil
|
||||
@h : Bool | Nil
|
||||
@skip_oa = false
|
||||
|
||||
DEFAULT_FILE_NAME = "tempfilename.pdf"
|
||||
|
||||
getter :bookmarks, :tmp, :cleanup, :output, :url, :clobber, :input_list, :cookie, :strip_first
|
||||
getter :bookmarks, :tmp, :cleanup, :output, :url, :clobber, :input_list, :cookie, :strip_first, :skip_oa
|
||||
setter :url
|
||||
|
||||
# Update the output filename unless we have a custom one passed
|
||||
|
@ -57,6 +58,7 @@ module Muse::Dl
|
|||
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(long_flag = "--skip-open-access", description = "Don't download open access content") { @skip_oa = true }
|
||||
parser.on("-h", "--help", "Show this help") { @h = true; puts parser }
|
||||
|
||||
parser.unknown_args do |args|
|
||||
|
|
|
@ -19,6 +19,13 @@ module Muse::Dl
|
|||
|
||||
private getter :h
|
||||
|
||||
def open_access
|
||||
if @info.has_key? "Open Access"
|
||||
return @info["Open Access"] == "Yes"
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
def initialize(html : String)
|
||||
@h = Myhtml::Parser.new html
|
||||
@info = InfoParser.infobox(h)
|
||||
|
|
Loading…
Reference in New Issue