Below is what I've cobbled together as the meat of my script:
Code: Select all
def processIssue(dirName=newpath, filename=newfilename):
if str.endswith(dirName + "/" + filename, "cbr"):
filepath = unrar(dirName + "/" + filename)
elif str.endswith(dirName + "/" + filename, "cbz"):
filepath = unzip(dirName + "/" + filename)
removeFilesByMatchingPattern(filepath, "z*.*")
convertImagesToWebP(filepath)
removeFilesByMatchingPattern(filepath, "*.jpg")
removeFilesByMatchingPattern(filepath, "*.png")
filePaths = os.listdir(filepath)
os.remove(filename)
zip_file = ZipFile(filepath+'.cbz', 'w')
with zip_file:
for file in filePaths:
zip_file.write(filepath + "/" + file)
shutil.rmtree(filepath)
def main():
processIssue(os.path.splitext(sys.argv[1])[0], sys.argv[1])
if __name__ == "__main__":
main()