add replace playlist feature

This commit is contained in:
XenGi 2024-04-18 11:46:09 +02:00
parent 44dd0ddd9c
commit aeaef11341
Signed by: xengi
SSH key fingerprint: SHA256:FGp51kRvGOcWnTHiOI39ImwVO4A3fpvR30nPX3LpV7g
4 changed files with 37 additions and 10 deletions

View file

@ -45,8 +45,8 @@
- [ ] Select tracks in results - [ ] Select tracks in results
- [ ] `Add` selected tracks to queue button - [ ] `Add` selected tracks to queue button
- Playlist browser - Playlist browser
- [ ] Show current playlists - [x] Show current playlists
- [ ] `Replace` current queue with playlist button - [x] `Replace` current queue with playlist button
- [ ] `Attach` playlist to current queue button - [ ] `Attach` playlist to current queue button
- [ ] `Save` current queue as playlist button - [ ] `Save` current queue as playlist button
- [x] Show dialog - [x] Show dialog
@ -77,8 +77,10 @@
- [ ] POST `/api/queue` `{"song_id": 123}` - [ ] POST `/api/queue` `{"song_id": 123}`
- [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`
- [ ] `/api/list_database/:path` - [ ] `/api/list_database/:path`
- [ ] `/api/list_playlists` - [x] GET `/api/playlists`
- [x] GET `/api/playlists/:name`
- [ ] `/api/save_playlist` - [ ] `/api/save_playlist`
- [ ] `/api/delete_playlist` - [ ] `/api/delete_playlist`

24
mpd.go
View file

@ -311,3 +311,27 @@ func listPlaylist(c echo.Context) error {
return c.JSON(http.StatusOK, playlist) return c.JSON(http.StatusOK, playlist)
} }
func replaceQueue(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.Clear()
if err != nil {
c.Logger().Error(err)
return c.String(http.StatusInternalServerError, err.Error())
}
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

@ -91,6 +91,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("/playlists", listPlaylists) g.GET("/playlists", listPlaylists)
g.GET("/playlists/:name", listPlaylist) g.GET("/playlists/:name", listPlaylist)

View file

@ -118,15 +118,15 @@ dialog_save_playlist_close.addEventListener("click", () => {
// Add API calls to controls // Add API calls to controls
control_replace_playlist.addEventListener("click", e => { control_replace_playlist.addEventListener("click", () => {
fetch(`${API_URL}/`).then(async r => { fetch(`${API_URL}/queue/replace/${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}`);
} }
}); });
}); });
control_attach_playlist.addEventListener("click", e => { control_attach_playlist.addEventListener("click", () => {
fetch(`${API_URL}/`).then(async r => { fetch(`${API_URL}/`).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}`);
@ -153,7 +153,7 @@ control_delete_playlist.addEventListener("click", () => {
}); });
}); });
tab_browser.addEventListener("click", e => { tab_browser.addEventListener("click", () => {
if (!tab_browser.classList.contains("active")) { if (!tab_browser.classList.contains("active")) {
tab_browser.classList.add("active"); tab_browser.classList.add("active");
tab_search.classList.remove("active") tab_search.classList.remove("active")
@ -164,7 +164,7 @@ tab_browser.addEventListener("click", e => {
} }
}); });
tab_search.addEventListener("click", e => { tab_search.addEventListener("click", () => {
if (!tab_search.classList.contains("active")) { if (!tab_search.classList.contains("active")) {
tab_browser.classList.remove("active"); tab_browser.classList.remove("active");
tab_search.classList.add("active") tab_search.classList.add("active")
@ -175,7 +175,7 @@ tab_search.addEventListener("click", e => {
} }
}); });
tab_playlists.addEventListener("click", e => { tab_playlists.addEventListener("click", () => {
fetch(`${API_URL}/playlists`).then(async r => { fetch(`${API_URL}/playlists`).then(async r => {
if (r.status === 200) { if (r.status === 200) {
const playlists = await r.json(); const playlists = await r.json();
@ -224,7 +224,7 @@ tab_playlists.addEventListener("click", e => {
// Add API calls to controls // Add API calls to controls
control_update_db.addEventListener("click", e => { control_update_db.addEventListener("click", () => {
console.log("Issuing database update") console.log("Issuing database update")
fetch(`${API_URL}/update_db`).then(async r => { fetch(`${API_URL}/update_db`).then(async r => {
if (r.status === 200) { if (r.status === 200) {