Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const axios = require("axios");
- class SunoFree {
- constructor() {
- this.API_KEY = "a03a378e05004f27b17ccd712721b18b"; // Ganti kalau punya API key sendiri
- this.API_URL = "https://api.topmediai.com/v1/music";
- }
- async requestMusic(payload) {
- try {
- const res = await axios.post(this.API_URL, payload, {
- headers: {
- "x-api-key": this.API_KEY,
- "Content-Type": "application/json",
- "User-Agent": "okhttp/5.0.0-alpha.3"
- }
- });
- if (res.data?.status === 200 && Array.isArray(res.data.data)) {
- return res.data.data.map((item) => ({
- title: item.title || "Lagu AI",
- audio_url: item.audio_file,
- duration: 0,
- image_url: item.image_file || "",
- tags: item.tags || "AI Music",
- mode: payload.is_auto
- ? "auto"
- : payload.instrumental
- ? "instrumental"
- : payload.lyrics
- ? "custom"
- : "normal"
- }));
- } else {
- throw new Error("Respons API tidak valid");
- }
- } catch (err) {
- throw new Error(err.response?.data?.message || err.message);
- }
- }
- // Mode normal → AI bikin lirik & judul otomatis
- async generateNormal(prompt) {
- return this.requestMusic({
- instrumental: 0,
- is_auto: 1,
- lyrics: "",
- prompt
- });
- }
- // Mode custom → user kasih genre & lirik, judul otomatis
- async generateCustom({ prompt, style, lyrics }) {
- if (!style || !lyrics) throw new Error("Genre dan lirik wajib diisi");
- return this.requestMusic({
- instrumental: 0,
- is_auto: 0,
- lyrics,
- prompt: `${prompt} in style ${style}`
- });
- }
- // Mode instrumental → tanpa lirik
- async generateInstrumental(prompt) {
- return this.requestMusic({
- instrumental: 1,
- is_auto: 0,
- lyrics: "",
- prompt
- });
- }
- }
- module.exports = new SunoFree();
Advertisement
Add Comment
Please, Sign In to add comment