Skip to content

Instantly share code, notes, and snippets.

@LT-SYAII
Last active November 12, 2025 03:31
Show Gist options
  • Save LT-SYAII/4441dd1c00f0b62b4edb7437f2965f5e to your computer and use it in GitHub Desktop.
Save LT-SYAII/4441dd1c00f0b62b4edb7437f2965f5e to your computer and use it in GitHub Desktop.
Spotify downloader (spotmate.online)
import axios from "axios";
class Spotdl {
constructor(url) {
if (!url) throw new Error("Mana URL nya min");
this.url = url;
this.baseURL = "https://spotmate.online";
this.userAgent =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120 Safari/537.36";
}
async getToken() {
const res = await axios.get(this.baseURL, {
headers: { "User-Agent": this.userAgent },
});
const html = res.data;
const match = html.match(
/<meta[^>]+(csrf[-_]?token|csrf|csrf_token)[^>]+content=["']([^"']+)["']/
);
if (!match) throw new Error("Token CSRF tidak ditemukan");
const token = match[2];
const cookie = (res.headers["set-cookie"] || [])
.map((c) => c.split(";")[0])
.join("; ");
return { token, cookie };
}
async run() {
const { token, cookie } = await this.getToken();
const headers = {
"Content-Type": "application/json",
"X-CSRF-TOKEN": token,
Cookie: cookie,
Referer: this.baseURL + "/",
"X-Requested-With": "XMLHttpRequest",
"User-Agent": this.userAgent,
};
let r = await axios
.post(this.baseURL + "/getTrackData", { spotify_url: this.url }, { headers })
.catch((e) => e.response);
if (r.status !== 200) throw new Error("Gagal ambil data metadata");
const meta = r.data;
r = await axios
.post(this.baseURL + "/convert", { urls: this.url }, { headers })
.catch((e) => e.response);
if (r.status !== 200) throw new Error("Gagal ambil link download");
const buffer = await axios.get(r.data.url, { responseType: "arraybuffer" }).catch(e => e.response);
return { metadata: meta, download: Buffer.from(buffer.data) || r.data };
}
}
// cara pakai nya
const data = new Spotdl("https://open.spotify.com/track/2VGT3UYAMvZPh49w6qb0Zk");
const result = await data.run();
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment