add custom download interval
This commit is contained in:
parent
9dfb36fe25
commit
f7a7b2492f
3 changed files with 17 additions and 9 deletions
|
@ -4,7 +4,7 @@ from time import sleep
|
||||||
from pathlib import Path
|
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
|
# download images
|
||||||
img_num = 1
|
img_num = 1
|
||||||
for img in image_urls:
|
for img in image_urls:
|
||||||
|
@ -15,7 +15,7 @@ def download_chapter(image_urls, chapter_path, verbose=False):
|
||||||
req = requests.get(img, stream = True)
|
req = requests.get(img, stream = True)
|
||||||
except:
|
except:
|
||||||
print(f'Request for image {img} failed, retrying')
|
print(f'Request for image {img} failed, retrying')
|
||||||
sleep(2)
|
sleep(md_wait)
|
||||||
req = requests.get(img, stream = True)
|
req = requests.get(img, stream = True)
|
||||||
|
|
||||||
if req.status_code == 200:
|
if req.status_code == 200:
|
||||||
|
@ -24,7 +24,7 @@ def download_chapter(image_urls, chapter_path, verbose=False):
|
||||||
shutil.copyfileobj(req.raw, file)
|
shutil.copyfileobj(req.raw, file)
|
||||||
|
|
||||||
# verbose logging
|
# verbose logging
|
||||||
if verbose:
|
if md_verbose:
|
||||||
print(f' Downloaded image {img_num}')
|
print(f' Downloaded image {img_num}')
|
||||||
|
|
||||||
img_num += 1
|
img_num += 1
|
||||||
|
|
|
@ -12,7 +12,8 @@ def mangadex_dlp(md_url='',
|
||||||
md_list_chapters=False,
|
md_list_chapters=False,
|
||||||
md_nocbz=False,
|
md_nocbz=False,
|
||||||
md_forcevol=False,
|
md_forcevol=False,
|
||||||
verbose=False):
|
md_wait=0.5,
|
||||||
|
md_verbose=False):
|
||||||
'''Download Mangas from Mangadex.org\n
|
'''Download Mangas from Mangadex.org\n
|
||||||
|
|
||||||
Args:\n
|
Args:\n
|
||||||
|
@ -135,7 +136,7 @@ def mangadex_dlp(md_url='',
|
||||||
chapter_path.mkdir(parents=True, exist_ok=True)
|
chapter_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
# verbose output
|
# verbose output
|
||||||
if verbose:
|
if md_verbose:
|
||||||
print(f'Filename: {chapter_path}\n')
|
print(f'Filename: {chapter_path}\n')
|
||||||
print(f'Image URLS: {image_urls}')
|
print(f'Image URLS: {image_urls}')
|
||||||
print(f'DEBUG: Downloading Volume {chapter_vol}')
|
print(f'DEBUG: Downloading Volume {chapter_vol}')
|
||||||
|
@ -146,7 +147,7 @@ def mangadex_dlp(md_url='',
|
||||||
else:
|
else:
|
||||||
print(f'+ Downloading Chapter {chapter_num}')
|
print(f'+ Downloading Chapter {chapter_num}')
|
||||||
try:
|
try:
|
||||||
MdDownloader.download_chapter(image_urls, chapter_path, verbose)
|
MdDownloader.download_chapter(image_urls, chapter_path, md_wait, md_verbose)
|
||||||
except:
|
except:
|
||||||
if md_forcevol:
|
if md_forcevol:
|
||||||
print(f'Cant download volume {chapter_vol} chapter {chapter_num}. Exiting')
|
print(f'Cant download volume {chapter_vol} chapter {chapter_num}. Exiting')
|
||||||
|
|
13
md-dlp.py
13
md-dlp.py
|
@ -9,6 +9,7 @@ def main(args):
|
||||||
args.list,
|
args.list,
|
||||||
args.nocbz,
|
args.nocbz,
|
||||||
args.forcevol,
|
args.forcevol,
|
||||||
|
args.wait,
|
||||||
args.verbose)
|
args.verbose)
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +30,7 @@ if __name__ == '__main__':
|
||||||
parser.add_argument('-d', '--destination',
|
parser.add_argument('-d', '--destination',
|
||||||
dest='dest',
|
dest='dest',
|
||||||
required=False,
|
required=False,
|
||||||
help='Download path',
|
help='Download path. Defaults to "<script_dir>/downloads',
|
||||||
action='store',
|
action='store',
|
||||||
default='downloads',
|
default='downloads',
|
||||||
)
|
)
|
||||||
|
@ -49,7 +50,7 @@ if __name__ == '__main__':
|
||||||
parser.add_argument('--nocbz',
|
parser.add_argument('--nocbz',
|
||||||
dest='nocbz',
|
dest='nocbz',
|
||||||
required=False,
|
required=False,
|
||||||
help='Dont pack it to a cbz archive',
|
help='Dont pack it to a cbz archive. Defaults to false.',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
)
|
)
|
||||||
parser.add_argument('--forcevol',
|
parser.add_argument('--forcevol',
|
||||||
|
@ -58,10 +59,16 @@ if __name__ == '__main__':
|
||||||
help='Force naming of volumes. For mangas where chapters reset each volume',
|
help='Force naming of volumes. For mangas where chapters reset each volume',
|
||||||
action='store_true',
|
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',
|
parser.add_argument('--verbose',
|
||||||
dest='verbose',
|
dest='verbose',
|
||||||
required=False,
|
required=False,
|
||||||
help='Verbose logging',
|
help='Verbose logging. Defaults to false.',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue