add attach playlist feature

This commit is contained in:
XenGi 2024-04-18 12:12:52 +02:00
parent aeaef11341
commit 1fc5dc2bf8
Signed by: xengi
SSH key fingerprint: SHA256:FGp51kRvGOcWnTHiOI39ImwVO4A3fpvR30nPX3LpV7g
4 changed files with 23 additions and 2 deletions

View file

@ -47,7 +47,7 @@
- Playlist browser - Playlist browser
- [x] Show current playlists - [x] Show current playlists
- [x] `Replace` current queue with playlist button - [x] `Replace` current queue with playlist button
- [ ] `Attach` playlist to current queue button - [x] `Attach` playlist to current queue button
- [ ] `Save` current queue as playlist button - [ ] `Save` current queue as playlist button
- [x] Show dialog - [x] Show dialog
- [ ] `Delete` selected playlist button - [ ] `Delete` selected playlist button
@ -78,6 +78,7 @@
- [x] GET `/api/queue/:song_id/delete` - [x] GET `/api/queue/:song_id/delete`
- [x] GET `/api/queue/:song_id/move/:position` - [x] GET `/api/queue/:song_id/move/:position`
- [x] GET `/api/queue/replace/:playlist_name` - [x] GET `/api/queue/replace/:playlist_name`
- [x] GET `/api/queue/attach/:playlist_name`
- [ ] `/api/list_database/:path` - [ ] `/api/list_database/:path`
- [x] GET `/api/playlists` - [x] GET `/api/playlists`
- [x] GET `/api/playlists/:name` - [x] GET `/api/playlists/:name`

19
mpd.go
View file

@ -335,3 +335,22 @@ func replaceQueue(c echo.Context) error {
return c.JSON(http.StatusOK, "") return c.JSON(http.StatusOK, "")
} }
func attachPlaylist(c echo.Context) error {
// Connect to MPD server
conn, err := mpd.Dial("tcp", "localhost:6600")
if err != nil {
c.Logger().Error(err)
}
defer conn.Close()
name := c.Param("playlist_name")
err = conn.PlaylistLoad(name, -1, -1)
if err != nil {
c.Logger().Error(err)
return c.String(http.StatusBadRequest, err.Error())
}
return c.JSON(http.StatusOK, "")
}

View file

@ -92,6 +92,7 @@ func main() {
g.GET("/queue/:song_id/delete", deleteTrackFromQueue) g.GET("/queue/:song_id/delete", deleteTrackFromQueue)
g.GET("/queue/:song_id/move/:position", moveTrackInQueue) g.GET("/queue/:song_id/move/:position", moveTrackInQueue)
g.GET("/queue/replace/:playlist_name", replaceQueue) g.GET("/queue/replace/:playlist_name", replaceQueue)
g.GET("/queue/attach/:playlist_name", attachPlaylist)
g.GET("/playlists", listPlaylists) g.GET("/playlists", listPlaylists)
g.GET("/playlists/:name", listPlaylist) g.GET("/playlists/:name", listPlaylist)

View file

@ -127,7 +127,7 @@ control_replace_playlist.addEventListener("click", () => {
}); });
control_attach_playlist.addEventListener("click", () => { control_attach_playlist.addEventListener("click", () => {
fetch(`${API_URL}/`).then(async r => { fetch(`${API_URL}/queue/attach/${control_playlist_list.value}`).then(async r => {
if (r.status !== 200) { if (r.status !== 200) {
console.error(`API returned ${r.status}: ${r.statusText}`); console.error(`API returned ${r.status}: ${r.statusText}`);
} }