Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
spotify
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web
spotify
Commits
f08093ec
Commit
f08093ec
authored
3 years ago
by
Benoît Harrault
Browse files
Options
Downloads
Patches
Plain Diff
Improve create playlist from existing playlist tracks
parent
c397460b
No related branches found
No related tags found
1 merge request
!7
Resolve "Improve create playlist from existing playlist"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
public/index.php
+26
-24
26 additions, 24 deletions
public/index.php
template.php
+22
-8
22 additions, 8 deletions
template.php
with
48 additions
and
32 deletions
public/index.php
+
26
−
24
View file @
f08093ec
...
@@ -49,35 +49,37 @@ $templateData = [
...
@@ -49,35 +49,37 @@ $templateData = [
'errors'
=>
[],
'errors'
=>
[],
];
];
$selectedPlaylistId
=
''
;
$generatePlaylistFromPlaylist
=
isset
(
$_GET
[
'generate-playlist-from-playlist'
]);
if
(
isset
(
$_GET
[
'playlist'
]))
{
$selectedPlaylistId
=
$_GET
[
'playlist'
];
}
$generatePlaylistFromArtists
=
isset
(
$_GET
[
'generate-playlist-top-artists'
]);
$generatePlaylistFromArtists
=
isset
(
$_GET
[
'generate-playlist-top-artists'
]);
if
(
$
selec
te
d
Playlist
Id
)
{
if
(
$
genera
tePlaylist
FromPlaylist
)
{
$
playlist
=
$api
->
getPlaylist
(
$
selected
P
laylist
Id
)
;
$
selectedPlaylists
=
$_GET
[
'
selected
-p
laylist
'
]
;
error_log
(
'Will create new playlist
from tracks in
playlist '
.
$selectedPlaylist
Id
.
' "'
.
$playlist
->
name
.
'".'
);
error_log
(
'Will create new playlist
with recommendations from
playlist
s:
'
.
join
(
', '
,
$selectedPlaylist
s
)
.
'".'
);
$recommendedTrackIds
=
[];
$recommendedTrackIds
=
[];
$playlistTracks
=
$playlist
->
tracks
->
items
;
error_log
(
'Found '
.
count
(
$playlistTracks
)
.
' tracks.'
);
foreach
(
$playlistTracks
as
$track
)
{
$artists
=
[];
foreach
(
$track
->
track
->
artists
as
$artist
)
{
$artists
[]
=
$artist
->
name
;
}
error_log
(
'Track '
.
$track
->
track
->
id
.
' "'
.
$track
->
track
->
name
.
'" ('
.
join
(
', '
,
$artists
)
.
')'
);
$recommendations
=
$api
->
getRecommendations
([
foreach
(
$selectedPlaylists
as
$selectedPlaylistId
)
{
'seed_tracks'
=>
[
$track
->
track
->
id
],
$playlist
=
$api
->
getPlaylist
(
$selectedPlaylistId
);
'limit'
=>
20
error_log
(
'Will get recommendations from tracks in playlist '
.
$selectedPlaylistId
.
' "'
.
$playlist
->
name
.
'".'
);
]);
$playlistTracks
=
$playlist
->
tracks
->
items
;
error_log
(
' -> Got '
.
count
(
$recommendations
->
tracks
)
.
' recommendatations.'
);
error_log
(
'Found '
.
count
(
$playlistTracks
)
.
' tracks.'
);
foreach
(
$recommendations
->
tracks
as
$recommendedTrack
)
{
foreach
(
$playlistTracks
as
$track
)
{
$recommendedTrackIds
[
$recommendedTrack
->
id
]
=
1
;
$artists
=
[];
foreach
(
$track
->
track
->
artists
as
$artist
)
{
$artists
[]
=
$artist
->
name
;
}
error_log
(
'Track '
.
$track
->
track
->
id
.
' "'
.
$track
->
track
->
name
.
'" ('
.
join
(
', '
,
$artists
)
.
')'
);
$recommendations
=
$api
->
getRecommendations
([
'seed_tracks'
=>
[
$track
->
track
->
id
],
'limit'
=>
20
]);
error_log
(
' -> Got '
.
count
(
$recommendations
->
tracks
)
.
' recommendatations.'
);
foreach
(
$recommendations
->
tracks
as
$recommendedTrack
)
{
$recommendedTrackIds
[
$recommendedTrack
->
id
]
=
1
;
}
}
}
}
}
$recommendedTrackIds
=
array_keys
(
$recommendedTrackIds
);
$recommendedTrackIds
=
array_keys
(
$recommendedTrackIds
);
error_log
(
'=> Got '
.
count
(
$recommendedTrackIds
)
.
' unique recommendatations for this playlist.'
);
error_log
(
'=> Got '
.
count
(
$recommendedTrackIds
)
.
' unique recommendatations for this playlist.'
);
shuffle
(
$recommendedTrackIds
);
shuffle
(
$recommendedTrackIds
);
...
@@ -136,7 +138,7 @@ if ($selectedPlaylistId) {
...
@@ -136,7 +138,7 @@ if ($selectedPlaylistId) {
$templateData
[
'infos'
][]
=
'Ok created new playlist with '
.
count
(
$pickedTrackIds
)
.
' tracks: '
.
$playlistLink
;
$templateData
[
'infos'
][]
=
'Ok created new playlist with '
.
count
(
$pickedTrackIds
)
.
' tracks: '
.
$playlistLink
;
}
else
{
}
else
{
$templateData
[
'topArtists'
]
=
$api
->
getMyTop
(
'artists'
,
[
'limit'
=>
16
,
'time_range'
=>
'short_term'
])
->
items
;
$templateData
[
'topArtists'
]
=
$api
->
getMyTop
(
'artists'
,
[
'limit'
=>
16
,
'time_range'
=>
'short_term'
])
->
items
;
$templateData
[
'playlists'
]
=
$api
->
getUserPlaylists
(
$user
->
id
)
->
items
;
$templateData
[
'playlists'
]
=
$api
->
getUserPlaylists
(
$user
->
id
,
[
'limit'
=>
30
]
)
->
items
;
}
}
require
'../template.php'
;
require
'../template.php'
;
This diff is collapsed.
Click to expand it.
template.php
+
22
−
8
View file @
f08093ec
...
@@ -72,14 +72,28 @@
...
@@ -72,14 +72,28 @@
<?php
}
?>
<?php
}
?>
<?php
if
(
count
(
$templateData
[
'playlists'
]))
{
?>
<?php
if
(
count
(
$templateData
[
'playlists'
]))
{
?>
<h3>
Please pick a playlist to get recommendations from:
</h3>
<form
class=
"clearfix"
>
<div
class=
"list-group"
>
<legend>
Generate playlist from tracks in existing playlist:
</legend>
<?php
foreach
(
$templateData
[
'playlists'
]
as
$playlist
)
{
?>
<ul
class=
"list-unstyled row row-cols-2"
>
<a
href=
"index.php?playlist=
<?php
echo
$playlist
->
id
;
?>
"
class=
"list-group-item list-group-item-action"
>
<?php
foreach
(
$templateData
[
'playlists'
]
as
$playlist
)
{
?>
<?php
echo
$playlist
->
name
;
?>
<li
class=
"col"
>
</a>
<div
class=
"custom-control custom-checkbox"
>
<?php
}
?>
<input
</div>
type=
"checkbox"
class=
"custom-control-input"
id=
"check-playlist-
<?php
echo
$playlist
->
id
;
?>
"
name=
"selected-playlist[]"
value=
"
<?php
echo
$playlist
->
id
;
?>
"
>
<label
class=
"custom-control-label"
for=
"check-playlist-
<?php
echo
$playlist
->
id
;
?>
"
>
<?php
echo
$playlist
->
name
;
?>
</label>
</div>
</li>
<?php
}
?>
</ul>
<button
name=
"generate-playlist-from-playlist"
type=
"submit"
class=
"btn btn-secondary float-end"
>
🎶 Generate!
</button>
</form>
<?php
}
?>
<?php
}
?>
</div>
</div>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment