Skip to content
Snippets Groups Projects

Resolve "Add a generate playlist from "almost top played artists""

3 files
+ 91
6
Compare changes
  • Side-by-side
  • Inline

Files

+ 44
2
@@ -55,7 +55,8 @@ $templateData = [
@@ -55,7 +55,8 @@ $templateData = [
];
];
$generatePlaylistFromPlaylist = isset($_GET['generate-playlist-from-playlist']);
$generatePlaylistFromPlaylist = isset($_GET['generate-playlist-from-playlist']);
$generatePlaylistFromArtists = isset($_GET['generate-playlist-top-artists']);
$generatePlaylistFromSelectedTopArtists = isset($_GET['generate-playlist-top-artists']);
 
$generatePlaylistFromRandomTopArtists = isset($_GET['generate-playlist-random-top-artists']);
if ($generatePlaylistFromPlaylist) {
if ($generatePlaylistFromPlaylist) {
$selectedPlaylists = $_GET['selected-playlist'];
$selectedPlaylists = $_GET['selected-playlist'];
@@ -109,7 +110,9 @@ if ($generatePlaylistFromPlaylist) {
@@ -109,7 +110,9 @@ if ($generatePlaylistFromPlaylist) {
$newPlaylist = createPlaylistWithRandomTracks($api, $recommendedTrackIds);
$newPlaylist = createPlaylistWithRandomTracks($api, $recommendedTrackIds);
$templateData['infos'][] = getCreatedPlaylistInformationMessage($api, $newPlaylist);
$templateData['infos'][] = getCreatedPlaylistInformationMessage($api, $newPlaylist);
$templateData['playlist'] = createDisplayablePlaylist($newPlaylist);
$templateData['playlist'] = createDisplayablePlaylist($newPlaylist);
} elseif ($generatePlaylistFromArtists) {
 
} elseif ($generatePlaylistFromSelectedTopArtists) {
 
$selectedArtists = $_GET['selected-artist'];
$selectedArtists = $_GET['selected-artist'];
error_log('Will create new playlist with filterted recommendations from artists: '.join(', ', $selectedArtists).'".');
error_log('Will create new playlist with filterted recommendations from artists: '.join(', ', $selectedArtists).'".');
$recommendedTrackIds = [];
$recommendedTrackIds = [];
@@ -140,6 +143,45 @@ if ($generatePlaylistFromPlaylist) {
@@ -140,6 +143,45 @@ if ($generatePlaylistFromPlaylist) {
}
}
}
}
 
$newPlaylist = createPlaylistWithRandomTracks($api, $recommendedTrackIds);
 
$templateData['infos'][] = getCreatedPlaylistInformationMessage($api, $newPlaylist);
 
$templateData['playlist'] = createDisplayablePlaylist($newPlaylist);
 
 
} elseif ($generatePlaylistFromRandomTopArtists) {
 
 
$countInTopArtists = random_int(4, 6);
 
$countInLessTopArtists = random_int(4, 6);
 
$limitBetweenTopAndLessTop = $topArtistsCount;
 
$selectedArtists = getRandomArtistsFromTopArtists($api, $countInTopArtists, $countInLessTopArtists, $limitBetweenTopAndLessTop);
 
error_log('Will create new playlist with filterted recommendations from random artists: '.join(', ', $selectedArtists).'".');
 
$recommendedTrackIds = [];
 
 
$shouldFilterByArtists = isset($_GET['check-top-artist-filter-artists']);
 
error_log('Filter by artists in selection: '.($shouldFilterByArtists ? 'yes' : 'no'));
 
 
foreach ($selectedArtists as $selectedArtist) {
 
error_log('Get recommendations for artist '.$selectedArtist.'');
 
$recommendations = $api->getRecommendations([
 
'seed_artists' => $selectedArtist,
 
'limit' => 100
 
]);
 
error_log(' -> Got '.count($recommendations->tracks).' recommendatations.');
 
 
// Filter by artist if requested, remove duplicates
 
foreach ($recommendations->tracks as $recommendedTrack) {
 
if ($shouldFilterByArtists) {
 
$trackArtistInWantedArtists = false;
 
foreach ($recommendedTrack->artists as $trackArtist) {
 
if (\in_array($trackArtist->id, $selectedArtists)) {
 
$recommendedTrackIds[$recommendedTrack->id] = 1;
 
}
 
}
 
} else {
 
$recommendedTrackIds[$recommendedTrack->id] = 1;
 
}
 
}
 
}
 
$newPlaylist = createPlaylistWithRandomTracks($api, $recommendedTrackIds);
$newPlaylist = createPlaylistWithRandomTracks($api, $recommendedTrackIds);
$templateData['infos'][] = getCreatedPlaylistInformationMessage($api, $newPlaylist);
$templateData['infos'][] = getCreatedPlaylistInformationMessage($api, $newPlaylist);
$templateData['playlist'] = createDisplayablePlaylist($newPlaylist);
$templateData['playlist'] = createDisplayablePlaylist($newPlaylist);
Loading