fix api request delay to not get rate limited with the --wait cli argument
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Ivan Schaller 2022-05-09 21:24:25 +02:00
parent 20ce0b6571
commit 78a4e1827f
4 changed files with 6 additions and 4 deletions

View file

@ -89,6 +89,7 @@ if __name__ == "__main__":
dest="wait", dest="wait",
required=False, required=False,
type=float, type=float,
default=0.5,
help="Time to wait for each picture to download in seconds(float). Defaults 0.5", help="Time to wait for each picture to download in seconds(float). Defaults 0.5",
) )
parser.add_argument( parser.add_argument(

View file

@ -171,7 +171,7 @@ class Mangadex:
return chapter_data return chapter_data
# get images for the chapter (mangadex@home) # get images for the chapter (mangadex@home)
def get_chapter_images(self, chapter): def get_chapter_images(self, chapter, wait_time):
if self.verbose: if self.verbose:
print(f"INFO: Getting chapter images for: {self.manga_uuid}") print(f"INFO: Getting chapter images for: {self.manga_uuid}")
athome_url = f"{self.api_base_url}/at-home/server" athome_url = f"{self.api_base_url}/at-home/server"
@ -192,6 +192,7 @@ class Mangadex:
for image in chapter_img_data: for image in chapter_img_data:
image_urls.append(f"{self.img_base_url}/data/{chapter_hash}/{image}") image_urls.append(f"{self.img_base_url}/data/{chapter_hash}/{image}")
sleep(wait_time)
return image_urls return image_urls
# create list of chapters # create list of chapters

View file

@ -4,7 +4,7 @@ from time import sleep
import requests import requests
# download images # download images
def download_chapter(image_urls, chapter_path, md_wait=0.5, md_verbose=False): def download_chapter(image_urls, chapter_path, md_wait, md_verbose):
img_num = 1 img_num = 1
for img in image_urls: for img in image_urls:
# set image path # set image path
@ -27,7 +27,7 @@ def download_chapter(image_urls, chapter_path, md_wait=0.5, md_verbose=False):
print(f"INFO: Downloaded image {img_num}") print(f"INFO: Downloaded image {img_num}")
img_num += 1 img_num += 1
sleep(0.5) sleep(md_wait)
else: else:
print(f"ERR: Image {img} could not be downloaded. Exiting") print(f"ERR: Image {img} could not be downloaded. Exiting")
exit(1) exit(1)

View file

@ -183,7 +183,7 @@ 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
chapter_image_urls = Api.get_chapter_images(chapter) chapter_image_urls = Api.get_chapter_images(chapter, download_wait)
# get filename for chapter # get filename for chapter
chapter_filename = Api.get_filename(chapter) chapter_filename = Api.get_filename(chapter)