1 Star 1 Fork 0

jobily/Suno-API

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cookie.py 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
cnwutong 提交于 1年前 . Update cookie.py
# -*- coding:utf-8 -*-
import os
import time
from http.cookies import SimpleCookie
from threading import Thread
import requests
from utils import COMMON_HEADERS
class SunoCookie:
def __init__(self):
self.cookie = SimpleCookie()
self.session_id = None
self.token = None
def load_cookie(self, cookie_str):
self.cookie.load(cookie_str)
def get_cookie(self):
return ";".join([f"{i}={self.cookie.get(i).value}" for i in self.cookie.keys()])
def set_session_id(self, session_id):
self.session_id = session_id
def get_session_id(self):
return self.session_id
def get_token(self):
return self.token
def set_token(self, token: str):
self.token = token
suno_auth = SunoCookie()
suno_auth.set_session_id(os.getenv("SESSION_ID"))
suno_auth.load_cookie(os.getenv("COOKIE"))
def update_token(suno_cookie: SunoCookie):
headers = {"cookie": suno_cookie.get_cookie()}
headers.update(COMMON_HEADERS)
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=4.72.0-snapshot.vc141245",
headers=headers,
)
resp_headers = dict(resp.headers)
set_cookie = resp_headers.get("Set-Cookie")
suno_cookie.load_cookie(set_cookie)
token = resp.json().get("jwt")
suno_cookie.set_token(token)
# print(set_cookie)
# print(f"*** token -> {token} ***")
def keep_alive(suno_cookie: SunoCookie):
while True:
try:
update_token(suno_cookie)
except Exception as e:
print(e)
finally:
time.sleep(5)
def start_keep_alive(suno_cookie: SunoCookie):
t = Thread(target=keep_alive, args=(suno_cookie,))
t.start()
start_keep_alive(suno_auth)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hubo/Suno-API.git
git@gitee.com:hubo/Suno-API.git
hubo
Suno-API
Suno-API
main

搜索帮助