- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
<?php
$data = file_get_contents('https://music.yandex.ru/users/[данные удалены]/playlists/[данные удалены]');
$data = json_decode($data);
$tracks = $data->result->tracks;
$track = $tracks[$argv[1]]; // передаём номер песни из плейлиста
/* Step 1 */
$trackId = $track->track->id;
$albumId = $track->track->albums[0]->id;
$time = strval(time()) . '000';
$url1 = 'https://music.yandex.ru/api/v2.1/handlers/track/' . $trackId . '%3A' . $albumId . '/web-user_playlists-playlist-track-saved/download/m?hq=0&external-domain=music.yandex.ru&overembed=no&__t=' . $time;
$options['http']['header'] = "Accept: application/json; q=1.0, text/*; q=0.8, */*; q=0.1\r\n"
. "X-Retpath-Y: https%3A%2F%2Fmusic.yandex.ru%2F\r\n"
. "X-Requested-With: XMLHttpRequest\r\n"
. "User-Agent: Mozilla/5.0 [данные удалены]\r\n"
. "Cookie: [данные удалены]\r\n";
$context = stream_context_create($options);
$data = file_get_contents($url1, false, $context);
$data = json_decode($data);
/* Step 2 */
$time = strval(time()) . '000';
$url2 = 'https:' . $data->src . '&format=json&external-domain=music.yandex.ru&overembed=no&__t=' . $time;
$data = file_get_contents($url2);
$data = json_decode($data);
/* Step 3 */
$salt = 'XGRlBW9FXlekgbPrRHuSiA';
$hash = md5($salt . substr($data->path, 1) . $data->s);
$url3 = 'https://' . $data->host . '/get-mp3/' . $hash . '/' . $data->ts . $data->path;
$name = $track->track->title;
if(isset($track->track->version)) {
$name .= ' (' . $track->track->version . ')';
}
$artists = array();
foreach($track->track->artists as $artist) {
$artists[] = $artist->name;
}
$name = implode(',', $artists) . ' - ' . $name;
$name = strtr($name, ':/\\*?<|>', '________');
$name = str_replace('"', '”', $name);
$name = mb_substr($name, 0, 255-4);
copy($url3, $name . '.mp3');