Answer the question
In order to leave comments, you need to log in
Yandex music: how to download the full track?
Good afternoon! Tell me, before it was possible to download audio from Yandex Music in this way, now it turns out to download only segments of 30 seconds, how can I download the song in full now?
<?php
$ch = curl_init('https://api.music.yandex.net/tracks/' . $ID . '/download-info');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
$json = json_decode(curl_exec($ch));
curl_close($ch);
foreach ($json->result as $track) {
if ($track->codec == 'mp3') {
$InfoUrl = $track->downloadInfoUrl;
break;
}
}
$ch = curl_init($InfoUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
$xml = new SimpleXMLElement(curl_exec($ch));
curl_close($ch);
$md5 = md5('XGRlBW9FXlekgbPrRHuSiA' . substr($xml->path, 1) . $xml->s);
$urlBody = "/get-mp3/$md5/" . $xml->ts . $xml->path;
$url = "https://" . $xml->host . $urlBody;
$fileName = __DIR__ . '/filename.mp3';
$fp = fopen($fileName, 'w+') or die('Unable to write a file');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1000);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question