Jump to content

Search music by API ?


Sasu

Recommended Posts

Posted

Hello.

I want to ask if it is there any page to search music by an API? Like FFS, I don't know how they get it but I guess with an API.

Thank you very much.

Posted

You can always use dom readers with php to get the data from the website and then send it to the client's pc. I'm not so expierenced with php. Here's the code what I have used:

<?php  
  
require "sdk/mta_sdk.php"; 
  
$input = mta::getInput(); 
$text = $input[0]; 
$search = $input[1]; 
  
  
  
function getdata($sex, $songField) 
{ 
$searchURL = "http://musicmp3.ru/search.html?text=" . rawurlencode($songField) . "&all=songs"; 
//$searchURL = "http://musicmp3.ru/search.html?text=angerfist&all=songs"; 
$html = file_get_contents($searchURL); 
  
$patternform = '/(<tbody.*<\/tbody>)/sm'; 
preg_match_all($patternform ,$html,$result); 
  
$DOM = new DOMDocument; 
$DOM->loadHTML($result[0][0]); 
$items = $DOM->getElementsByTagName('tr'); 
  
$xpath = new DOMXPath($DOM); 
$items = $xpath->query('//tr[@class]/td[@class]'); 
  
  
  
$counterDerp = 0; 
foreach ($items as $node) 
{ 
$kopnaam = $node->getAttribute('class'); 
  
    if ($kopnaam == "song__artist song__artist--search" ) { 
        $artistNaamReturn = $node->nodeValue; 
        $artistNaam = $artistNaamReturn; 
    } 
  
  
    if ($kopnaam == "song__name song__name--search" ) { 
        $songNaam = $node->nodeValue; 
  
    } 
  
  
  
    if ($kopnaam == "song__play_button" ) { 
        $streamKopUrl = $node->getElementsByTagName('a'); 
$counterDerp ++; 
        foreach ($streamKopUrl as $streamKop){ 
  
            $streamUrl = $streamKop->getAttribute('rel'); 
  
        } 
    } 
  
    if ((isset($songNaam)) and (is_string($songNaam)) and (isset($artistNaam)) and (is_string($artistNaam))) { 
        $returnsongArtist[$counterDerp] = $artistNaam; 
        $returnPath[$counterDerp] = $streamUrl; 
        $returnsongNaam[$counterDerp] = $songNaam; 
    } 
} 
  
  
if ((isset($returnsongNaam[1]))){ 
mta::doReturn($returnPath,$returnsongNaam, $returnsongArtist, $sex, $songField); 
} 
else { 
mta::doReturn("false","false", "false",$sex, $songField); 
} 
  
  
  
  
} 
getdata($text, $search); 
  
  
?>  
  

Now the problem was the streamUrl, I scripted this in 1 hour and then I didn't continued it because I had so many other things to do, but the problem was that if you are searching for let's say Ellie goudling, the wrong was song playing(You should look at their link generating)

I used it like this:

Server:

function result(value1, value2, value3, playerR, searched) 
if value1 ~= "ERROR" then 
triggerLatentClientEvent (playerR, "song:sendTable", 40000,false, playerR, value1, value2, value3 ) 
end 
end 
  
addEvent ( "search:database", true ) 
addEventHandler ( "search:database", root, function (player, song) 
callRemote ("http://82.72.66.169:1234/MTA/index2.php", result, player, song) 
end) 

Client:

  
  
pathTable = {} 
list = {} 
listartist = {} 
  
function add(string, artiststring) 
    table.insert(list, string) 
    table.insert(listartist, artiststring) 
end 
  
function addTable (value1, value2, value3) 
if value1 == "false" or value1 == nil then 
outputChatBox ( "No songs found derp!" ) 
else 
pathTable = {} 
list = {} 
listartist = {} 
  
  
for k, v in pairs(value2) do 
  
pathTable [ v ] = value1[tostring(k)] 
  
add(v, value3[tostring(k)]) 
end 
end 
loading = false 
loadrot = 0 
end 
addEvent ( "song:sendTable", true ) 
addEventHandler ( "song:sendTable", root, addTable ) 

Posted

Thank you very much. Well, I think I will call a friend who knows php to get the mp3 stream url.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...