-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathutils.py
More file actions
66 lines (51 loc) · 1.9 KB
/
utils.py
File metadata and controls
66 lines (51 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding:utf-8 -*-
import json
import os
import time
import requests
COMMON_HEADERS = {
"Content-Type": "application/x-www-form-urlencoded",
# "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",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36",
"Referer": "https://suno.com/",
"Origin": "https://suno.com",
}
BASE_URL = "https://studio-api.suno.ai"
def fetch(url, headers=None, data=None, method="POST"):
if headers is None:
headers = {}
headers.update(COMMON_HEADERS)
if data is not None:
data = json.dumps(data)
try:
resp = None
if method == "GET":
resp = requests.get(url=url, headers=headers)
else:
resp = requests.post(url=url, headers=headers, data=data)
if resp.status_code != 200:
print(resp.text)
return resp.json()
except Exception as e:
return {"detail":str(e)}
def get_feed(ids, token):
headers = {"Authorization": f"Bearer {token}"}
api_url = f"{BASE_URL}/api/feed/?ids={ids}"
response = fetch(api_url, headers, method="GET")
return response
def generate_music(data, token):
headers = {"Authorization": f"Bearer {token}"}
api_url = f"{BASE_URL}/api/generate/v2/"
response = fetch(api_url, headers, data)
return response
def generate_lyrics(prompt, token):
headers = {"Authorization": f"Bearer {token}"}
api_url = f"{BASE_URL}/api/generate/lyrics/"
data = {"prompt": prompt}
return fetch(api_url, headers, data)
def get_lyrics(lid, token):
headers = {"Authorization": f"Bearer {token}"}
api_url = f"{BASE_URL}/api/generate/lyrics/{lid}"
return fetch(api_url, headers, method="GET")
def local_time():
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())