UNPKG

spotidownloader

Version:

A lightweight API to fetch Spotify track details and provide direct download links.

33 lines (26 loc) 939 B
const axios = require('axios'); const SpotifyDL = { api: 'https://spotifydl-api.gleeze.com/spotifydl', isValid(url) { return url.startsWith('https://open.spotify.com/track/'); }, async get(url) { if (!this.isValid(url)) return { error: 'Invalid Spotify URL' }; try { const { data } = await axios.get(`${this.api}?url=${url}`); if (!data.success) return { error: 'Failed to fetch track' }; return { title: data.trackInfo.title, artist: data.trackInfo.artist, album: data.trackInfo.album, cover: data.trackInfo.coverUrl, released: data.trackInfo.releaseDate, duration: data.trackInfo.duration, download: data.downloadUrl }; } catch { return { error: 'Fetch failed' }; } } }; module.exports = SpotifyDL;