Merge pull request #75 from alifhughes/add-get-clip-route
Add get clip route
This commit is contained in:
commit
cfa3e0ab7f
11
README.md
11
README.md
@ -124,6 +124,7 @@ Suno API currently mainly implements the following APIs:
|
|||||||
If no IDs are provided, all music will be returned.
|
If no IDs are provided, all music will be returned.
|
||||||
- `/api/get_limit`: Get quota Info
|
- `/api/get_limit`: Get quota Info
|
||||||
- `/api/extend_audio`: Extend audio length
|
- `/api/extend_audio`: Extend audio length
|
||||||
|
- `/api/clip`: Get clip information based on ID passed as query parameter `id`
|
||||||
- `/api/concat`: Generate the whole song from extensions
|
- `/api/concat`: Generate the whole song from extensions
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -170,6 +171,10 @@ def get_quota_information():
|
|||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
|
def get_clip(clip_id):
|
||||||
|
url = f"{base_url}/api/clip?id={clip_id}"
|
||||||
|
response = requests.get(url)
|
||||||
|
return response.json()
|
||||||
|
|
||||||
def generate_whole_song(clip_id):
|
def generate_whole_song(clip_id):
|
||||||
payloyd = {"clip_id": clip_id}
|
payloyd = {"clip_id": clip_id}
|
||||||
@ -243,6 +248,12 @@ async function getQuotaInformation() {
|
|||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getClipInformation(clipId) {
|
||||||
|
const url = `${baseUrl}/api/clip?id=${clipId}`;
|
||||||
|
const response = await axios.get(url);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const data = await generateAudioByPrompt({
|
const data = await generateAudioByPrompt({
|
||||||
prompt:
|
prompt:
|
||||||
|
|||||||
48
src/app/api/clip/route.ts
Normal file
48
src/app/api/clip/route.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import { NextResponse, NextRequest } from "next/server";
|
||||||
|
import { sunoApi } from "@/lib/SunoApi";
|
||||||
|
import { corsHeaders } from "@/lib/utils";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
export async function GET(req: NextRequest) {
|
||||||
|
if (req.method === 'GET') {
|
||||||
|
try {
|
||||||
|
const url = new URL(req.url);
|
||||||
|
const clipId = url.searchParams.get('id');
|
||||||
|
const audioInfo = await (await sunoApi).getClip(clipId);
|
||||||
|
|
||||||
|
return new NextResponse(JSON.stringify(audioInfo), {
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...corsHeaders
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching audio:', error);
|
||||||
|
|
||||||
|
return new NextResponse(JSON.stringify({ error: 'Internal server error' }), {
|
||||||
|
status: 500,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...corsHeaders
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return new NextResponse('Method Not Allowed', {
|
||||||
|
headers: {
|
||||||
|
Allow: 'GET',
|
||||||
|
...corsHeaders
|
||||||
|
},
|
||||||
|
status: 405
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function OPTIONS(request: Request) {
|
||||||
|
return new Response(null, {
|
||||||
|
status: 200,
|
||||||
|
headers: corsHeaders
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -29,6 +29,7 @@ export default function Docs() {
|
|||||||
ids. If no IDs are provided, all music will be returned.
|
ids. If no IDs are provided, all music will be returned.
|
||||||
- \`/api/get_limit\`: Get quota Info
|
- \`/api/get_limit\`: Get quota Info
|
||||||
- \`/api/extend_audio\`: Extend audio length
|
- \`/api/extend_audio\`: Extend audio length
|
||||||
|
- \`/api/clip\`: Get clip information based on ID passed as query parameter \`id\`
|
||||||
- \`/api/concat\`: Generate the whole song from extensions
|
- \`/api/concat\`: Generate the whole song from extensions
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
|
|||||||
@ -361,6 +361,17 @@ class SunoApi {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves information for a specific audio clip.
|
||||||
|
* @param clipId The ID of the audio clip to retrieve information for.
|
||||||
|
* @returns A promise that resolves to an object containing the audio clip information.
|
||||||
|
*/
|
||||||
|
public async getClip(clipId: string): Promise<object> {
|
||||||
|
await this.keepAlive(false);
|
||||||
|
const response = await this.client.get(`${SunoApi.BASE_URL}/api/clip/${clipId}`);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
public async get_credits(): Promise<object> {
|
public async get_credits(): Promise<object> {
|
||||||
await this.keepAlive(false);
|
await this.keepAlive(false);
|
||||||
const response = await this.client.get(`${SunoApi.BASE_URL}/api/billing/info/`);
|
const response = await this.client.get(`${SunoApi.BASE_URL}/api/billing/info/`);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user