v1.5.4
parent
6d5a7d2b74
commit
f9c7d877c3
|
|
@ -168,6 +168,9 @@ From v1.5, v1.x goes into maintenance phase.
|
||||||
Enjoy!
|
Enjoy!
|
||||||
|
|
||||||
# Change Log
|
# Change Log
|
||||||
|
## v1.5.4
|
||||||
|
* set sys.stdout to utf-8
|
||||||
|
|
||||||
## v1.5.3
|
## v1.5.3
|
||||||
* When downloading a model by url, check if target model version is already existed in user selected sub-folder.
|
* When downloading a model by url, check if target model version is already existed in user selected sub-folder.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ model_type_dict = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# get image with full size
|
# get image with full size
|
||||||
# width is in number, not string
|
# width is in number, not string
|
||||||
# return: url str
|
# return: url str
|
||||||
|
|
@ -42,7 +43,7 @@ def get_model_info_by_hash(hash:str):
|
||||||
util.printD("hash is empty")
|
util.printD("hash is empty")
|
||||||
return
|
return
|
||||||
|
|
||||||
r = requests.get(url_dict["hash"]+hash)
|
r = requests.get(url_dict["hash"]+hash, headers=util.def_headers)
|
||||||
if not r.ok:
|
if not r.ok:
|
||||||
if r.status_code == 404:
|
if r.status_code == 404:
|
||||||
# this is not a civitai model
|
# this is not a civitai model
|
||||||
|
|
@ -79,7 +80,7 @@ def get_model_info_by_id(id:str) -> dict:
|
||||||
util.printD("id is empty")
|
util.printD("id is empty")
|
||||||
return
|
return
|
||||||
|
|
||||||
r = requests.get(url_dict["modelId"]+str(id))
|
r = requests.get(url_dict["modelId"]+str(id), headers=util.def_headers)
|
||||||
if not r.ok:
|
if not r.ok:
|
||||||
if r.status_code == 404:
|
if r.status_code == 404:
|
||||||
# this is not a civitai model
|
# this is not a civitai model
|
||||||
|
|
@ -115,7 +116,7 @@ def get_version_info_by_version_id(id:str) -> dict:
|
||||||
util.printD("id is empty")
|
util.printD("id is empty")
|
||||||
return
|
return
|
||||||
|
|
||||||
r = requests.get(url_dict["modelVersionId"]+str(id))
|
r = requests.get(url_dict["modelVersionId"]+str(id), headers=util.def_headers)
|
||||||
if not r.ok:
|
if not r.ok:
|
||||||
if r.status_code == 404:
|
if r.status_code == 404:
|
||||||
# this is not a civitai model
|
# this is not a civitai model
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ def dl(url, folder, filename, filepath):
|
||||||
file_path = os.path.join(folder, filename)
|
file_path = os.path.join(folder, filename)
|
||||||
|
|
||||||
# first request for header
|
# first request for header
|
||||||
rh = requests.get(url, stream=True, verify=False)
|
rh = requests.get(url, stream=True, verify=False, headers=util.def_headers)
|
||||||
# get file size
|
# get file size
|
||||||
total_size = 0
|
total_size = 0
|
||||||
total_size = int(rh.headers['Content-Length'])
|
total_size = int(rh.headers['Content-Length'])
|
||||||
|
|
@ -76,6 +76,8 @@ def dl(url, folder, filename, filepath):
|
||||||
|
|
||||||
# create header range
|
# create header range
|
||||||
headers = {'Range': 'bytes=%d-' % downloaded_size}
|
headers = {'Range': 'bytes=%d-' % downloaded_size}
|
||||||
|
headers['User-Agent'] = util.def_headers['User-Agent']
|
||||||
|
|
||||||
# download with header
|
# download with header
|
||||||
r = requests.get(url, stream=True, verify=False, headers=headers)
|
r = requests.get(url, stream=True, verify=False, headers=headers)
|
||||||
|
|
||||||
|
|
@ -90,7 +92,8 @@ def dl(url, folder, filename, filepath):
|
||||||
|
|
||||||
# progress
|
# progress
|
||||||
progress = int(50 * downloaded_size / total_size)
|
progress = int(50 * downloaded_size / total_size)
|
||||||
sys.stdout.write("\r[%s%s] %d%%" % ('█' * progress, ' ' * (50 - progress), 100 * downloaded_size / total_size))
|
sys.stdout.reconfigure(encoding='utf-8')
|
||||||
|
sys.stdout.write("\r[%s%s] %d%%" % ('-' * progress, ' ' * (50 - progress), 100 * downloaded_size / total_size))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,9 @@ import shutil
|
||||||
|
|
||||||
version = "1.5.3"
|
version = "1.5.3"
|
||||||
|
|
||||||
|
def_headers = {'User-Agent': 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148'}
|
||||||
|
|
||||||
|
|
||||||
# print for debugging
|
# print for debugging
|
||||||
def printD(msg):
|
def printD(msg):
|
||||||
print(f"Civitai Helper: {msg}")
|
print(f"Civitai Helper: {msg}")
|
||||||
|
|
@ -30,7 +33,7 @@ def gen_file_sha256(filname):
|
||||||
def download_file(url, path):
|
def download_file(url, path):
|
||||||
printD("Downloading file from: " + url)
|
printD("Downloading file from: " + url)
|
||||||
# get file
|
# get file
|
||||||
r = requests.get(url, stream=True)
|
r = requests.get(url, stream=True, headers=def_headers)
|
||||||
if not r.ok:
|
if not r.ok:
|
||||||
printD("Get error code: " + str(r.status_code))
|
printD("Get error code: " + str(r.status_code))
|
||||||
printD(r.text)
|
printD(r.text)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue