better interrupt handling and fixed some loop bugs
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c80d68fe8e
commit
6fd02ecf20
5 changed files with 18 additions and 9 deletions
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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}'")
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue