diff --git a/README.md b/README.md
index 35e103b..8636839 100644
--- a/README.md
+++ b/README.md
@@ -125,6 +125,10 @@ Enjoy!
# Change Log
+## v1.4.1
+* When checking new versions, also searching and ignore already existed ones.
+* Add version number to the bottom of this extension's tab
+
## v1.4
* Support checking model's new version, display the result in UI and offer download url
* Remove addintional sub tabs on extension tab. make ui simpler.
diff --git a/scripts/civitai_helper.py b/scripts/civitai_helper.py
index d6921a2..768daf9 100644
--- a/scripts/civitai_helper.py
+++ b/scripts/civitai_helper.py
@@ -24,6 +24,7 @@ from scripts.lib import setting
from scripts.lib import civitai
# init
+version = "1.4.1"
model.get_custom_model_folder()
setting.load()
@@ -105,7 +106,11 @@ def on_ui_tabs():
save_setting_btn = gr.Button(value="Save Setting", elem_id="ch_save_setting_btn")
general_log_md = gr.Markdown(value="", elem_id="ch_general_log_md")
- # hidden component for js, not in any tab
+
+ # ====Footer====
+ gr.Markdown(f"
version:{version}")
+
+ # ====hidden component for js, not in any tab====
js_msg_txtbox = gr.Textbox(label="Request Msg From Js", visible=False, lines=1, value="", elem_id="ch_js_msg_txtbox")
py_msg_txtbox = gr.Textbox(label="Response Msg From Python", visible=False, lines=1, value="", elem_id="ch_py_msg_txtbox")
js_open_url_btn = gr.Button(value="Open Model Url", visible=False, elem_id="ch_js_open_url_btn")
diff --git a/scripts/lib/civitai.py b/scripts/lib/civitai.py
index cb830d3..371f9e5 100644
--- a/scripts/lib/civitai.py
+++ b/scripts/lib/civitai.py
@@ -351,9 +351,65 @@ def get_preview_image_by_model_path(model_path:str, max_size_preview, skip_nsfw_
break
+
+# search local model by version id in 1 folder, no subfolder
+# return - model_info
+def search_local_model_info_by_version_id(folder:str, version_id:int) -> dict:
+ util.printD("Searching local model by version id")
+ util.printD("folder: " + folder)
+ util.printD("version_id: " + str(version_id))
+
+ if not folder:
+ util.printD("folder is none")
+ return
+
+ if not os.path.isdir(folder):
+ util.printD("folder is not a dir")
+ return
+
+ if not version_id:
+ util.printD("version_id is none")
+ return
+
+ # search civitai model info file
+ for filename in os.listdir(folder):
+ # check ext
+ base, ext = os.path.splitext(filename)
+ if ext == model.info_ext:
+ # find info file
+ if len(base) < 9:
+ # not a civitai info file
+ continue
+
+ if base[-8:] == suffix:
+ # find a civitai info file
+ path = os.path.join(folder, filename)
+ model_info = model.load_model_info(path)
+ if not model_info:
+ continue
+
+ if "id" not in model_info.keys():
+ continue
+
+ id = model_info["id"]
+ if not id:
+ continue
+
+ # util.printD(f"Compare version id, src: {id}, target:{version_id}")
+ if str(id) == str(version_id):
+ # find the one
+ return model_info
+
+
+ return
+
+
+
+
+
# check new version for a model by model path
# return (model_path, model_id, model_name, new_verion_id, new_version_name, description, download_url, img_url)
-def check_model_new_version_by_path(model_path:str) -> tuple:
+def check_model_new_version_by_path(model_path:str, delay:float=1) -> tuple:
if not model_path:
util.printD("model_path is empty")
return
@@ -390,6 +446,10 @@ def check_model_new_version_by_path(model_path:str) -> tuple:
# get model info by id from civitai
model_info = get_model_info_by_id(model_id)
+ # delay before next request, to prevent to be treat as DDoS
+ util.printD(f"delay:{delay} second")
+ time.sleep(delay)
+
if not model_info:
return
@@ -467,7 +527,7 @@ def check_model_new_version_by_path(model_path:str) -> tuple:
# check model's new version
# parameter: delay - float, how many seconds to delay between each request to civitai
# return: new_versions - a list for all new versions, each one is (model_path, model_id, model_name, new_verion_id, new_version_name, description, download_url, img_url)
-def check_models_new_version_by_model_types(model_types:list, delay:float=0.5) -> list:
+def check_models_new_version_by_model_types(model_types:list, delay:float=1) -> list:
util.printD("Checking models' new version")
if not model_types:
@@ -502,15 +562,34 @@ def check_models_new_version_by_model_types(model_types:list, delay:float=0.5) -
base, ext = os.path.splitext(item)
if ext in model.exts:
# find a model
- r = check_model_new_version_by_path(item)
-
- # delay before next request, to prevent to be treat as DDoS
- util.printD(f"delay:{delay} second")
- time.sleep(delay)
+ r = check_model_new_version_by_path(item, delay)
if not r:
continue
+ model_path, model_id, model_name, current_version_id, new_version_name, description, downloadUrl, img_url = r
+ # check exist
+ if not current_version_id:
+ continue
+
+ # check this version id in list
+ is_already_in_list = False
+ for new_version in new_versions:
+ if current_version_id == new_version[3]:
+ # already in list
+ is_already_in_list = True
+ break
+
+ if is_already_in_list:
+ util.printD("New version is already in list")
+ continue
+
+ # search this new version id to check if this model is already downloaded
+ target_model_info = search_local_model_info_by_version_id(root, current_version_id)
+ if target_model_info:
+ util.printD("New version is already existed")
+ continue
+
# add to list
new_versions.append(r)
@@ -518,3 +597,5 @@ def check_models_new_version_by_model_types(model_types:list, delay:float=0.5) -
return new_versions
+
+
diff --git a/scripts/lib/general_action.py b/scripts/lib/general_action.py
deleted file mode 100644
index 72a5047..0000000
--- a/scripts/lib/general_action.py
+++ /dev/null
@@ -1,11 +0,0 @@
-# -*- coding: UTF-8 -*-
-# handle msg between js and python side
-import os
-import json
-import requests
-import shutil
-import webbrowser
-from . import util
-from . import model
-from . import civitai
-from . import msg_handler
diff --git a/scripts/lib/model.py b/scripts/lib/model.py
index 72926c4..a264415 100644
--- a/scripts/lib/model.py
+++ b/scripts/lib/model.py
@@ -54,7 +54,7 @@ def write_model_info(path, model_info):
def load_model_info(path):
- util.printD("Load model info from file: " + path)
+ # util.printD("Load model info from file: " + path)
model_info = None
with open(path, 'r') as f:
try:
diff --git a/scripts/lib/model_action_civitai.py b/scripts/lib/model_action_civitai.py
index 756b13c..fe0a014 100644
--- a/scripts/lib/model_action_civitai.py
+++ b/scripts/lib/model_action_civitai.py
@@ -44,7 +44,7 @@ def scan_model(max_size_preview, skip_nsfw_preview):
output = "Failed to get model_info"
util.printD(output)
return output+", check console log for detail"
-
+
# write model info to file
model.write_model_info(info_file, model_info)