From 5266dcd41b68415642c187ea0cb53c15579f24ae Mon Sep 17 00:00:00 2001 From: Dhruv Kanojia Date: Thu, 24 Aug 2017 07:19:37 +0530 Subject: [PATCH] Fix for #28 Fix for #28 .Check the ReadMe for details --- Changelog.md | 3 ++- ReadMe.md | 2 +- comic_dl/__version__.py | 2 +- comic_dl/globalFunctions.py | 26 +++++++++++++++++++++++++- docs/Changelog.md | 3 ++- docs/index.md | 2 +- 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Changelog.md b/Changelog.md index 6cf391c..0c21da0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -44,4 +44,5 @@ - Fix for #36 [2017.07.24] - Fix for #37 [2017.07.24] - Fix for #30 [2017.08.23] -- Fix for #30 (mangahere.co) [2017.08.23] \ No newline at end of file +- Fix for #30 (mangahere.co) [2017.08.23] +- Added support for CBZ file creation (#28) [2017.08.24] \ No newline at end of file diff --git a/ReadMe.md b/ReadMe.md index 0c26002..57989a7 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -142,7 +142,7 @@ Currently, the script supports these arguments : --sorting Sorts the download order.(VALUES = asc, ascending,old,new,desc,descending,latest,new) -dd,--download-directory Specifies custom download location for the comics/manga. -rn,--range Selects the range of Chapters to download (Default = All) [ Ex : --range 1-10 (This will download first 10 episodes of a series)] ---convert Tells the script to convert the downloaded Images to PDF or anything else. (Supported Values : pdf) (Default : No) [By default, script will not convert anything.] +--convert Tells the script to convert the downloaded Images to PDF or anything else. (Supported Values : pdf, cbz) (Default : No) [By default, script will not convert anything.] --keep Tells the script whether to keep the files after conversion or not. (Supported : No, False) (Default : Yes/True) [By default, images will be kept even after conversion.] ``` #### Note : diff --git a/comic_dl/__version__.py b/comic_dl/__version__.py index 1c4cfbd..4e62555 100644 --- a/comic_dl/__version__.py +++ b/comic_dl/__version__.py @@ -1,4 +1,4 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -__version__ = "2017.08.23.b" \ No newline at end of file +__version__ = "2017.08.24" \ No newline at end of file diff --git a/comic_dl/globalFunctions.py b/comic_dl/globalFunctions.py index 1832148..2eea4a7 100644 --- a/comic_dl/globalFunctions.py +++ b/comic_dl/globalFunctions.py @@ -126,6 +126,31 @@ def conversion(self, directory_path, conversion, delete_files, comic_name, chapt print(FileMoveError) pass + elif str(conversion).lower().strip() in ['cbz']: + # Such kind of lambda functions and breaking is dangerous... + + main_directory = str(directory_path).split('\\') + main_directory.pop() + cbz_directory = str('\\'.join(main_directory)) + '\\' + + cbz_file_name = str(cbz_directory) + "{0} - Ch {1}".format(comic_name, chapter_number) + + try: + shutil.make_archive(cbz_file_name, 'zip', directory_path) + os.rename(str(cbz_file_name) + ".zip", str(cbz_file_name).replace(".zip", ".cbz")) + except Exception as CBZError: + print("Coudn't write the cbz file...") + print(CBZError) + # Let's not delete the files if the conversion failed... + delete_files = "No" + pass + try: + self.conversion_cleaner(file_path=str(directory_path)) + except Exception as FileMoveError: + print("Could not move the pdf file.") + print(FileMoveError) + pass + elif str(conversion) == "None": pass else: @@ -160,4 +185,3 @@ def conversion_cleaner(self, file_path): print("Couldn't move the file or delete the directory.") print(FileDeleteError) pass - diff --git a/docs/Changelog.md b/docs/Changelog.md index 6cf391c..0c21da0 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -44,4 +44,5 @@ - Fix for #36 [2017.07.24] - Fix for #37 [2017.07.24] - Fix for #30 [2017.08.23] -- Fix for #30 (mangahere.co) [2017.08.23] \ No newline at end of file +- Fix for #30 (mangahere.co) [2017.08.23] +- Added support for CBZ file creation (#28) [2017.08.24] \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index 0c26002..57989a7 100644 --- a/docs/index.md +++ b/docs/index.md @@ -142,7 +142,7 @@ Currently, the script supports these arguments : --sorting Sorts the download order.(VALUES = asc, ascending,old,new,desc,descending,latest,new) -dd,--download-directory Specifies custom download location for the comics/manga. -rn,--range Selects the range of Chapters to download (Default = All) [ Ex : --range 1-10 (This will download first 10 episodes of a series)] ---convert Tells the script to convert the downloaded Images to PDF or anything else. (Supported Values : pdf) (Default : No) [By default, script will not convert anything.] +--convert Tells the script to convert the downloaded Images to PDF or anything else. (Supported Values : pdf, cbz) (Default : No) [By default, script will not convert anything.] --keep Tells the script whether to keep the files after conversion or not. (Supported : No, False) (Default : Yes/True) [By default, images will be kept even after conversion.] ``` #### Note :