2020-03-28 19:29:47 +00:00
|
|
|
require "./parser.cr"
|
|
|
|
require "./pdftk.cr"
|
|
|
|
require "./fetch.cr"
|
2020-03-28 19:51:36 +00:00
|
|
|
require "./book.cr"
|
2020-03-28 22:22:57 +00:00
|
|
|
require "./journal.cr"
|
2020-03-29 14:04:51 +00:00
|
|
|
require "./util.cr"
|
2020-03-28 21:07:14 +00:00
|
|
|
|
2020-03-28 19:29:47 +00:00
|
|
|
module Muse::Dl
|
|
|
|
VERSION = "0.1.0"
|
|
|
|
|
2020-03-28 21:07:14 +00:00
|
|
|
class Main
|
2020-03-28 21:14:48 +00:00
|
|
|
def self.run(args : Array(String))
|
|
|
|
parser = Parser.new(args)
|
2020-03-28 22:22:57 +00:00
|
|
|
thing = Fetch.get_info(parser.url)
|
|
|
|
|
|
|
|
if thing.is_a? Muse::Dl::Book
|
2020-03-29 14:04:51 +00:00
|
|
|
# Will have no effect if parser has a custom title
|
|
|
|
parser.output = Util.slug_filename "#{thing.title}.pdf"
|
|
|
|
|
|
|
|
# Save each chapter
|
2020-03-28 22:22:57 +00:00
|
|
|
thing.chapters.each do |chapter|
|
2020-03-29 12:21:01 +00:00
|
|
|
Fetch.save_chapter(parser.tmp, chapter[0], chapter[1], parser.bookmarks)
|
2020-03-28 22:22:57 +00:00
|
|
|
end
|
2020-03-29 12:21:01 +00:00
|
|
|
chapter_ids = thing.chapters.map { |c| c[0] }
|
2020-03-29 14:04:51 +00:00
|
|
|
|
|
|
|
# Stitch the PDFs together
|
2020-03-29 12:21:01 +00:00
|
|
|
pdf_builder = Pdftk.new(parser.tmp)
|
2020-03-29 13:21:07 +00:00
|
|
|
temp_stitched_file = pdf_builder.stitch chapter_ids
|
|
|
|
pdf_builder.add_metadata(temp_stitched_file, parser.output, thing)
|
|
|
|
temp_stitched_file.delete
|
2020-03-29 12:21:01 +00:00
|
|
|
puts "Saved final output to #{parser.output}"
|
2020-03-28 22:22:57 +00:00
|
|
|
end
|
2020-03-28 21:07:14 +00:00
|
|
|
end
|
|
|
|
end
|
2020-03-28 19:29:47 +00:00
|
|
|
end
|
2020-03-28 21:14:48 +00:00
|
|
|
|
|
|
|
Muse::Dl::Main.run(ARGV)
|