Compare commits

..

No commits in common. "da812cb201571108f02459f263500de655faded3" and "15013d02feffde90af2ad464ec48537c97319181" have entirely different histories.

2 changed files with 16 additions and 46 deletions

View File

@ -37,9 +37,6 @@ will be used to make multiple ebooks back-to-back.
directories.
cleanall: Deletes everything except the config file and ePub.
[flag]: If "--continue" is passed, script will continue with the default order
of actions from the action specified.
Requirements:
- Binaries: pandoc, curl
```

View File

@ -2,7 +2,7 @@
local help = [[Usage:
make-epub.lua <config (JSON file)> [action] [flag]
make-epub.lua <config (JSON file)> [action]
If "." is used instead of a JSON file, every JSON file in the current directory
will be used to make multiple ebooks back-to-back.
@ -18,9 +18,6 @@ will be used to make multiple ebooks back-to-back.
directories.
cleanall: Deletes everything except the config file and ePub.
[flag]: If "--continue" is passed, script will continue with the default order
of actions from the action specified.
Requirements:
- Binaries: pandoc, curl
@ -37,7 +34,7 @@ if not success then
end
local path_separator = utility.path_separator
local copyright_warning = "This ebook was created by an automated tool for personal use. It cannot be distributed or sold without permission of its copyright holder(s). (If you did not make this ebook, you may be infringing.)\n\n"
local copyright_warning = "This ebook was created by an automated tool for personal use. It cannot be distributed or sold without permission of copyright holder(s). (If you did not make this ebook, you may be infringing.)\n\n"
-- also checks for errors TODO make it check for ALL required elements and error if any are missing!
local function load_config(config_file_text)
@ -63,10 +60,6 @@ local function load_config(config_file_text)
config.base_url = config.first_section_url -- prevent errors due to required item being missing
end
if not config.sections then
config.sections = {} -- I've decided to allow empty sections (defaults to 1 section, for single story ebooks)
end
-- detecting manually specified sections and flagging it to the rest of the script
if config.sections[1] then
config.sections.start = 1
@ -79,10 +72,6 @@ local function load_config(config_file_text)
config.sections.start = 1 -- the first one can be optional since the common use case is ALL OF THEM
end
if not config.sections.finish then
config.sections.finish = 1
end
if #config.page_counts ~= config.sections.finish - config.sections.start + 1 then
error("Number of page_counts does not match number of sections.")
end
@ -129,7 +118,6 @@ local function format_metadata(config)
end
local function download_pages(config)
print("\nDownloading pages...\n")
local htmlparser = utility.require("htmlparser")
utility.required_program("curl")
local working_dir = config.base_file_name
@ -184,7 +172,6 @@ local function download_pages(config)
end
local function convert_pages(config)
print("\nConverting pages...\n")
utility.required_program("pandoc")
local working_dir = config.base_file_name
@ -199,7 +186,6 @@ local function convert_pages(config)
end
local function concatenate_pages(config)
print("\nConcatenating pages...\n")
local working_dir = config.base_file_name
for section = config.sections.start, config.sections.finish do
@ -234,7 +220,6 @@ local function concatenate_pages(config)
end
local function write_markdown_file(config)
print("\nWriting Markdown file...\n")
local working_dir = config.base_file_name
utility.open(config.base_file_name .. ".md", "w")(function(markdown_file)
@ -286,7 +271,6 @@ local function write_markdown_file(config)
end
local function make_epub(config)
print("\nMaking ePub...\n")
utility.required_program("pandoc")
local output_dir = "All ePubs"
os.execute("mkdir " .. output_dir:enquote())
@ -297,7 +281,6 @@ local function make_epub(config)
end
local function rm_page_files(config)
print("\nRemoving page files...\n")
local working_dir = config.base_file_name
for section = config.sections.start, config.sections.finish do
@ -307,7 +290,6 @@ local function rm_page_files(config)
end
local function rm_all(config)
print("\nRemoving all extra files...\n")
local working_dir = config.base_file_name
os.execute(utility.recursive_remove_command .. working_dir:enquote())
@ -344,41 +326,32 @@ local function main(arguments)
cleanpage = rm_page_files,
cleanall = rm_all,
}
local default_action_order = {
"download",
"convert",
"concat",
"cleanpage",
"markdown",
"epub",
}
if arguments.action then
if actions[arguments.action] then
actions[arguments.action](config)
if arguments.flag == "--continue" then
local starting_point_reached = false
for _, action in ipairs(default_action_order) do
if starting_point_reached then
actions[action](config)
elseif action == arguments.action then
starting_point_reached = true
end
end
end
else
print(help)
error("\nInvalid action specified.")
end
else
for _, action in ipairs(default_action_order) do
actions[action](config)
end
end
print("\nDownloading pages...\n")
download_pages(config)
print("\nConverting pages...\n")
convert_pages(config)
print("\nConcatenating pages...\n")
concatenate_pages(config)
print("\nRemoving page files...\n")
rm_page_files(config)
print("\nWriting Markdown file...\n")
write_markdown_file(config)
print("\nMaking ePub...\n")
make_epub(config)
print("\nDone!\n")
end
end
local positional_arguments = {"json_file_name", "action", "flag"}
local positional_arguments = {"json_file_name", "action"}
local arguments = argparse(arg, positional_arguments)
if not arguments.json_file_name then
print(help)