Skip to content

Instantly share code, notes, and snippets.

@PythonCoderAS
Created June 16, 2022 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PythonCoderAS/2a9f8c7adf4657ca60c2eb115f444c27 to your computer and use it in GitHub Desktop.
Save PythonCoderAS/2a9f8c7adf4657ca60c2eb115f444c27 to your computer and use it in GitHub Desktop.
A script to convert my existing manga directories to one compatible with komga

This isn't really going to be useful for anyone else. But if you have a comic/manga collection where every series is stored in a directory that contains directories representing each chapter of the series, and you want to turn those directories into .cbz files, this may be of some use for you.

from os import listdir, makedirs
from os.path import abspath, expanduser, isdir, join
from zipfile import ZIP_DEFLATED, ZipFile
from tqdm import tqdm
BASE = abspath(expanduser("~/Manga/downloaded-manga"))
KOMGA_BASE = abspath(expanduser("~/Manga/downloaded-manga-komga"))
for manga in tqdm(listdir(BASE), desc="Manga"):
manga_base = join(BASE, manga)
if not isdir(manga_base):
continue
komga_manga_base = join(KOMGA_BASE, manga)
makedirs(komga_manga_base, exist_ok=True)
for chapter in tqdm(listdir(manga_base), desc="Chapters", leave=False):
chapter_base = join(manga_base, chapter)
if not isdir(chapter_base):
continue
zipfile = ZipFile(join(komga_manga_base, chapter)[:250] + ".cbz", mode="w", compression=ZIP_DEFLATED)
for file in tqdm(listdir(chapter_base), desc="Files", leave=False):
zipfile.write(join(chapter_base, file), file)
zipfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment