Skip to content

Instantly share code, notes, and snippets.

@Sekaiichi
Last active July 21, 2021 06:52
Show Gist options
  • Save Sekaiichi/0860a3f596affc505a76551ab2e09a22 to your computer and use it in GitHub Desktop.
Save Sekaiichi/0860a3f596affc505a76551ab2e09a22 to your computer and use it in GitHub Desktop.
<?php
$uri = 'https://music.yandex.ru/handlers/playlist.jsx?owner=Sekaiichi8&kinds=3';
$responseRaw = file_get_contents($uri);
$response = json_decode($responseRaw);
$playlistTitle = $response->playlist->title;
$tracks = $response->playlist->tracks;
file_exists($playlistTitle . '.txt') ? unlink($playlistTitle . '.txt') : null;
// Генерация с нумерацией или без нее
$flagNums = true;
$numSong = 1;
foreach ($tracks as $track) {
$artistsNames = [];
foreach ($track->artists as $artist) {
$artistsNames[] = $artist->name;
}
$artistsNames = implode(', ', $artistsNames);
$flagNums ? $fullTrack = $numSong++ . ') ' . $artistsNames . ' - ' . $track->title . PHP_EOL :
$fullTrack = $artistsNames . ' - ' . $track->title . PHP_EOL;
file_put_contents($playlistTitle . '.txt', $fullTrack, FILE_APPEND);
}
echo 'Done!';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment