From fa604ebc5e252aa8cb133c4c2990f149fce2d427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=8F=E6=98=B1?= Date: Sun, 23 Apr 2023 12:08:33 +0800 Subject: [PATCH] chore: Support more image formats for cover detection, while improving the compatibility of the element selector plugin. --- .gitignore | 1 + javascript/civitai_helper.js | 2 +- scripts/ch_lib/civitai.py | 8 ++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 1583181..72f001c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ scripts/__pycache__/ scripts/ch_lib/__pycache__/ setting.json +.idea \ No newline at end of file diff --git a/javascript/civitai_helper.js b/javascript/civitai_helper.js index 4454d0d..ee02245 100644 --- a/javascript/civitai_helper.js +++ b/javascript/civitai_helper.js @@ -430,7 +430,7 @@ onUiLoaded(() => { if (!extra_tabs) {console.log("can not find extra_tabs: " + tab_prefix+"_extra_tabs");} //get active extratab - const active_extra_tab = Array.from(get_uiCurrentTabContent().querySelectorAll('.extra-network-cards,.extra-network-thumbs')) + const active_extra_tab = Array.from(document.querySelectorAll('.extra-network-cards,.extra-network-thumbs')) .find(el => el.closest('.tabitem').style.display === 'block') ?.id.match(/^(txt2img|img2img)_(.+)_cards$/)[2] diff --git a/scripts/ch_lib/civitai.py b/scripts/ch_lib/civitai.py index 2a15ae7..affe4d7 100644 --- a/scripts/ch_lib/civitai.py +++ b/scripts/ch_lib/civitai.py @@ -319,16 +319,20 @@ def get_preview_image_by_model_path(model_path:str, max_size_preview, skip_nsfw_ return if not os.path.isfile(model_path): - util.printD("model_path is not a file: "+model_path) + util.printD("model_path is not a file: "+ model_path) return base, ext = os.path.splitext(model_path) + first_preview = base+".png" sec_preview = base+".preview.png" + + check_preview_files = [base + ext for ext in (".png", ".preview.png", ".jpg", ".preview.jpg", ".webp", ".preview.webp")] + info_file = base + suffix + model.info_ext # check preview image - if not os.path.isfile(sec_preview): + if not all(os.path.isfile(file) for file in check_preview_files): # need to download preview image util.printD("Checking preview image for model: " + model_path) # load model_info file