first commit

This commit is contained in:
“xHuPo” 2024-10-17 12:01:35 +08:00
parent 973c47ff25
commit 4b01ff4c75
5 changed files with 40 additions and 21 deletions

10
main.py
View file

@ -10,6 +10,7 @@ from config import Config
from utils import logger, generate_lyrics, generate_music, get_feed, get_lyrics, get_credits, recharge, get_expire
from cookie import LoadAccounts,reload_threads
from accounts import accounts_info,accounts_list
from report import send_feishu_notification_text
app = FastAPI()
@ -30,6 +31,9 @@ def get_least_recently_used_account():
available_accounts = [account for account in suno_auth if account.get_status()]
if available_accounts == []:
logger.error({"accounts_err": "no account available"})
#send_feishu_notification_text("!! 严重!! sunoAPI: no account available!! 开始尝试重载配置")
reload_configuration()
#send_feishu_notification_text("重载已完成,若还有报错,请通知相应人员")
return None
return min(available_accounts, key=lambda x: x.last_called)
@ -53,8 +57,9 @@ async def get_root():
@app.get("/reload")
async def reload_configuration():
global threads, config_loader,config
global threads, config_loader, config
try:
config = None
config_loader.reload_config()
config = config_loader.config
logger.info({"config_reload": "config reload successfully"})
@ -83,7 +88,7 @@ async def get_accounts_info():
account_id = suno_cookie.account_id
try:
resp = await fetch_credits(get_token(account_id))
if resp["credits_left"] < 10:
if resp["subscription_type"] == False:
suno_cookie.set_status(False)
except Exception as e:
logger.error({"get_credits_err": f"{account_id} token invalid, {e}"})
@ -108,6 +113,7 @@ async def generate(
try:
resp = await generate_music(config.base_url, data.model_dump(), token)
logger.info({"generate_resp": resp})
return {"account_id": suno_cookie.account_id, **resp}
except Exception as e:
raise HTTPException(