From 05b5cbee0da4c27b039574a21586d7772fa4c21b Mon Sep 17 00:00:00 2001 From: Dhruv Kanojia Date: Mon, 24 Jul 2017 21:11:02 +0530 Subject: [PATCH] Fix for #34 , #36 and #37 Fix for #34 , #36 and #37. --- Changelog.md | 5 ++++- ReadMe.md | 10 ++++++---- comic_dl/__version__.py | 2 +- comic_dl/comic_dl.py | 5 ++--- comic_dl/globalFunctions.py | 30 +++++++++++++++++++++++++++++- docs/Changelog.md | 5 ++++- docs/index.md | 10 ++++++---- 7 files changed, 52 insertions(+), 15 deletions(-) diff --git a/Changelog.md b/Changelog.md index 79692fe..7624c6d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -39,4 +39,7 @@ - Support to download only selected chapters (range) [2017.07.06] - Fix for #32 [2017.07.07] - Support for converting downloaded images into pdf #17 [2017.07.07] -- Fix for #33 [2017.07.07] \ No newline at end of file +- Fix for #33 [2017.07.07] +- Fix for #34 [2017.07.24] +- Fix for #36 [2017.07.24] +- Fix for #37 [2017.07.24] \ No newline at end of file diff --git a/ReadMe.md b/ReadMe.md index c0929b3..0c26002 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -34,7 +34,7 @@ Comic-dl is a command line tool to download Comics and Manga from various Manga You can check the list of supported websites [**`HERE`**](https://github.com/Xonshiz/comic-dl/blob/master/Supported_Sites.md). ## Dependencies Installation -This script can run on multiple Operating Systems. You need `Node.js` in your system's path for this script to work. Download the `Node.Js` from [Node.js official website](https://nodejs.org/en/). Doesn't matter which operating system you're on, this is a must. Follow the instructions mentioned below, according to your OS. +This script can run on multiple Operating Systems. You need `Node.js` in your system's path for this script to work (You need this on each and every Operating System, even on WINDOWS :/). Download the `Node.Js` from [Node.js official website](https://nodejs.org/en/). Doesn't matter which operating system you're on, this is a must. Follow the instructions mentioned below, according to your OS. ### Linux/Debian : Since most (if not all) Linux/Debian OS come with python pre-installed, you don't have to install python manually. Make sure you're using python >= 2.7.x though. @@ -78,7 +78,7 @@ phantomjs --version ``` ### Windows : -If you're on windows, then it is recommended to download the [`windows binary`](https://github.com/Xonshiz/comic-dl#windows-binary) for this script. If you use the windows binary, you don't need to install anything. But, if for some weird reason you want to use Python script instead, then follow these steps : +If you're on windows, then it is recommended to download the [`windows binary`](https://github.com/Xonshiz/comic-dl#windows-binary) for this script. If you use the windows binary, you don't need to install anything, except Node.js. But, if for some weird reason you want to use Python script instead, then follow these steps : * Install Python > 2.7.6. Download the desired installer from [here](https://www.python.org/downloads/). * [Add it in the system path](http://superuser.com/questions/143119/how-to-add-python-to-the-windows-path) (if not already added). @@ -91,6 +91,8 @@ pip install -r requirements.txt * It should install the required external libraries. * Download PhantomJS : http://phantomjs.org/download.html +Now, install Node.Js as well and make sure it's in your path. + Well, if everything came up good without any error(s), then you're good to go! ### Mac OS X : @@ -140,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)] ---conversion 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) (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 : @@ -164,7 +166,7 @@ After you've saved this script in a directory/folder, you need to open `command *If you're using the windows binary :* -`comic-dl.exe -i ` +`comic_dl.exe -i ` *If you're using the Python Script :* diff --git a/comic_dl/__version__.py b/comic_dl/__version__.py index 477dedc..6a0d428 100644 --- a/comic_dl/__version__.py +++ b/comic_dl/__version__.py @@ -1,4 +1,4 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -__version__ = "2017.07.07" \ No newline at end of file +__version__ = "2017.07.24" \ No newline at end of file diff --git a/comic_dl/comic_dl.py b/comic_dl/comic_dl.py index ca8cbde..86f4b01 100644 --- a/comic_dl/comic_dl.py +++ b/comic_dl/comic_dl.py @@ -20,11 +20,10 @@ def __init__(self, argv): parser.add_argument('-s', '--sorting', nargs=1, help='Decides downloading order of chapters.') parser.add_argument('-dd', '--download-directory', nargs=1, help='Decides the download directory of the comics/manga.') parser.add_argument('-rn', '--range', nargs=1, help='Specifies the range of chapters to download.', default='All') - parser.add_argument('--convert', nargs=1, help='Tells the script to convert the downloaded Images to PDF or anything else.',default='None') + parser.add_argument('--convert', nargs=1, help='Tells the script to convert the downloaded Images to PDF or anything else.') parser.add_argument('--keep', nargs=1, help='Tells the script whether to keep the files after conversion or not.', default='True') - required_args = parser.add_argument_group('Required Arguments :') - required_args.add_argument('-i', '--input', nargs=1, help='Inputs the URL to anime.') + parser.add_argument('-i', '--input', nargs=1, help='Inputs the URL to anime.') parser.add_argument("-v", "--verbose", help="Prints important debugging messages on screen.", action="store_true") diff --git a/comic_dl/globalFunctions.py b/comic_dl/globalFunctions.py index dc5ad26..1832148 100644 --- a/comic_dl/globalFunctions.py +++ b/comic_dl/globalFunctions.py @@ -102,6 +102,7 @@ def info_printer(self, anime_name, episode_number, **kwargs): print('{:^80}'.format('=====================================================================\n')) def conversion(self, directory_path, conversion, delete_files, comic_name, chapter_number): + if str(conversion).lower().strip() in ['pdf']: # Such kind of lambda functions and breaking is dangerous... im_files = [image_files for image_files in sorted(glob.glob(str(directory_path) + "/" + "*.jpg"), @@ -118,7 +119,14 @@ def conversion(self, directory_path, conversion, delete_files, comic_name, chapt # Let's not delete the files if the conversion failed... delete_files = "No" pass - elif str(conversion) is None: + try: + self.conversion_cleaner(file_path=str(directory_path) + "/" + str(pdf_file_name)) + except Exception as FileMoveError: + print("Could not move the pdf file.") + print(FileMoveError) + pass + + elif str(conversion) == "None": pass else: print("Seems like that conversion isn't supported yet. Please report it on the repository...") @@ -133,3 +141,23 @@ def conversion(self, directory_path, conversion, delete_files, comic_name, chapt print(FileDeleteError) pass print("Deleted the files...") + + def conversion_cleaner(self, file_path): + print("Cleaning Up...") + path_breaker = str(file_path).split("/") + + path_breaker.pop() + old_path = '/'.join(path_breaker) + + path_breaker = str(old_path).split("\\") + path_breaker.pop() + new_path = str('/'.join(path_breaker)) + "/" + + try: + shutil.move(file_path, new_path) + shutil.rmtree(old_path) + except Exception as FileDeleteError: + print("Couldn't move the file or delete the directory.") + print(FileDeleteError) + pass + diff --git a/docs/Changelog.md b/docs/Changelog.md index 79692fe..7624c6d 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -39,4 +39,7 @@ - Support to download only selected chapters (range) [2017.07.06] - Fix for #32 [2017.07.07] - Support for converting downloaded images into pdf #17 [2017.07.07] -- Fix for #33 [2017.07.07] \ No newline at end of file +- Fix for #33 [2017.07.07] +- Fix for #34 [2017.07.24] +- Fix for #36 [2017.07.24] +- Fix for #37 [2017.07.24] \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index c0929b3..0c26002 100644 --- a/docs/index.md +++ b/docs/index.md @@ -34,7 +34,7 @@ Comic-dl is a command line tool to download Comics and Manga from various Manga You can check the list of supported websites [**`HERE`**](https://github.com/Xonshiz/comic-dl/blob/master/Supported_Sites.md). ## Dependencies Installation -This script can run on multiple Operating Systems. You need `Node.js` in your system's path for this script to work. Download the `Node.Js` from [Node.js official website](https://nodejs.org/en/). Doesn't matter which operating system you're on, this is a must. Follow the instructions mentioned below, according to your OS. +This script can run on multiple Operating Systems. You need `Node.js` in your system's path for this script to work (You need this on each and every Operating System, even on WINDOWS :/). Download the `Node.Js` from [Node.js official website](https://nodejs.org/en/). Doesn't matter which operating system you're on, this is a must. Follow the instructions mentioned below, according to your OS. ### Linux/Debian : Since most (if not all) Linux/Debian OS come with python pre-installed, you don't have to install python manually. Make sure you're using python >= 2.7.x though. @@ -78,7 +78,7 @@ phantomjs --version ``` ### Windows : -If you're on windows, then it is recommended to download the [`windows binary`](https://github.com/Xonshiz/comic-dl#windows-binary) for this script. If you use the windows binary, you don't need to install anything. But, if for some weird reason you want to use Python script instead, then follow these steps : +If you're on windows, then it is recommended to download the [`windows binary`](https://github.com/Xonshiz/comic-dl#windows-binary) for this script. If you use the windows binary, you don't need to install anything, except Node.js. But, if for some weird reason you want to use Python script instead, then follow these steps : * Install Python > 2.7.6. Download the desired installer from [here](https://www.python.org/downloads/). * [Add it in the system path](http://superuser.com/questions/143119/how-to-add-python-to-the-windows-path) (if not already added). @@ -91,6 +91,8 @@ pip install -r requirements.txt * It should install the required external libraries. * Download PhantomJS : http://phantomjs.org/download.html +Now, install Node.Js as well and make sure it's in your path. + Well, if everything came up good without any error(s), then you're good to go! ### Mac OS X : @@ -140,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)] ---conversion 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) (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 : @@ -164,7 +166,7 @@ After you've saved this script in a directory/folder, you need to open `command *If you're using the windows binary :* -`comic-dl.exe -i ` +`comic_dl.exe -i ` *If you're using the Python Script :*