21.12.2016, 13:50
(
Last edited by BroZeus; 12/04/2017 at 06:22 PM.
)
API's for converting ******* video to mp3 or other formats are generally unreliable, sometimes the url returned by API works and sometimes it doesn't. I have tested over 3 different API for this all were unreliable.
Only fully reliable method imo is (requires that your server is hosted on vps/dedi that you have root access to) to host a php script on your vps/dedi that downloads ******* video then converts it to mp3 format then store that mp3 file on your vps and returns url for it.
Here is how I have done it:
Firstly install these two things on your vps :
1. ffmpeg (to convert downloaded video to mp3 format)
2. *******-dl (to download video from *******)
then you can simply use this script to download and convert it then return then link
Firstly place this file for say in path like example.com/yt2mp3.php
Then create a path example.com/files
Now make a http get request from your samp script to example.com/yt2mp3.php?id=XXX
Where XXX is video ID.
Now after execution of script is complete the title will be available via script output and to play the file simply play it from url example.com/files/XXX.mp3 (Where XXX is video ID that was originally passed)
Only fully reliable method imo is (requires that your server is hosted on vps/dedi that you have root access to) to host a php script on your vps/dedi that downloads ******* video then converts it to mp3 format then store that mp3 file on your vps and returns url for it.
Here is how I have done it:
Firstly install these two things on your vps :
1. ffmpeg (to convert downloaded video to mp3 format)
2. *******-dl (to download video from *******)
then you can simply use this script to download and convert it then return then link
PHP Code:
<?php
set_time_limit(0);
$id = $_GET['id'];
$url = "https://www.youtube.com/watch?v=".$id;
if(!file_exists("files/$id.mp3"))
{
exec("*******-dl --extract-audio --audio-format mp3 $url -o files/$id.mp3");
}
// get title
$info = json_decode(file_get_contents("https://www.*******.com/oembed?format=json&url=".$url), true);
if($info === null)echo "Invalid link?";
else echo $info['title'];
?>
Then create a path example.com/files
Now make a http get request from your samp script to example.com/yt2mp3.php?id=XXX
Where XXX is video ID.
Now after execution of script is complete the title will be available via script output and to play the file simply play it from url example.com/files/XXX.mp3 (Where XXX is video ID that was originally passed)