diff --git a/modules/civitai/search_civitai.py b/modules/civitai/search_civitai.py index 07fc7f809..e3b116dc2 100644 --- a/modules/civitai/search_civitai.py +++ b/modules/civitai/search_civitai.py @@ -1,3 +1,4 @@ +import re import time from installer import log from modules.civitai.client_civitai import client @@ -20,12 +21,18 @@ def search_civitai( token: str = None, exact: bool = True, ) -> list[CivitModel]: - if not query: - log.error('CivitAI: empty query') + if not query and not tag and not sort: + log.error('CivitAI: no search criteria provided') return [] t0 = time.time() + # URL query → extract model ID (e.g. https://civitai.com/models/967405/nova-orange-xl) + url_match = re.match(r'https?://civitai\.com/models/(\d+)', query.strip()) + if url_match: + query = url_match.group(1) + log.info(f'CivitAI: extracted model id={query} from URL') + # Numeric query → single model fetch if query.isnumeric(): model = client.get_model(int(query), token=token) @@ -49,7 +56,7 @@ def search_civitai( all_models = response.items exact_models: list[CivitModel] = [] - if exact: + if exact and query: q_lower = query.lower() for model in all_models: names = [model.name.lower()]