add custom download interval

This commit is contained in:
Ivan Schaller 2021-12-20 15:33:04 +01:00
parent 9dfb36fe25
commit f7a7b2492f
3 changed files with 17 additions and 9 deletions

View file

@ -4,7 +4,7 @@ from time import sleep
from pathlib import Path
def download_chapter(image_urls, chapter_path, verbose=False):
def download_chapter(image_urls, chapter_path, md_wait=0.5, md_verbose=False):
# download images
img_num = 1
for img in image_urls:
@ -15,7 +15,7 @@ def download_chapter(image_urls, chapter_path, verbose=False):
req = requests.get(img, stream = True)
except:
print(f'Request for image {img} failed, retrying')
sleep(2)
sleep(md_wait)
req = requests.get(img, stream = True)
if req.status_code == 200:
@ -24,7 +24,7 @@ def download_chapter(image_urls, chapter_path, verbose=False):
shutil.copyfileobj(req.raw, file)
# verbose logging
if verbose:
if md_verbose:
print(f' Downloaded image {img_num}')
img_num += 1

View file

@ -12,7 +12,8 @@ def mangadex_dlp(md_url='',
md_list_chapters=False,
md_nocbz=False,
md_forcevol=False,
verbose=False):
md_wait=0.5,
md_verbose=False):
'''Download Mangas from Mangadex.org\n
Args:\n
@ -135,7 +136,7 @@ def mangadex_dlp(md_url='',
chapter_path.mkdir(parents=True, exist_ok=True)
# verbose output
if verbose:
if md_verbose:
print(f'Filename: {chapter_path}\n')
print(f'Image URLS: {image_urls}')
print(f'DEBUG: Downloading Volume {chapter_vol}')
@ -146,7 +147,7 @@ def mangadex_dlp(md_url='',
else:
print(f'+ Downloading Chapter {chapter_num}')
try:
MdDownloader.download_chapter(image_urls, chapter_path, verbose)
MdDownloader.download_chapter(image_urls, chapter_path, md_wait, md_verbose)
except:
if md_forcevol:
print(f'Cant download volume {chapter_vol} chapter {chapter_num}. Exiting')

View file

@ -9,6 +9,7 @@ def main(args):
args.list,
args.nocbz,
args.forcevol,
args.wait,
args.verbose)
@ -29,7 +30,7 @@ if __name__ == '__main__':
parser.add_argument('-d', '--destination',
dest='dest',
required=False,
help='Download path',
help='Download path. Defaults to "<script_dir>/downloads',
action='store',
default='downloads',
)
@ -49,7 +50,7 @@ if __name__ == '__main__':
parser.add_argument('--nocbz',
dest='nocbz',
required=False,
help='Dont pack it to a cbz archive',
help='Dont pack it to a cbz archive. Defaults to false.',
action='store_true',
)
parser.add_argument('--forcevol',
@ -58,10 +59,16 @@ if __name__ == '__main__':
help='Force naming of volumes. For mangas where chapters reset each volume',
action='store_true',
)
parser.add_argument('--wait',
dest='wait',
required=False,
type=float,
help='Time to wait for each picture to download in seconds(float). Defaults 0.5.',
)
parser.add_argument('--verbose',
dest='verbose',
required=False,
help='Verbose logging',
help='Verbose logging. Defaults to false.',
action='store_true',
)