|
|
const express = require('express'); |
|
|
const axios = require('axios'); |
|
|
const NodeCache = require('node-cache'); |
|
|
const os = require('os'); |
|
|
const crypto = require('crypto'); |
|
|
const app = express(); |
|
|
const cache = new NodeCache({ stdTTL: 3600 }); |
|
|
const PORT = 7860; |
|
|
|
|
|
app.use(express.json()); |
|
|
|
|
|
|
|
|
function getSystemInfo() { |
|
|
return { |
|
|
os: os.type(), |
|
|
arch: os.arch(), |
|
|
cpu: os.cpus()[0].model, |
|
|
cpuLoad: os.loadavg()[0].toFixed(2), |
|
|
totalRAM: (os.totalmem() / 1024 / 1024).toFixed(2) + ' MB', |
|
|
freeRAM: (os.freemem() / 1024 / 1024).toFixed(2) + ' MB', |
|
|
uptime: (os.uptime() / 60).toFixed(2) + ' menit' |
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
app.get('/', (req, res) => { |
|
|
res.json({ |
|
|
status: "Server berjalan", |
|
|
systemInfo: getSystemInfo() |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
async function spotifydl(url) { |
|
|
try { |
|
|
const res = await axios.post('https://spotymate.com/api/download-track', { url }); |
|
|
return res.data.file_url; |
|
|
} catch (error) { |
|
|
throw new Error('Gagal mendapatkan URL unduhan'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function spotifyInfo(url) { |
|
|
try { |
|
|
const res = await axios.post('https://spotymate.com/api/get-metadata', { url }); |
|
|
return res.data.apiResponse.data; |
|
|
} catch (error) { |
|
|
throw new Error('Gagal mendapatkan metadata'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function generateShortToken() { |
|
|
return crypto.randomBytes(16).toString('hex'); |
|
|
} |
|
|
|
|
|
|
|
|
app.get('/download', async (req, res) => { |
|
|
const { url } = req.query; |
|
|
if (!url) return res.status(400).json({ error: 'URL Spotify diperlukan' }); |
|
|
|
|
|
try { |
|
|
const { data } = await axios.get(`https://backed-spotify.ex-project.my.id/download?url=${url}&signature=abcd5etyg2n89ewayyw`) |
|
|
const metadata = await spotifyInfo(url); |
|
|
const fileUrl = data.url |
|
|
const shortToken = generateShortToken(); |
|
|
cache.set(shortToken, { fileUrl, metadata }); |
|
|
|
|
|
res.json({ |
|
|
shortToken, |
|
|
downloadUrl: `https://rianofc-spotify.hf.space/spotify/result/${shortToken}`, |
|
|
metadata |
|
|
}); |
|
|
} catch (error) { |
|
|
res.status(500).json({ error: error.message }); |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
app.get('/spotify/result/:shortToken', async (req, res) => { |
|
|
const { shortToken } = req.params; |
|
|
const data = cache.get(shortToken); |
|
|
|
|
|
if (!data) return res.status(404).json({ error: 'Short token tidak ditemukan atau kadaluarsa' }); |
|
|
|
|
|
try { |
|
|
const fileBuffer = await axios.get(data.fileUrl, { responseType: 'arraybuffer' }); |
|
|
res.setHeader('Content-Type', 'audio/mpeg'); |
|
|
res.send(fileBuffer.data); |
|
|
} catch (error) { |
|
|
res.status(500).json({ error: 'Gagal mengambil file' }); |
|
|
} |
|
|
}); |
|
|
|
|
|
app.listen(PORT, () => { |
|
|
console.log(`Server berjalan di http://localhost:${PORT}`); |
|
|
}); |