File size: 3,262 Bytes
d5c8a20
 
 
 
0fc9257
b029b5a
d5c8a20
b029b5a
 
 
 
d5c8a20
 
 
 
 
 
 
 
 
 
 
b029b5a
 
d5c8a20
 
 
 
 
 
 
b029b5a
d5c8a20
 
 
 
 
 
 
b029b5a
d5c8a20
b029b5a
d5c8a20
 
 
 
 
 
 
8ac3a35
d5c8a20
b029b5a
d5c8a20
 
0fc9257
d5c8a20
8ac3a35
d5c8a20
 
 
 
 
 
326cb11
d5c8a20
326cb11
d5c8a20
 
 
 
 
fc54eaf
d5c8a20
 
 
 
8ac3a35
b029b5a
 
d5c8a20
 
 
 
b029b5a
d5c8a20
b029b5a
d5c8a20
 
 
 
 
 
 
b029b5a
 
 
 
d5c8a20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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 }); // Cache 1 jam
const PORT = 7860;

app.use(express.json());

// Fungsi untuk mendapatkan informasi sistem
function getSystemInfo() {
    return {
        os: os.type(), // Jenis OS (Linux, Windows, dll.)
        arch: os.arch(), // Arsitektur CPU (x64, arm, dll.)
        cpu: os.cpus()[0].model, // Model CPU
        cpuLoad: os.loadavg()[0].toFixed(2), // Load CPU (1 menit terakhir)
        totalRAM: (os.totalmem() / 1024 / 1024).toFixed(2) + ' MB', // Total RAM
        freeRAM: (os.freemem() / 1024 / 1024).toFixed(2) + ' MB', // RAM yang tersisa
        uptime: (os.uptime() / 60).toFixed(2) + ' menit' // Waktu uptime sistem
    };
}

// Endpoint utama untuk mendapatkan info sistem
app.get('/', (req, res) => {
    res.json({
        status: "Server berjalan",
        systemInfo: getSystemInfo()
    });
});

// Fungsi untuk mendapatkan file unduhan dari Spotymate
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');
    }
}

// Fungsi untuk mendapatkan metadata lagu dari Spotymate
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');
    }
}

// Generate short token
function generateShortToken() {
    return crypto.randomBytes(16).toString('hex');
}

// Endpoint GET untuk mengunduh lagu dari Spotify
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 });
    }
});

// Endpoint untuk mendapatkan buffer file dari short token
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}`);
});