Skip to content

Instantly share code, notes, and snippets.

@JacquesDuflos
Last active February 16, 2026 06:45
Show Gist options
  • Select an option

  • Save JacquesDuflos/a0e7f4c33c6efeb86450a1b267ca2116 to your computer and use it in GitHub Desktop.

Select an option

Save JacquesDuflos/a0e7f4c33c6efeb86450a1b267ca2116 to your computer and use it in GitHub Desktop.
Makes cbz files for each chapter of a manga downloaded form mangakatana.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import zipfile
'''
this script is ment to turn .zip files downloaded from mangakatana.com to a serie
of .cbz files. The .zip files contain usually 10 chapters of a same manga stored as
a serie of folders.
'''
def main():
# Chemin vers le dossier racine contenant les fichiers .zip
whereiam = os.path.dirname(os.path.abspath(__file__))
dossier_racine = whereiam
# Parcours des fichiers .zip dans le dossier racine
for fichier_zip in os.listdir(dossier_racine):
if fichier_zip.endswith(".zip"):
chemin_zip = os.path.join(dossier_racine, fichier_zip)
# Extraire le nom du chapitre à partir du nom du fichier .zip
nom_chapitre = os.path.splitext(fichier_zip)[0]
nom_serie = "-".join(nom_chapitre.split("_")[:-2])
dossier_cbz = os.path.join(dossier_racine, "cbz")
if not os.path.exists(dossier_cbz):
os.makedirs(dossier_cbz)
try:
count=0
with zipfile.ZipFile(chemin_zip, 'r') as zip_ref:
for dossier in zip_ref.namelist():
if dossier.endswith('/') and dossier != nom_chapitre + "/":
count += 1
nom_sous_dossier = os.path.basename(dossier[:-1])
chemin_cbz = os.path.join(dossier_cbz, f"{nom_serie}_{nom_sous_dossier}.cbz")
with zipfile.ZipFile(chemin_cbz, 'w', compression=zipfile.ZIP_DEFLATED) as cbz:
for fichier in zip_ref.namelist():
if fichier.startswith(dossier):
contenu_fichier = zip_ref.read(fichier)
chemin_fichier_cbz = os.path.join(nom_sous_dossier, os.path.basename(fichier))
cbz.writestr(chemin_fichier_cbz, contenu_fichier)
print(f"Traitement du ZIP terminé : {nom_chapitre}.zip, {count} CBZ générés, {len(os.listdir(dossier_cbz))} total")
except Exception as e:
print(f"Erreur lors de la lecture du fichier ZIP : {chemin_zip}\n{e}")
print("Terminé !")
if __name__ == "__main__":
main()
@MadShield
Copy link
Copy Markdown

Thank you a lot !!!

@MadShield
Copy link
Copy Markdown

I'm sorry, I said thank you too fast, where should i put the zip files before using the script ?

@JacquesDuflos
Copy link
Copy Markdown
Author

I'm sorry, I said thank you too fast, where should i put the zip files before using the script ?

Create an empty folder, put the zip files and the python script in it, execute the script

@ThorondorManwe
Copy link
Copy Markdown

Thanks!

@MercyBundi
Copy link
Copy Markdown

hello what about pdf?

@MadShield
Copy link
Copy Markdown

hello what about pdf?

What do you mean ? would you like to turn a mangakatana download into a pdf ? you can try converting the cbz to pdf

@k37epik
Copy link
Copy Markdown

k37epik commented May 21, 2025

I'm sorry, I said thank you too fast, where should i put the zip files before using the script ?

Create an empty folder, put the zip files and the python script in it, execute the script

how do you execute it?

@k37epik
Copy link
Copy Markdown

k37epik commented May 21, 2025

sorry, i'm dum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment