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
c7627cdd
Commit
c7627cdd
authored
2 years ago
by
Benoît Harrault
Browse files
Options
Downloads
Plain Diff
Merge branch '36-add-a-show-playlist-route' into 'master'
Resolve "Add a "show playlist" route" Closes
#36
See merge request
!32
parents
d7f169ce
26c3c91a
No related branches found
No related tags found
1 merge request
!32
Resolve "Add a "show playlist" route"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
public/.htaccess
+1
-0
1 addition, 0 deletions
public/.htaccess
public/index.php
+11
-3
11 additions, 3 deletions
public/index.php
spotify/lib.php
+13
-1
13 additions, 1 deletion
spotify/lib.php
with
25 additions
and
4 deletions
public/.htaccess
+
1
−
0
View file @
c7627cdd
RewriteEngine
On
RewriteRule
^playlist-generator index.php [L,QSA]
RewriteRule
^view-playlist-([^./]+)$ index.php?show-playlist=1&id=$1 [L,QSA]
This diff is collapsed.
Click to expand it.
public/index.php
+
11
−
3
View file @
c7627cdd
...
...
@@ -74,6 +74,8 @@ $templateData = [
$generatePlaylistFromPlaylist
=
isset
(
$_GET
[
'generate-playlist-from-playlist'
]);
$generatePlaylistFromSelectedTopArtists
=
isset
(
$_GET
[
'generate-playlist-top-artists'
]);
$generatePlaylistFromRandomTopArtists
=
isset
(
$_GET
[
'generate-playlist-random-top-artists'
]);
$showPlaylistContent
=
isset
(
$_GET
[
'show-playlist'
]);
if
(
$generatePlaylistFromPlaylist
)
{
$selectedPlaylists
=
$_GET
[
'selected-playlist'
];
...
...
@@ -130,7 +132,6 @@ if ($generatePlaylistFromPlaylist) {
$newPlaylist
=
createPlaylistWithRandomTracks
(
$api
,
$recommendedTrackIds
,
$generateLongPlaylist
?
100
:
50
);
$templateData
[
'infos'
][]
=
getCreatedPlaylistInformationMessage
(
$api
,
$newPlaylist
);
$templateData
[
'playlist'
]
=
createDisplayablePlaylist
(
$newPlaylist
);
}
elseif
(
$generatePlaylistFromSelectedTopArtists
)
{
...
...
@@ -169,7 +170,6 @@ if ($generatePlaylistFromPlaylist) {
$newPlaylist
=
createPlaylistWithRandomTracks
(
$api
,
$recommendedTrackIds
,
$generateLongPlaylist
?
100
:
50
);
$templateData
[
'infos'
][]
=
getCreatedPlaylistInformationMessage
(
$api
,
$newPlaylist
);
$templateData
[
'playlist'
]
=
createDisplayablePlaylist
(
$newPlaylist
);
}
elseif
(
$generatePlaylistFromRandomTopArtists
)
{
...
...
@@ -211,7 +211,15 @@ if ($generatePlaylistFromPlaylist) {
$newPlaylist
=
createPlaylistWithRandomTracks
(
$api
,
$recommendedTrackIds
,
$generateLongPlaylist
?
100
:
50
);
$templateData
[
'infos'
][]
=
getCreatedPlaylistInformationMessage
(
$api
,
$newPlaylist
);
$templateData
[
'playlist'
]
=
createDisplayablePlaylist
(
$newPlaylist
);
}
elseif
(
$showPlaylistContent
)
{
printLog
(
'Get content of playlist: '
.
(
$generateLongPlaylist
?
'yes'
:
'no'
));
$playlistId
=
$_GET
[
'id'
];
$playlist
=
$api
->
getPlaylist
(
$playlistId
);
$templateData
[
'infos'
][]
=
getPlaylistInformationMessage
(
$api
,
$playlist
);
$templateData
[
'playlist'
]
=
createDisplayablePlaylist
(
$playlist
);
}
else
{
$templateData
[
'topArtists'
]
=
$api
->
getMyTop
(
'artists'
,
[
'limit'
=>
$topArtistsCount
,
'time_range'
=>
'short_term'
])
->
items
;
$templateData
[
'playlists'
]
=
$api
->
getUserPlaylists
(
$user
[
'id'
],
[
'limit'
=>
$playlistsCount
])
->
items
;
...
...
This diff is collapsed.
Click to expand it.
spotify/lib.php
+
13
−
1
View file @
c7627cdd
...
...
@@ -7,6 +7,10 @@ function printLog($message = '')
}
}
function
generateShowPlaylistUrl
(
$playlistId
)
{
return
'/view-playlist-'
.
$playlistId
;
}
function
generatePlaylistName
()
{
$now
=
new
DateTime
();
...
...
@@ -82,12 +86,20 @@ function createPlaylistWithRandomTracks($api, $trackIds, $count = 50)
function
getCreatedPlaylistInformationMessage
(
$api
,
$playlist
)
{
$link
=
'<a href="'
.
$playlist
->
external_urls
->
spotify
.
'">'
.
$playlist
->
name
.
'</a>'
;
$link
=
'<a href="'
.
generateShowPlaylistUrl
(
$playlist
->
id
)
.
'">'
.
$playlist
->
name
.
'</a>'
;
$message
=
'Ok created new playlist with '
.
count
(
$playlist
->
tracks
->
items
)
.
' tracks: '
.
$link
;
return
$message
;
}
function
getPlaylistInformationMessage
(
$api
,
$playlist
)
{
$link
=
'<a href="'
.
$playlist
->
external_urls
->
spotify
.
'">'
.
$playlist
->
name
.
'</a>'
;
$message
=
'Playlist with '
.
count
(
$playlist
->
tracks
->
items
)
.
' tracks: '
.
$link
;
return
$message
;
}
function
createDisplayablePlaylist
(
$playlist
)
{
$output
=
[
...
...
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