Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce "redundancy", so the check only happens once and that value is stored, allowing that value to be compared. #1201

Merged
merged 3 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PixivConstant.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

HTML_TEMPLATE = '<!DOCTYPE html> <html lang="ja"> <head> <title>%artistName% - %imageTitle%</title> <meta charset="utf-8"> <style type="text/css"> *{margin:0px; padding:0px; max-width:100%; overflow:auto;} body{text-align:center; background-color:#f3f5f8;} h1, h2, h5, p{text-align:left;} h1, h2, h5, p{padding-left:4%; padding-right:4%;} p{word-break:break-word; padding-top:0.5em; padding-bottom:0.5em;} span{padding:0px;} .title{margin-top:2rem; margin-bottom:2rem;} a{margin:auto;} .root{max-width:1280px; margin:auto; background-color:#ffffff;} .caption{display:grid;} .non-article.main, .non-article.images{position:fixed; overflow-y:scroll; background-color:#ffffff;} .non-article.main{top:0px; left:0px; height:100%; width:360px;} .non-article.images{top:0px; left:360px; height:100%;} @media screen and (max-aspect-ratio:4/5){.non-article.main{height:25%; width:100%;} .non-article.images{top:25%; left:0px; height:75%; width:100%;}} </style> </head> <body> <div class="root"> <div class="main"> %coverImage% <div class="title"> <h1>%imageTitle%</h1> <h5>%worksDate%</h5> </div> %body_text(article)% %text(non-article)% </div> %images(non-article)% </div> </body> </html>'

BUFFER_SIZE = 1024 * 128
BUFFER_SIZE = 512 * 1024

DOWNLOAD_PIXIV = "Pixiv"
DOWNLOAD_FANBOX = "Fanbox"
Expand Down
20 changes: 13 additions & 7 deletions PixivDownloadHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,30 @@ def download_image(caller,
req = None
try:
try:
does_file_exist = os.path.isfile(filename_save)

if not overwrite and not config.alwaysCheckFileSize:
PixivHelper.print_and_log(None, '\rChecking local filename...', newline=False)
if os.path.isfile(filename_save):
if does_file_exist:
PixivHelper.print_and_log('info', f"\rLocal file exists: {filename}")
return (PixivConstant.PIXIVUTIL_SKIP_DUPLICATE, filename_save)

# Issue #807
if config.checkLastModified and os.path.isfile(filename_save) and image is not None:
if config.checkLastModified and does_file_exist and image is not None:
local_timestamp = os.path.getmtime(filename_save)
remote_timestamp = time.mktime(image.worksDateDateTime.timetuple())
if local_timestamp == remote_timestamp:
PixivHelper.print_and_log('info', f"\rLocal file timestamp match with remote: {filename} => {image.worksDateDateTime}")
return (PixivConstant.PIXIVUTIL_SKIP_DUPLICATE, filename_save)

remote_file_size = get_remote_filesize(url, referer, config, notifier)
if does_file_exist:
remote_file_size = get_remote_filesize(url, referer, config, notifier)
else:
remote_file_size = -1
PixivHelper.print_and_log(None, f"\rSkipped getting remote file size because local file not exists")

# 837
if config.skipUnknownSize and os.path.isfile(filename_save) and remote_file_size == -1:
if config.skipUnknownSize and does_file_exist and remote_file_size == -1:
PixivHelper.print_and_log('info', f"\rSkipped because file exists and cannot get remote file size for: {filename}")
return (PixivConstant.PIXIVUTIL_SKIP_DUPLICATE, filename_save)

Expand All @@ -98,7 +104,7 @@ def download_image(caller,
# check if existing ugoira file exists
if filename.endswith(".zip"):
# non-converted zip (no animation.json)
if os.path.isfile(filename_save):
if does_file_exist:
old_size = os.path.getsize(filename_save)
# update for #451, always return identical?
check_result = PixivHelper.check_file_exists(overwrite, filename_save, remote_file_size, old_size, backup_old_file)
Expand All @@ -115,7 +121,7 @@ def download_image(caller,
handle_ugoira(image, filename_save, config, notifier)

return (check_result, filename)
elif os.path.isfile(filename_save):
elif does_file_exist:
# other image? files
old_size = os.path.getsize(filename_save)
check_result = PixivHelper.check_file_exists(overwrite, filename, remote_file_size, old_size, backup_old_file)
Expand Down Expand Up @@ -193,7 +199,7 @@ def download_image(caller,
os.rename(old_filename_save, filename_save)

# set last-modified and last-accessed timestamp
if image is not None and config.setLastModified and filename_save is not None and os.path.isfile(filename_save):
if image is not None and config.setLastModified and filename_save is not None and does_file_exist:
ts = time.mktime(image.worksDateDateTime.timetuple())
os.utime(filename_save, (ts, ts))

Expand Down