Created
August 15, 2022 15:42
-
-
Save lennyRBLX/51dfb1b8c01d4026e1c3aa8e2ce9016d to your computer and use it in GitHub Desktop.
Merges Tachiyomi CBZ chapters. Requires Lua 5.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("zip") | |
-- credits: https://stackoverflow.com/questions/2829175/how-to-extract-files-from-a-zip-file-using-lua | |
function extract(zipPath, zipFilename, destinationPath) | |
local zfile, err = zip.open(zipPath .. zipFilename) | |
-- iterate through each file insize the zip file | |
for file in zfile:files() do | |
local currFile, err = zfile:open(file.filename) | |
local currFileContents = currFile:read("*a") -- read entire contents of current file | |
local hBinaryOutput = io.open(destinationPath .. file.filename, "wb") | |
-- write current file inside zip to a file outside zip | |
if(hBinaryOutput)then | |
hBinaryOutput:write(currFileContents) | |
hBinaryOutput:close() | |
end | |
currFile:close() | |
end | |
zfile:close() | |
end | |
os.execute("if not exist \"final\" mkdir final") | |
local files = io.popen('dir /B') | |
local list = { } | |
local count = nil | |
for filename in files:lines() do | |
if filename:find('cbz') then | |
local zfile = zip.open(filename) | |
if zfile then | |
local pngs = {} | |
for png in zfile:files() do | |
if png.filename:find("png") then | |
if count == nil then | |
count = tonumber(png.filename:match("%d+")) | |
end | |
pngs[png.filename] = tostring(count) .. ".png" | |
count = count + 1 | |
end | |
end | |
list[filename] = pngs | |
zfile:close() | |
end | |
end | |
end | |
for filename, pngs in pairs(list) do | |
extract("", filename, "final\\") | |
for old, new in pairs(pngs) do | |
os.rename("final\\" .. old, "final\\" .. new) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment