Last active
July 21, 2021 06:52
-
-
Save Sekaiichi/0860a3f596affc505a76551ab2e09a22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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