mirror of
https://github.com/TangentFoxy/.lua-files.git
synced 2024-11-20 21:34:23 +00:00
Compare commits
No commits in common. "da812cb201571108f02459f263500de655faded3" and "15013d02feffde90af2ad464ec48537c97319181" have entirely different histories.
da812cb201
...
15013d02fe
@ -37,9 +37,6 @@ will be used to make multiple ebooks back-to-back.
|
|||||||
directories.
|
directories.
|
||||||
cleanall: Deletes everything except the config file and ePub.
|
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:
|
Requirements:
|
||||||
- Binaries: pandoc, curl
|
- Binaries: pandoc, curl
|
||||||
```
|
```
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
local help = [[Usage:
|
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
|
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.
|
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.
|
directories.
|
||||||
cleanall: Deletes everything except the config file and ePub.
|
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:
|
Requirements:
|
||||||
- Binaries: pandoc, curl
|
- Binaries: pandoc, curl
|
||||||
|
|
||||||
@ -37,7 +34,7 @@ if not success then
|
|||||||
end
|
end
|
||||||
|
|
||||||
local path_separator = utility.path_separator
|
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!
|
-- 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)
|
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
|
config.base_url = config.first_section_url -- prevent errors due to required item being missing
|
||||||
end
|
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
|
-- detecting manually specified sections and flagging it to the rest of the script
|
||||||
if config.sections[1] then
|
if config.sections[1] then
|
||||||
config.sections.start = 1
|
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
|
config.sections.start = 1 -- the first one can be optional since the common use case is ALL OF THEM
|
||||||
end
|
end
|
||||||
|
|
||||||
if not config.sections.finish then
|
|
||||||
config.sections.finish = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if #config.page_counts ~= config.sections.finish - config.sections.start + 1 then
|
if #config.page_counts ~= config.sections.finish - config.sections.start + 1 then
|
||||||
error("Number of page_counts does not match number of sections.")
|
error("Number of page_counts does not match number of sections.")
|
||||||
end
|
end
|
||||||
@ -129,7 +118,6 @@ local function format_metadata(config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function download_pages(config)
|
local function download_pages(config)
|
||||||
print("\nDownloading pages...\n")
|
|
||||||
local htmlparser = utility.require("htmlparser")
|
local htmlparser = utility.require("htmlparser")
|
||||||
utility.required_program("curl")
|
utility.required_program("curl")
|
||||||
local working_dir = config.base_file_name
|
local working_dir = config.base_file_name
|
||||||
@ -184,7 +172,6 @@ local function download_pages(config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function convert_pages(config)
|
local function convert_pages(config)
|
||||||
print("\nConverting pages...\n")
|
|
||||||
utility.required_program("pandoc")
|
utility.required_program("pandoc")
|
||||||
local working_dir = config.base_file_name
|
local working_dir = config.base_file_name
|
||||||
|
|
||||||
@ -199,7 +186,6 @@ local function convert_pages(config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function concatenate_pages(config)
|
local function concatenate_pages(config)
|
||||||
print("\nConcatenating pages...\n")
|
|
||||||
local working_dir = config.base_file_name
|
local working_dir = config.base_file_name
|
||||||
|
|
||||||
for section = config.sections.start, config.sections.finish do
|
for section = config.sections.start, config.sections.finish do
|
||||||
@ -234,7 +220,6 @@ local function concatenate_pages(config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function write_markdown_file(config)
|
local function write_markdown_file(config)
|
||||||
print("\nWriting Markdown file...\n")
|
|
||||||
local working_dir = config.base_file_name
|
local working_dir = config.base_file_name
|
||||||
|
|
||||||
utility.open(config.base_file_name .. ".md", "w")(function(markdown_file)
|
utility.open(config.base_file_name .. ".md", "w")(function(markdown_file)
|
||||||
@ -286,7 +271,6 @@ local function write_markdown_file(config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function make_epub(config)
|
local function make_epub(config)
|
||||||
print("\nMaking ePub...\n")
|
|
||||||
utility.required_program("pandoc")
|
utility.required_program("pandoc")
|
||||||
local output_dir = "All ePubs"
|
local output_dir = "All ePubs"
|
||||||
os.execute("mkdir " .. output_dir:enquote())
|
os.execute("mkdir " .. output_dir:enquote())
|
||||||
@ -297,7 +281,6 @@ local function make_epub(config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function rm_page_files(config)
|
local function rm_page_files(config)
|
||||||
print("\nRemoving page files...\n")
|
|
||||||
local working_dir = config.base_file_name
|
local working_dir = config.base_file_name
|
||||||
|
|
||||||
for section = config.sections.start, config.sections.finish do
|
for section = config.sections.start, config.sections.finish do
|
||||||
@ -307,7 +290,6 @@ local function rm_page_files(config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function rm_all(config)
|
local function rm_all(config)
|
||||||
print("\nRemoving all extra files...\n")
|
|
||||||
local working_dir = config.base_file_name
|
local working_dir = config.base_file_name
|
||||||
|
|
||||||
os.execute(utility.recursive_remove_command .. working_dir:enquote())
|
os.execute(utility.recursive_remove_command .. working_dir:enquote())
|
||||||
@ -344,41 +326,32 @@ local function main(arguments)
|
|||||||
cleanpage = rm_page_files,
|
cleanpage = rm_page_files,
|
||||||
cleanall = rm_all,
|
cleanall = rm_all,
|
||||||
}
|
}
|
||||||
local default_action_order = {
|
|
||||||
"download",
|
|
||||||
"convert",
|
|
||||||
"concat",
|
|
||||||
"cleanpage",
|
|
||||||
"markdown",
|
|
||||||
"epub",
|
|
||||||
}
|
|
||||||
|
|
||||||
if arguments.action then
|
if arguments.action then
|
||||||
if actions[arguments.action] then
|
if actions[arguments.action] then
|
||||||
actions[arguments.action](config)
|
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
|
else
|
||||||
print(help)
|
print(help)
|
||||||
error("\nInvalid action specified.")
|
error("\nInvalid action specified.")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
for _, action in ipairs(default_action_order) do
|
print("\nDownloading pages...\n")
|
||||||
actions[action](config)
|
download_pages(config)
|
||||||
end
|
print("\nConverting pages...\n")
|
||||||
end
|
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")
|
print("\nDone!\n")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local positional_arguments = {"json_file_name", "action", "flag"}
|
local positional_arguments = {"json_file_name", "action"}
|
||||||
local arguments = argparse(arg, positional_arguments)
|
local arguments = argparse(arg, positional_arguments)
|
||||||
if not arguments.json_file_name then
|
if not arguments.json_file_name then
|
||||||
print(help)
|
print(help)
|
||||||
|
Loading…
Reference in New Issue
Block a user