diff --git a/manga-dlp.py b/manga-dlp.py index 3ea32f7..d21473e 100644 --- a/manga-dlp.py +++ b/manga-dlp.py @@ -21,7 +21,8 @@ if __name__ == "__main__": parser = argparse.ArgumentParser( description="Script to download mangas from various sites" ) - parser.add_argument( + group = parser.add_mutually_exclusive_group(required=True) + group.add_argument( "-u", "--url", "--uuid", @@ -56,7 +57,7 @@ if __name__ == "__main__": action="store", default="en", ) - parser.add_argument( + group.add_argument( "--read", dest="read", required=False, diff --git a/mangadlp/api/mangadex.py b/mangadlp/api/mangadex.py index ff8d34b..a562f68 100644 --- a/mangadlp/api/mangadex.py +++ b/mangadlp/api/mangadex.py @@ -34,7 +34,7 @@ class Mangadex: if self.verbose: print(f"INFO: Getting manga data for: {self.manga_uuid}") counter = 1 - while counter < 3: + while counter <= 3: try: manga_data = requests.get( f"{self.api_base_url}/manga/{self.manga_uuid}" @@ -180,7 +180,7 @@ class Mangadex: # retry up to two times if the api applied ratelimits api_error = False counter = 1 - while counter < 3: + while counter <= 3: try: r = requests.get(f"{athome_url}/{chapter_uuid}") api_data = r.json() @@ -196,10 +196,11 @@ class Mangadex: api_error = False break except: + if counter >= 3: + api_error = True print(f"ERR: Retrying in a few seconds") counter += 1 sleep(wait_time + 2) - continue # check if result is ok else: if api_error: diff --git a/mangadlp/downloader.py b/mangadlp/downloader.py index 68cb8c0..96179bc 100644 --- a/mangadlp/downloader.py +++ b/mangadlp/downloader.py @@ -12,6 +12,9 @@ def download_chapter(image_urls, chapter_path, md_wait, md_verbose): try: # print('Try getting ' + img) req = requests.get(img, stream=True) + except KeyboardInterrupt: + print("ERR: Stopping") + exit(1) except: print(f"ERR: Request for image {img} failed, retrying") sleep(md_wait) diff --git a/mangadlp/main.py b/mangadlp/main.py index f6d3a1e..a2266e7 100644 --- a/mangadlp/main.py +++ b/mangadlp/main.py @@ -185,7 +185,11 @@ def get_manga( chapter_infos = Api.get_chapter_infos(chapter) # get image urls for chapter - chapter_image_urls = Api.get_chapter_images(chapter, download_wait) + try: + chapter_image_urls = Api.get_chapter_images(chapter, download_wait) + except KeyboardInterrupt: + print("ERR: Stopping") + exit(1) # check if the image urls are empty. if yes skip this chapter (for mass downloads) if not chapter_image_urls: @@ -223,7 +227,7 @@ def get_manga( if manga_nocbz else f"INFO: Filename: '{chapter_filename}.cbz'\n" ) - print(f"INFO: Image URLS: {chapter_image_urls}") + print(f"INFO: Image URLS:\n{chapter_image_urls}\n") # log print(f"INFO: Downloading: '{chapter_filename}'") diff --git a/sonar-project.properties b/sonar-project.properties index 4083328..0dc6264 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -5,8 +5,8 @@ sonar.links.scm=https://github.com/olofvndrhr/manga-dlp sonar.links.issue=https://github.com/olofvndrhr/manga-dlp/issues sonar.links.ci=https://drone.44net.ch/olofvndrhr/manga-dlp # -sonar.sources=. -#sonar.tests=tests +sonar.sources=mangadlp +sonar.tests=tests sonar.exclusions=tests/**,docker/**,contrib/** sonar.python.version=3.9 sonar.python.coverage.reportPaths=coverage.xml