Files
ComfyUI-Lora-Manager/services/civitai_client.py
2025-01-26 13:41:16 +08:00

35 lines
1.2 KiB
Python

import aiohttp
import os
import json
from typing import Optional, Dict
class CivitaiClient:
def __init__(self):
self.base_url = "https://civitai.com/api/v1"
self.session = aiohttp.ClientSession()
async def get_model_by_hash(self, model_hash: str) -> Optional[Dict]:
try:
async with self.session.get(f"{self.base_url}/model-versions/by-hash/{model_hash}") as response:
if response.status == 200:
return await response.json()
return None
except Exception as e:
print(f"API Error: {str(e)}")
return None
async def download_preview_image(self, image_url: str, save_path: str):
try:
async with self.session.get(image_url) as response:
if response.status == 200:
content = await response.read()
with open(save_path, 'wb') as f:
f.write(content)
return True
return False
except Exception as e:
print(f"Download Error: {str(e)}")
return False
async def close(self):
await self.session.close()