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

View file

@ -1,14 +0,0 @@
base_url: "https://studio-api.suno.ai"
subscribe:
500: a79f3640-d366-4c21-8d85-b35dad751f70
4000: 4cb5c6d9-bdb2-4bc1-9f62-c2cc55d48586
accounts:
account_1:
session_id: xxx
cookie: xxx
account_2:
session_id: xxx
cookie: xxx

View file

@ -81,7 +81,7 @@ def update_token(suno_cookie: SunoCookie):
session_id = suno_cookie.get_session_id()
resp = requests.post(
url=f"https://clerk.suno.com/v1/client/sessions/{session_id}/tokens?_clerk_js_version=5.16.1",
url=f"https://clerk.suno.com/v1/client/sessions/{session_id}/tokens?_clerk_js_version=5.26.1",
headers=headers,
)

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(

26
report.py Normal file
View file

@ -0,0 +1,26 @@
import requests
import json
from logger import logger
#feishu_webhook_url = "https://open.feishu.cn/open-apis/bot/v2/hook/0a627129-bfe9-4958-a1c8-9dd38ece6016"
feishu_webhook_url = "https://open.feishu.cn/open-apis/bot/v2/hook/051679ae-0bef-4a21-9ff7-25fd76cd73ee"
def send_feishu_notification_text(message):
headers = {
'Content-Type': 'application/json;charset=utf-8'
}
payload = {
"msg_type": "text",
"content": {
"text": message
}
}
try:
response = requests.post(feishu_webhook_url, headers=headers, data=json.dumps(payload))
if response.status_code == 200:
logger.info(f"飞书通知发送成功: {message}")
else:
logger.error(f"飞书通知发送失败,状态码: {response.status_code},消息: {message}")
except requests.exceptions.RequestException as e:
logger.error(f"飞书通知发送失败: {e},消息: {message}")

View file

@ -6,7 +6,7 @@ from logger import logger
COMMON_HEADERS = {
"Content-Type": "text/plain;charset=UTF-8",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
"Referer": "https://suno.com",
"Referer": "https://suno.com/",
"Origin": "https://suno.com",
}
@ -37,7 +37,7 @@ async def fetch(url, headers=None, data=None, method="POST"):
async def get_feed(url, ids, token):
headers = {"Authorization": f"Bearer {token}"}
api_url = f"{url}/api/feed/?ids={ids}"
api_url = f"{url}/api/feed/v2?ids={ids}"
response = await fetch(api_url, headers, method="GET")
return response
@ -70,7 +70,8 @@ async def get_credits(url,token):
"credits_left": respose['total_credits_left'],
"period": respose['period'],
"monthly_limit": respose['monthly_limit'],
"monthly_usage": respose['monthly_usage']
"monthly_usage": respose['monthly_usage'],
"subscription_type": respose['subscription_type']
}
async def recharge(url,data, token):
@ -86,5 +87,5 @@ async def get_expire(cookie):
logger.error("Invalid cookie at get expire")
raise
headers = {"Cookie": cookie}
api_url = "https://clerk.suno.com/v1/client?_clerk_js_version=5.16.1"
api_url = "https://clerk.suno.com/v1/client?_clerk_js_version=5.26.1"
return await fetch(api_url, headers, method="GET")