[Backport] Add option to disable image file size check (close #170) (#228)

This commit is backport from
[saveweb/wikiteam3](https://github.com/saveweb/wikiteam3) all credit
goes to the original author.

Close #170 
Fix size mismatch error when some wiki do server-side image
resizing/compression without re-upload/update data in wiki.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
pull/409/head
sian1468 5 months ago committed by GitHub
parent 265855dff2
commit eb6e38e28c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -129,6 +129,11 @@ def getArgumentParser():
action="store_true",
help="Bypass CDN image compression. (CloudFlare Polish, etc.)",
)
groupDownload.add_argument(
"--disable-image-verify",
action="store_true",
help="Don't verify image size and hash while downloading. (useful for wikis with server-side image resizing)",
)
groupDownload.add_argument(
"--namespaces",
metavar="1,2,3",
@ -469,6 +474,7 @@ def getParameters(params=None) -> Tuple[Config, Dict]:
"session": session,
"stdout_log_path": args.stdout_log_path,
"bypass_cdn_image_compression": args.bypass_cdn_image_compression,
"disable_image_verify": args.disable_image_verify,
}
# calculating path, if not defined by user with --path=

@ -48,6 +48,7 @@ class Image:
c_savedImageDescs = 0
bypass_cdn_image_compression: bool = other["bypass_cdn_image_compression"]
disable_image_verify: bool = other["disable_image_verify"]
def modify_params(params: Optional[Dict] = None) -> Dict:
"""bypass Cloudflare Polish (image optimization)"""
@ -130,7 +131,11 @@ class Image:
if r.status_code == 200:
try:
if size == "False" or len(r.content) == int(size):
if (
size == "False"
or len(r.content) == int(size)
or disable_image_verify
):
# size == 'False' means size is unknown
with open(filename3, "wb") as imagefile:
imagefile.write(r.content)

Loading…
Cancel
Save