R
R
rikorit7462020-10-18 11:45:36
PHP
rikorit746, 2020-10-18 11:45:36

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

1 answer(s)
V
vitaly_74, 2020-10-19
@vitaly_74

only at first atvorization as a user, and then emit listening - while listening, he will give parts of mp3, glue them together and save. the only way. more crap = but it works)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question