feat(metadata): add OpenModelDB metadata provider and model source for upscalers

Add OpenModelDB (openmodeldb.info) as a metadata and download source for
the existing upscaler model type.

Metadata:
- New OpenModelDBClient: fetches the site's bulk JSON dumps, caches them
  on disk (24h TTL + ETag revalidation), and builds a local sha256 index
- New OpenModelDBModelMetadataProvider adapts catalogue entries to the
  CivitAI-shaped version dict contract; registered in the fallback chain
  behind the enable_openmodeldb_api setting (default on), gated to the
  upscaler sub-type so other model types never trigger the dump download
- Persisted provenance uses metadata_source "openmodeldb" plus a nested
  openmodeldb block (page URL, architecture, scale, license)

Images: paired-image LR/SR URLs are ephemeral imgdiff.net sessions, so
displayable images come from the site-hosted auto-generated thumbnails
(model-level cover leads images[], per-image thumbs for the rest); the
original comparison URL is kept in meta.comparisonUrl.

Downloads:
- New OpenModelDBSource (flat model ids, omdb: group prefix) with
  resource filename derivation that recovers names hidden mid-path
  (mediafire) or synthesizes {id}.{type} for folder links
- HTML-gateway mirrors (mediafire/mega/drive) are rejected with a clear
  manual-download hint instead of silently saving an HTML page as .pth
- ModelSource base gains is_valid_source_id / default_subdir_parts /
  resolve_download_url hooks so flat-id sources need no platform branches

UI: "View on OpenModelDB" link in the model modal (downloaded and
hash-enriched models), settings toggle next to the CivArchive one.
This commit is contained in:
Will Miao
2026-10-03 21:13:07 +08:00
parent 515469054c
commit 35f1ced41a
39 changed files with 2787 additions and 37 deletions
+51
View File
@@ -73,6 +73,7 @@ def _stub_settings(**overrides):
base = {
"enable_metadata_archive_db": False,
"enable_civarchive_api": True,
"enable_openmodeldb_api": False,
"metadata_provider_order": "civitai_archive_sqlite",
}
base.update(overrides)
@@ -99,6 +100,11 @@ async def _run_initialize(monkeypatch, settings):
"get_civarchive_client",
AsyncMock(return_value=object()),
)
monkeypatch.setattr(
metadata_service.ServiceRegistry,
"get_openmodeldb_client",
AsyncMock(return_value=object()),
)
# Make MetadataArchiveManager report a usable db path when enabled
fake_archive = SimpleNamespace(get_database_path=lambda: "/tmp/fake.db")
@@ -172,3 +178,48 @@ async def test_initialize_providers_single_provider_when_only_civitai(monkeypatc
assert "fallback" not in manager.providers
assert manager.default_provider == "civitai_api"
# ---------------------------------------------------------------------------
# initialize_metadata_providers — OpenModelDB gating + ordering
# ---------------------------------------------------------------------------
@pytest.mark.asyncio
async def test_initialize_providers_includes_openmodeldb_when_enabled(monkeypatch):
settings = _stub_settings(enable_openmodeldb_api=True)
manager = await _run_initialize(monkeypatch, settings)
assert "openmodeldb_api" in manager.providers
# Local-index lookups run before the rate-limited CivArchive network API.
assert _fallback_provider_order(manager) == [
"civitai_api",
"openmodeldb_api",
"civarchive_api",
]
@pytest.mark.asyncio
async def test_initialize_providers_openmodeldb_sqlite_preset(monkeypatch):
settings = _stub_settings(
enable_metadata_archive_db=True,
enable_openmodeldb_api=True,
metadata_provider_order="civitai_sqlite_archive",
)
manager = await _run_initialize(monkeypatch, settings)
assert _fallback_provider_order(manager) == [
"civitai_api",
"openmodeldb_api",
"sqlite",
"civarchive_api",
]
@pytest.mark.asyncio
async def test_initialize_providers_skips_openmodeldb_when_disabled(monkeypatch):
settings = _stub_settings(
enable_metadata_archive_db=True,
enable_openmodeldb_api=False,
)
manager = await _run_initialize(monkeypatch, settings)
assert "openmodeldb_api" not in manager.providers
assert _fallback_provider_order(manager) == ["civitai_api", "civarchive_api", "sqlite"]