Skip to content

Commit 7a82fd9

Browse files
committed
add configurable download buffer
1 parent af4fc9c commit 7a82fd9

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

PixivConfig.py

+1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ class PixivConfig():
217217
ConfigItem("DownloadControl", "postProcessingCmd", ""),
218218
ConfigItem("DownloadControl", "extensionFilter", ""),
219219
ConfigItem("DownloadControl", "aiDisplayFewer", False),
220+
ConfigItem("DownloadControl", "downloadBuffer", 512, restriction=lambda x: int(x) > 0),
220221
]
221222

222223
def __init__(self):

PixivConstant.py

-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
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>'
2828

29-
BUFFER_SIZE = 512 * 1024
30-
3129
DOWNLOAD_PIXIV = "Pixiv"
3230
DOWNLOAD_FANBOX = "Fanbox"
3331
DOWNLOAD_SKETCH = "Sketch"

PixivHelper.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ def makeSubdirs(filename):
758758
def download_image(url, filename, res, file_size, overwrite):
759759
''' Actual download, return the downloaded filesize and saved filename.'''
760760
start_time = datetime.now()
761+
global _config
762+
BUFFER_SIZE = _config.downloadBuffer * 1024
761763

762764
# try to save to the given filename + .pixiv extension if possible
763765
try:
@@ -779,10 +781,8 @@ def download_image(url, filename, res, file_size, overwrite):
779781
curr = 0
780782
msg_len = 0
781783
try:
782-
# read the first 4kb for ui refresh
783-
save.write(res.read(4096))
784784
while True:
785-
save.write(res.read(PixivConstant.BUFFER_SIZE))
785+
save.write(res.read(BUFFER_SIZE))
786786
curr = save.tell()
787787
msg_len = print_progress(curr, file_size, msg_len)
788788

0 commit comments

Comments
 (0)