MegaSa1nt / GMDprivateServer

Geometry Dash Private Server
GNU General Public License v3.0
26 stars 28 forks source link

File song upload via YouTube #185

Open M336G opened 2 months ago

M336G commented 2 months ago

Add a tab to upload songs with a YouTube URL via the Cobalt API (only if the song file reupload option is enabled, of course).

masckmaster2007 commented 3 weeks ago
<?php
$music = 'https://www.youtube.com/watch?v=bv0_KXEwNUw';
$data = array(
    "url" => $music,
    "aFormat" => "mp3",
    "isAudioOnly" => true
);

$postdata = json_encode($data);

$ch = curl_init("https://api.cobalt.tools/api/json"); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
$result = json_decode(curl_exec($ch));
curl_close($ch);

if($result->status != "stream") exit("-1"); // Change to Dashboard error.
$musicFile = $result->url;
echo $musicFile;

Here's cobalt API already. Download link is stored at $musicFile. It's possible.

MegaSa1nt commented 3 weeks ago

Are these links permanent?

M336G commented 3 weeks ago

Are these links permanent?

Nah it uses the old API, so it'll probably be deprecated in the future

MegaSa1nt commented 3 weeks ago

Nah it uses the old API, so it'll probably be deprecated in the future

I mean output result links

masckmaster2007 commented 3 weeks ago
<?php
// assuming $music has been handled correctly
$music = 'https://www.youtube.com/watch?v=bv0_KXEwNUw';
$data = array(
    "url" => $music,
    "aFormat" => "mp3",
    "isAudioOnly" => true
);

$postdata = json_encode($data);

$ch = curl_init("https://api.cobalt.tools/api/json"); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
$result = json_decode(curl_exec($ch));
curl_close($ch);

if($result->status != "stream") exit("Fuck");

// change lol.mp3 with a random int.mp3 (see /dashboard/songs/index.php)
file_put_contents("lol.mp3", file_get_contents($result->url));

current POC, needs to be implemented correctly