From ae42a19aed1e2f4c39887ba24b8e6e8f1e905629 Mon Sep 17 00:00:00 2001 From: Ivan Schaller Date: Fri, 20 May 2022 23:57:27 +0200 Subject: [PATCH 1/8] change logging of skipped chapters and fix error list --- .gitignore | 1 + mangadlp/app.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index fc74140..6c61148 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ downloads/ __pycache__/ .pytest_cache/ chaps.txt +mangas.txt .idea/ venv diff --git a/mangadlp/app.py b/mangadlp/app.py index 6bc7e35..f538e12 100644 --- a/mangadlp/app.py +++ b/mangadlp/app.py @@ -164,10 +164,13 @@ class MangaDLP: return_infos = self.archive_chapter(return_infos["chapter_path"]) error_chapters.append(return_infos.get("error")) skipped_chapters.append(return_infos.get("skipped")) - - # done with chapter - print("INFO: Done with chapter") - print("-----------------------------------------\n") + # check if chapter was skipped + try: + return_infos["skipped"] + # chapter was not skipped + except KeyError: + # done with chapter + print("INFO: Done with chapter\n") # done with manga print(f"{print_divider}") @@ -176,6 +179,10 @@ class MangaDLP: skipped_chapters = list(filter(None, skipped_chapters)) if len(skipped_chapters) >= 1: print(f"INFO: Skipped chapters:\n{', '.join(skipped_chapters)}") + # filter error list + error_chapters = list(filter(None, error_chapters)) + if len(error_chapters) >= 1: + print(f"INFO: Chapters with errors:\n{', '.join(error_chapters)}") print(f"{print_divider}\n") # once called per chapter From cbf62b26dbeecc205df018d1590452d5bc3fb39a Mon Sep 17 00:00:00 2001 From: Ivan Schaller Date: Wed, 25 May 2022 20:10:43 +0200 Subject: [PATCH 2/8] replace exit with sys.exit and add option to list chapters in interactive input --- manga-dlp.py | 33 ++++++++++++++++++++++++--------- mangadlp/api/mangadex.py | 13 ++++++++----- mangadlp/app.py | 15 ++++++++------- mangadlp/downloader.py | 6 ++++-- mangadlp/input.py | 5 +++-- 5 files changed, 47 insertions(+), 25 deletions(-) diff --git a/manga-dlp.py b/manga-dlp.py index f2f136b..e324644 100644 --- a/manga-dlp.py +++ b/manga-dlp.py @@ -1,7 +1,8 @@ -from mangadlp.input import get_args -import os +import subprocess import sys +from mangadlp.input import get_args + mangadlp_version = "2.1.2" @@ -12,22 +13,36 @@ def get_input(): try: url_uuid = str(input("Url or UUID: ")) readlist = str(input("List with links (optional): ")) - language = str(input("Language: ")) - chapters = str(input("Chapters: ")) + language = str(input("Language: ")) or "en" + list_chapters = str(input("List chapters? y/N: ")) + if list_chapters.lower() != "y" or list_chapters.lower() != "yes": + chapters = str(input("Chapters: ")) except KeyboardInterrupt: - exit(1) + sys.exit(1) except: continue else: break - args = [f"-l {language}", f"-c {chapters}"] + + args = [ + "python3", + "manga-dlp.py", + "-l", + language, + "-c", + chapters, + ] if url_uuid: - args.append(f"-u {url_uuid}") + args.append("-u") + args.append(url_uuid) if readlist: - args.append(f"--read {readlist}") + args.append("--read") + args.append(readlist) + if list_chapters.lower() == "y" or list_chapters.lower() == "yes": + args.append("--list") # start script again with the arguments - os.system(f"python3 manga-dlp.py {' '.join(args)}") + subprocess.call(args) if __name__ == "__main__": diff --git a/mangadlp/api/mangadex.py b/mangadlp/api/mangadex.py index 8f53f33..af1d0dd 100644 --- a/mangadlp/api/mangadex.py +++ b/mangadlp/api/mangadex.py @@ -1,6 +1,9 @@ import re +import sys from time import sleep + import requests + import mangadlp.utils as utils @@ -43,7 +46,7 @@ class Mangadex: except: if counter >= 3: print("ERR: Maybe the MangaDex API is down?") - exit(1) + sys.exit(1) else: print("ERR: Mangadex API not reachable. Retrying") sleep(2) @@ -53,7 +56,7 @@ class Mangadex: # check if manga exists if manga_data.json()["result"] != "ok": print("ERR: Manga not found") - exit(1) + sys.exit(1) return manga_data @@ -66,7 +69,7 @@ class Mangadex: # check for new mangadex id if not uuid_regex.search(self.url_uuid): print("ERR: No valid UUID found") - exit(1) + sys.exit(1) manga_uuid = uuid_regex.search(self.url_uuid)[0] return manga_uuid @@ -86,7 +89,7 @@ class Mangadex: title = alt_titles[self.language] except: # no title on requested language found print("ERR: Chapter in requested language not found.") - exit(1) + sys.exit(1) return utils.fix_name(title) # check if chapters are available in requested language @@ -120,7 +123,7 @@ class Mangadex: # check for chapters in specified lang total_chapters = self.check_chapter_lang() if total_chapters == 0: - exit(1) + sys.exit(1) chapter_data = {} last_chapter = ["", ""] diff --git a/mangadlp/app.py b/mangadlp/app.py index f538e12..5e4894b 100644 --- a/mangadlp/app.py +++ b/mangadlp/app.py @@ -1,5 +1,6 @@ import re import shutil +import sys from pathlib import Path import mangadlp.downloader as downloader @@ -81,7 +82,7 @@ class MangaDLP: print( f'ERR: You need to specify a manga url/uuid with "-u" or a list with "--read"' ) - exit(1) + sys.exit(1) # checks if --list is not used if not self.list_chapters: if self.chapters is None: @@ -89,15 +90,15 @@ class MangaDLP: print( f'ERR: You need to specify one or more chapters to download. To see all chapters use "--list"' ) - exit(1) + sys.exit(1) # if forcevol is used, but didn't specify a volume in the chapters selected if self.forcevol and ":" not in self.chapters: print(f"ERR: You need to specify the volume if you use --forcevol") - exit(1) + sys.exit(1) # if forcevol is not used, but a volume is specified if not self.forcevol and ":" in self.chapters: print(f"ERR: Don't specify the volume without --forcevol") - exit(1) + sys.exit(1) # check the api which needs to be used def check_api(self, url_uuid: str) -> type: @@ -115,7 +116,7 @@ class MangaDLP: # this is only for testing multiple apis if api_test.search(url_uuid): print("Not supported yet") - exit(1) + sys.exit(1) # no supported api found print(f"ERR: No supported api in link/uuid found: {url_uuid}") @@ -197,7 +198,7 @@ class MangaDLP: ) except KeyboardInterrupt: print("ERR: Stopping") - exit(1) + sys.exit(1) # check if the image urls are empty. if yes skip this chapter (for mass downloads) if not chapter_image_urls: @@ -258,7 +259,7 @@ class MangaDLP: ) except KeyboardInterrupt: print("ERR: Stopping") - exit(1) + sys.exit(1) except: print(f"ERR: Cant download: '{chapter_filename}'. Skipping") # add to skipped chapters list diff --git a/mangadlp/downloader.py b/mangadlp/downloader.py index f468678..d3efb6c 100644 --- a/mangadlp/downloader.py +++ b/mangadlp/downloader.py @@ -1,6 +1,8 @@ +import shutil +import sys from pathlib import Path from time import sleep -import shutil + import requests import mangadlp.utils as utils @@ -29,7 +31,7 @@ def download_chapter( raise ConnectionError except KeyboardInterrupt: print("ERR: Stopping") - exit(1) + sys.exit(1) except: if counter >= 3: print("ERR: Maybe the MangaDex Servers are down?") diff --git a/mangadlp/input.py b/mangadlp/input.py index 94f7a82..105c8bb 100644 --- a/mangadlp/input.py +++ b/mangadlp/input.py @@ -1,7 +1,8 @@ import argparse -import mangadlp.app as app from pathlib import Path +import mangadlp.app as app + mangadlp_version = "2.1.2" @@ -9,7 +10,7 @@ def check_args(args): # check if --version was used if args.version: print(f"manga-dlp version: {mangadlp_version}") - exit(0) + sys.exit(0) # check if a readin list was provided if not args.read: # single manga, no readin list From 3336649ada1d019eb8bf4314922eeb6cf0f19f35 Mon Sep 17 00:00:00 2001 From: Ivan Schaller Date: Wed, 25 May 2022 20:15:30 +0200 Subject: [PATCH 3/8] import sys --- mangadlp/input.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mangadlp/input.py b/mangadlp/input.py index 105c8bb..11da9f5 100644 --- a/mangadlp/input.py +++ b/mangadlp/input.py @@ -1,4 +1,5 @@ import argparse +import sys from pathlib import Path import mangadlp.app as app From 0305631f7822363209e791f4dbaa8697ad4f699e Mon Sep 17 00:00:00 2001 From: Ivan Schaller Date: Wed, 25 May 2022 22:18:23 +0200 Subject: [PATCH 4/8] rename class methods so they don't use a dunder format --- mangadlp/app.py | 10 +++------- mangadlp/input.py | 2 +- tests/test_21_full.py | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/mangadlp/app.py b/mangadlp/app.py index 5e4894b..3ff5dab 100644 --- a/mangadlp/app.py +++ b/mangadlp/app.py @@ -12,7 +12,7 @@ from mangadlp.api.mangadex import Mangadex class MangaDLP: """Download Mangas from supported sites. - After initialization, start the script with the function __main__(). + After initialization, start the script with the function get_manga(). :param url_uuid: URL or UUID of the manga :param language: Manga language with country codes. "en" --> english @@ -50,9 +50,9 @@ class MangaDLP: self.download_wait = download_wait self.verbose = verbose # prepare everything - self.__prepare__() + self._prepare() - def __prepare__(self) -> None: + def _prepare(self) -> None: # additional stuff # set manga format suffix if self.file_format and "." not in self.file_format: @@ -71,10 +71,6 @@ class MangaDLP: self.manga_chapter_list = self.api.chapter_list self.manga_path = Path(f"{self.download_path}/{self.manga_title}") - def __main__(self): - # start flow - self.get_manga() - def pre_checks(self) -> None: # prechecks userinput/options # no url and no readin list given diff --git a/mangadlp/input.py b/mangadlp/input.py index 11da9f5..2edea85 100644 --- a/mangadlp/input.py +++ b/mangadlp/input.py @@ -49,7 +49,7 @@ def call_app(args): args.wait, args.verbose, ) - mdlp.__main__() + mdlp.get_manga() def get_args(): diff --git a/tests/test_21_full.py b/tests/test_21_full.py index 72bef4c..5b2f798 100644 --- a/tests/test_21_full.py +++ b/tests/test_21_full.py @@ -19,7 +19,7 @@ def test_full_api_mangadex(): download_wait=0.5, verbose=True, ) - mdlp.__main__() + mdlp.get_manga() assert manga_path.exists() and manga_path.is_dir() assert chapter_path.exists() and chapter_path.is_file() From a8e670de7184f322326c441a58c026dbf3184c97 Mon Sep 17 00:00:00 2001 From: Ivan Schaller Date: Wed, 25 May 2022 22:25:04 +0200 Subject: [PATCH 5/8] change print version to match -v --- manga-dlp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manga-dlp.py b/manga-dlp.py index e324644..defce91 100644 --- a/manga-dlp.py +++ b/manga-dlp.py @@ -7,7 +7,7 @@ mangadlp_version = "2.1.2" def get_input(): - print(f"Manga-DLP Version {mangadlp_version}") + print(f"manga-dlp version: {mangadlp_version}") print("Enter details of the manga you want to download:") while True: try: From b27e819e46ef6d7617d5619addfab4f0d8288ee7 Mon Sep 17 00:00:00 2001 From: Ivan Schaller Date: Wed, 25 May 2022 22:31:28 +0200 Subject: [PATCH 6/8] prepare changelog + .md formatting --- CHANGELOG.md | 34 +++++++++++++++++++++++++++++----- README.md | 3 ++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b91a75..b4fc2b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,43 +9,64 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Add support for more sites +## [2.1.3] - 2022-05-20 + +### Fixed + +- Error-chapters and skipped-chapters list are now shown again +- The Interactive input version now matches `--version` + +### Added + +- Ability to list chapters with interactive input + +### Changed + +- Replace `exit()` with `sys.exit()` +- Renamed class methods to not look like dunder methods ## [2.1.2] - 2022-05-20 ### Fixed + - List chapters when none were specified - Typos ### Added + - Ability to download whole volumes ### Changed + - Moved processing of list with links to input.py - Updated README for volume and chapter selection - ## [2.1.1] - 2022-05-18 ### Fixed + - Progress bar on verbose output - Sonarqube link for CI - A few typos - Removed unnecessary escapes from file rename regex ### Added + - API template ### Changed + - Updated docker baseimage - Rewrote app.py to a class - ## [2.1.0] - 2022-05-16 ### Fixed + - Detection of files. Now it will skip them again ### Added + - Ability to save the chapters as pdf (only on amd64/x86) - New output formats: rar, zip - Progress bar to show image download @@ -55,14 +76,15 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Removed duplicate code ### Changed + - How the variables are used inside the script - Variables have now the same name as in other scripts (mostly) - Better retrying when a task fails - ## [2.0.8] - 2022-05-13 ### Changed + - Rewrote parts of script to be easier to maintain - Moved the input script to the base folder - Moved all arguments to a class @@ -71,24 +93,26 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [2.0.7] - 2022-05-13 ### Changed + - Changed CI/CD Platform from Drone-CI to Woodpecker-CI - Release title is now only the version ## [2.0.6] - 2022-05-11 ### Fixed -- Filenames on windows (ntfs). Removed double quote from file and folder names +- Filenames on windows (ntfs). Removed double quote from file and folder names ## [2.0.5] - 2022-05-11 ### Fixed + - Better error handling on "KeyboardInterrupt" - Release notes now fixed ### Added -- New test cases +- New test cases ## [2.0.4] - 2022-05-10 diff --git a/README.md b/README.md index 2bcb7a6..0d29ad5 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,8 @@ See the docker [README](./docker/README.md) ## Options -> "--format" currently only works with "", "pdf", "zip", "rar" and "cbz". As it just renames the zip file with the new suffix (except pdf). For pdf creation you have to install img2pdf. +> "--format" currently only works with "", "pdf", "zip", "rar" and "cbz". As it just renames the zip file with the new +> suffix (except pdf). For pdf creation you have to install img2pdf. ```txt usage: manga-dlp.py [-h] (-u URL_UUID | --read READ | -v) [-c CHAPTERS] [-p PATH] [-l LANG] [--list] [--format FORMAT] [--forcevol] [--wait WAIT] [--verbose] From 57d26755289eebc7aad90f2c654c1027783787ef Mon Sep 17 00:00:00 2001 From: Ivan Schaller Date: Wed, 25 May 2022 22:33:09 +0200 Subject: [PATCH 7/8] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4fc2b7..8c6ea31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Replace `exit()` with `sys.exit()` - Renamed class methods to not look like dunder methods +- Script execution moved from `os.system()` to `subprocess.call()` ## [2.1.2] - 2022-05-20 From 547d056822b667945b975cc9432ec145e3224763 Mon Sep 17 00:00:00 2001 From: Ivan Schaller Date: Sun, 29 May 2022 13:49:27 +0200 Subject: [PATCH 8/8] prepare for 2.1.3 release --- CHANGELOG.md | 2 +- docker/Dockerfile.amd64 | 2 +- docker/Dockerfile.arm64 | 2 +- manga-dlp.py | 2 +- mangadlp/input.py | 2 +- setup.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c6ea31..55a83e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Add support for more sites -## [2.1.3] - 2022-05-20 +## [2.1.3] - 2022-05-29 ### Fixed diff --git a/docker/Dockerfile.amd64 b/docker/Dockerfile.amd64 index 63efe79..5e162ba 100644 --- a/docker/Dockerfile.amd64 +++ b/docker/Dockerfile.amd64 @@ -7,7 +7,7 @@ LABEL build_version="Version:- ${VERSION} Build-date:- ${BUILD_DATE}" LABEL maintainer="Ivan Schaller" # manga-dlp version -ENV MDLP_VERSION=2.1.2 +ENV MDLP_VERSION=2.1.3 # install packages RUN \ diff --git a/docker/Dockerfile.arm64 b/docker/Dockerfile.arm64 index 13f1f36..dd205b0 100644 --- a/docker/Dockerfile.arm64 +++ b/docker/Dockerfile.arm64 @@ -7,7 +7,7 @@ LABEL build_version="Version:- ${VERSION} Build-date:- ${BUILD_DATE}" LABEL maintainer="Ivan Schaller" # manga-dlp version -ENV MDLP_VERSION=2.1.2 +ENV MDLP_VERSION=2.1.3 # install packages RUN \ diff --git a/manga-dlp.py b/manga-dlp.py index defce91..40715cf 100644 --- a/manga-dlp.py +++ b/manga-dlp.py @@ -3,7 +3,7 @@ import sys from mangadlp.input import get_args -mangadlp_version = "2.1.2" +mangadlp_version = "2.1.3" def get_input(): diff --git a/mangadlp/input.py b/mangadlp/input.py index 2edea85..a18e142 100644 --- a/mangadlp/input.py +++ b/mangadlp/input.py @@ -4,7 +4,7 @@ from pathlib import Path import mangadlp.app as app -mangadlp_version = "2.1.2" +mangadlp_version = "2.1.3" def check_args(args): diff --git a/setup.py b/setup.py index ff52eda..1877374 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ long_description = readme.read_text() setuptools.setup( name="manga-dlp", - version="2.1.2", + version="2.1.3", author="Ivan Schaller", author_email="ivan@schaller.sh", description="A cli manga downloader",