From 1fc5dc2bf8e2c56c8be3ba14643004b5a278da39 Mon Sep 17 00:00:00 2001 From: "Ricardo (XenGi) Band" Date: Thu, 18 Apr 2024 12:12:52 +0200 Subject: [PATCH] add attach playlist feature --- NOTES.md | 3 ++- mpd.go | 19 +++++++++++++++++++ server.go | 1 + static/index.js | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/NOTES.md b/NOTES.md index b8f027b..dde6d84 100644 --- a/NOTES.md +++ b/NOTES.md @@ -47,7 +47,7 @@ - Playlist browser - [x] Show current playlists - [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 - [x] Show dialog - [ ] `Delete` selected playlist button @@ -78,6 +78,7 @@ - [x] GET `/api/queue/:song_id/delete` - [x] GET `/api/queue/:song_id/move/:position` - [x] GET `/api/queue/replace/:playlist_name` + - [x] GET `/api/queue/attach/:playlist_name` - [ ] `/api/list_database/:path` - [x] GET `/api/playlists` - [x] GET `/api/playlists/:name` diff --git a/mpd.go b/mpd.go index 5ea21fe..9b76102 100644 --- a/mpd.go +++ b/mpd.go @@ -335,3 +335,22 @@ func replaceQueue(c echo.Context) error { 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, "") +} diff --git a/server.go b/server.go index 67baad6..2a8881c 100644 --- a/server.go +++ b/server.go @@ -92,6 +92,7 @@ func main() { g.GET("/queue/:song_id/delete", deleteTrackFromQueue) g.GET("/queue/:song_id/move/:position", moveTrackInQueue) g.GET("/queue/replace/:playlist_name", replaceQueue) + g.GET("/queue/attach/:playlist_name", attachPlaylist) g.GET("/playlists", listPlaylists) g.GET("/playlists/:name", listPlaylist) diff --git a/static/index.js b/static/index.js index 4ffcb18..17369df 100644 --- a/static/index.js +++ b/static/index.js @@ -127,7 +127,7 @@ control_replace_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) { console.error(`API returned ${r.status}: ${r.statusText}`); }