Last active
February 21, 2025 20:10
-
-
Save JacquesDuflos/a0e7f4c33c6efeb86450a1b267ca2116 to your computer and use it in GitHub Desktop.
Makes cbz files for each chapter of a manga downloaded form mangakatana.
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
#!/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() |
I'm sorry, I said thank you too fast, where should i put the zip files before using the script ?
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
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you a lot !!!