small improvements; aur package
This commit is contained in:
parent
79a6049a91
commit
03677e24be
15 changed files with 386 additions and 287 deletions
57
mpd.go
57
mpd.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fhs/gompd/v2/mpd"
|
||||
"github.com/labstack/echo/v4"
|
||||
"net/http"
|
||||
|
@ -23,7 +24,7 @@ func updateDb(c echo.Context) error {
|
|||
c.Logger().Error(err)
|
||||
}
|
||||
|
||||
return c.String(http.StatusOK, strconv.Itoa(jobId))
|
||||
return c.String(http.StatusOK, fmt.Sprintf("Database update started with job id %d", jobId))
|
||||
}
|
||||
|
||||
func previousTrack(c echo.Context) error {
|
||||
|
@ -39,7 +40,7 @@ func previousTrack(c echo.Context) error {
|
|||
c.Logger().Error(err)
|
||||
}
|
||||
|
||||
return c.String(http.StatusOK, "")
|
||||
return c.String(http.StatusOK, "Playing previous track in queue")
|
||||
}
|
||||
|
||||
func nextTrack(c echo.Context) error {
|
||||
|
@ -55,7 +56,7 @@ func nextTrack(c echo.Context) error {
|
|||
c.Logger().Error(err)
|
||||
}
|
||||
|
||||
return c.String(http.StatusOK, "")
|
||||
return c.String(http.StatusOK, "PLaying next track in queue")
|
||||
}
|
||||
|
||||
func stopPlayback(c echo.Context) error {
|
||||
|
@ -71,7 +72,7 @@ func stopPlayback(c echo.Context) error {
|
|||
c.Logger().Error(err)
|
||||
}
|
||||
|
||||
return c.String(http.StatusOK, "")
|
||||
return c.String(http.StatusOK, "Playback stopped")
|
||||
}
|
||||
|
||||
func resumePlayback(c echo.Context) error {
|
||||
|
@ -98,7 +99,7 @@ func resumePlayback(c echo.Context) error {
|
|||
}
|
||||
}
|
||||
|
||||
return c.String(http.StatusOK, "")
|
||||
return c.String(http.StatusOK, "Playback resumed")
|
||||
}
|
||||
|
||||
func pausePlayback(c echo.Context) error {
|
||||
|
@ -114,7 +115,7 @@ func pausePlayback(c echo.Context) error {
|
|||
c.Logger().Error(err)
|
||||
}
|
||||
|
||||
return c.String(http.StatusOK, "")
|
||||
return c.String(http.StatusOK, "Playback paused")
|
||||
}
|
||||
|
||||
func seek(c echo.Context) error {
|
||||
|
@ -134,12 +135,13 @@ func seek(c echo.Context) error {
|
|||
return c.String(http.StatusBadRequest, "seconds must be positive integer")
|
||||
}
|
||||
|
||||
// TODO: Duration type seems to be used incorrectly
|
||||
err = conn.SeekCur(time.Duration(seconds)*time.Second, false)
|
||||
if err != nil {
|
||||
c.Logger().Error(err)
|
||||
}
|
||||
|
||||
return c.String(http.StatusOK, "")
|
||||
return c.String(http.StatusOK, fmt.Sprintf("Seeked current track to %d seconds", seconds))
|
||||
}
|
||||
|
||||
func toggleRepeat(c echo.Context) error {
|
||||
|
@ -154,16 +156,19 @@ func toggleRepeat(c echo.Context) error {
|
|||
if err != nil {
|
||||
c.Logger().Error(err)
|
||||
}
|
||||
var msg string
|
||||
if status["repeat"] == "1" {
|
||||
err = conn.Repeat(false)
|
||||
msg = "Toggled Repeat mode to off"
|
||||
} else {
|
||||
err = conn.Repeat(true)
|
||||
msg = "Toggled Repeat mode to on"
|
||||
}
|
||||
if err != nil {
|
||||
c.Logger().Error(err)
|
||||
}
|
||||
|
||||
return c.String(http.StatusOK, "")
|
||||
return c.String(http.StatusOK, msg)
|
||||
}
|
||||
|
||||
func toggleRandom(c echo.Context) error {
|
||||
|
@ -178,16 +183,19 @@ func toggleRandom(c echo.Context) error {
|
|||
if err != nil {
|
||||
c.Logger().Error(err)
|
||||
}
|
||||
var msg string
|
||||
if status["random"] == "1" {
|
||||
err = conn.Random(false)
|
||||
msg = "Toggled Random mode to off"
|
||||
} else {
|
||||
err = conn.Random(true)
|
||||
msg = "Toggled Random mode to on"
|
||||
}
|
||||
if err != nil {
|
||||
c.Logger().Error(err)
|
||||
}
|
||||
|
||||
return c.String(http.StatusOK, "")
|
||||
return c.String(http.StatusOK, msg)
|
||||
}
|
||||
|
||||
func setVolume(c echo.Context) error {
|
||||
|
@ -212,7 +220,7 @@ func setVolume(c echo.Context) error {
|
|||
c.Logger().Error(err)
|
||||
}
|
||||
|
||||
return c.String(http.StatusOK, "")
|
||||
return c.String(http.StatusOK, fmt.Sprintf("Set volume to %d", level))
|
||||
}
|
||||
|
||||
// Queue
|
||||
|
@ -236,5 +244,32 @@ func deleteTrackFromQueue(c echo.Context) error {
|
|||
return c.String(http.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
return c.String(http.StatusOK, "")
|
||||
return c.String(http.StatusOK, fmt.Sprintf("Removed song %d from queue", songId))
|
||||
}
|
||||
|
||||
func moveTrackInQueue(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()
|
||||
|
||||
songId, err := strconv.Atoi(c.Param("song_id"))
|
||||
if err != nil {
|
||||
c.Logger().Error(err)
|
||||
}
|
||||
|
||||
position, err := strconv.Atoi(c.Param("position"))
|
||||
if err != nil {
|
||||
c.Logger().Error(err)
|
||||
}
|
||||
|
||||
err = conn.MoveID(songId, position)
|
||||
if err != nil {
|
||||
c.Logger().Error(err)
|
||||
return c.String(http.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
return c.String(http.StatusOK, fmt.Sprintf("Moved song %d to position %d", songId, position))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue