better interrupt handling and fixed some loop bugs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Ivan Schaller 2022-05-11 14:23:42 +02:00
parent c80d68fe8e
commit 6fd02ecf20
5 changed files with 18 additions and 9 deletions

View file

@ -21,7 +21,8 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Script to download mangas from various sites" description="Script to download mangas from various sites"
) )
parser.add_argument( group = parser.add_mutually_exclusive_group(required=True)
group.add_argument(
"-u", "-u",
"--url", "--url",
"--uuid", "--uuid",
@ -56,7 +57,7 @@ if __name__ == "__main__":
action="store", action="store",
default="en", default="en",
) )
parser.add_argument( group.add_argument(
"--read", "--read",
dest="read", dest="read",
required=False, required=False,

View file

@ -34,7 +34,7 @@ class Mangadex:
if self.verbose: if self.verbose:
print(f"INFO: Getting manga data for: {self.manga_uuid}") print(f"INFO: Getting manga data for: {self.manga_uuid}")
counter = 1 counter = 1
while counter < 3: while counter <= 3:
try: try:
manga_data = requests.get( manga_data = requests.get(
f"{self.api_base_url}/manga/{self.manga_uuid}" 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 # retry up to two times if the api applied ratelimits
api_error = False api_error = False
counter = 1 counter = 1
while counter < 3: while counter <= 3:
try: try:
r = requests.get(f"{athome_url}/{chapter_uuid}") r = requests.get(f"{athome_url}/{chapter_uuid}")
api_data = r.json() api_data = r.json()
@ -196,10 +196,11 @@ class Mangadex:
api_error = False api_error = False
break break
except: except:
if counter >= 3:
api_error = True
print(f"ERR: Retrying in a few seconds") print(f"ERR: Retrying in a few seconds")
counter += 1 counter += 1
sleep(wait_time + 2) sleep(wait_time + 2)
continue
# check if result is ok # check if result is ok
else: else:
if api_error: if api_error:

View file

@ -12,6 +12,9 @@ def download_chapter(image_urls, chapter_path, md_wait, md_verbose):
try: try:
# print('Try getting ' + img) # print('Try getting ' + img)
req = requests.get(img, stream=True) req = requests.get(img, stream=True)
except KeyboardInterrupt:
print("ERR: Stopping")
exit(1)
except: except:
print(f"ERR: Request for image {img} failed, retrying") print(f"ERR: Request for image {img} failed, retrying")
sleep(md_wait) sleep(md_wait)

View file

@ -185,7 +185,11 @@ def get_manga(
chapter_infos = Api.get_chapter_infos(chapter) chapter_infos = Api.get_chapter_infos(chapter)
# get image urls for chapter # get image urls for chapter
try:
chapter_image_urls = Api.get_chapter_images(chapter, download_wait) 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) # check if the image urls are empty. if yes skip this chapter (for mass downloads)
if not chapter_image_urls: if not chapter_image_urls:
@ -223,7 +227,7 @@ def get_manga(
if manga_nocbz if manga_nocbz
else f"INFO: Filename: '{chapter_filename}.cbz'\n" 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 # log
print(f"INFO: Downloading: '{chapter_filename}'") print(f"INFO: Downloading: '{chapter_filename}'")

View file

@ -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.issue=https://github.com/olofvndrhr/manga-dlp/issues
sonar.links.ci=https://drone.44net.ch/olofvndrhr/manga-dlp sonar.links.ci=https://drone.44net.ch/olofvndrhr/manga-dlp
# #
sonar.sources=. sonar.sources=mangadlp
#sonar.tests=tests sonar.tests=tests
sonar.exclusions=tests/**,docker/**,contrib/** sonar.exclusions=tests/**,docker/**,contrib/**
sonar.python.version=3.9 sonar.python.version=3.9
sonar.python.coverage.reportPaths=coverage.xml sonar.python.coverage.reportPaths=coverage.xml