Beispiel #1
0
def _single_img_download(img: Page, img_dir: Path,
                         params: "QueryParams") -> Tuple[bool, str]:
    img_name, img_path, img_path_orig = _get_img_path(img, img_dir)
    if not _valid_img_type(img_name, params.early_icons_removal):
        if img_path.exists():
            img_path.unlink()

        return (False, "")

    if img_path.exists():
        return (False, img_path.name)

    if img_path_orig.exists():
        return (False, img_path_orig.name)

    if params.debug_info: print('Downloading image', img_name)
    try:
        urlretrieve(_get_url(img_name, params.img_width), img_path)
        return (True, img_path.name)
    except Exception as e:
        print(str(e))
        img.download(filename=img_path_orig, chunk_size=8 * 1024)
        return (True, img_path_orig.name)