Skip to content

Commit

Permalink
[extapi] added start/stop to icecast playlist via mpd
Browse files Browse the repository at this point in the history
  • Loading branch information
DictumMortuum committed Jan 2, 2025
1 parent b86bb23 commit a428cce
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/servus-extapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func Version(c *gin.Context) {
rs := map[string]any{
"version": "v0.0.42",
"version": "v0.0.43",
}
c.AbortWithStatusJSON(200, rs)
}
Expand Down Expand Up @@ -62,7 +62,8 @@ func main() {
g.GET("/eurovisionvotes/all", adapter.A(model.GetEurovisionVotes), middleware.ResultRa)
g.GET("/eurovisionparticipations/user/:id", middleware.Id, adapter.A(model.GetEurovisionParticipationsByUserId), middleware.ResultRa)
g.GET("/players/email/:id", middleware.Id, adapter.A(model.GetPlayerByEmail), middleware.ResultRa)
g.GET("/playlists/play/:id", middleware.Id, adapter.A(model.M3u), middleware.ResultRa)
g.GET("/playlists/play/:id", middleware.Id, adapter.A(model.PlaylistPlay), middleware.ResultRa)
g.GET("/playlists/stop", adapter.A(model.PlaylistStop), middleware.ResultRa)

// cachedPrices := model.CachedPrice{}
// g.GET("/cachedprices/search/:id", OpenDB, Id, LoadOne(cachedPrices.Get), adapter.G(bgg.SearchCachedPriceOnBgg), CloseDB)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/DictumMortuum/servus v0.7.23
github.com/MicahParks/keyfunc/v2 v2.1.0
github.com/boggydigital/yt_urls v0.1.47
github.com/fhs/gompd v1.0.1
github.com/gin-contrib/cache v1.3.0
github.com/gin-contrib/cors v1.7.2
github.com/gin-gonic/gin v1.10.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fhs/gompd v1.0.1 h1:kBcAhjnAPJQAylZXR0TeH+d2vpjawXlTtKYguqNlF4A=
github.com/fhs/gompd v1.0.1/go.mod h1:b219/mNa9PvRqvkUip51b23hGL3iX4d4q3gNXdtrD04=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4=
Expand Down
41 changes: 41 additions & 0 deletions pkg/model/playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/boggydigital/yt_urls"
"github.com/fhs/gompd/mpd"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -105,6 +106,46 @@ func (obj Playlist) Delete(db *gorm.DB, id int64) (any, error) {
return data, nil
}

func PlaylistPlay(req *Map, res *Map) error {
playlist_id, err := req.GetString("id")
if err != nil {
return err
}

conn, err := mpd.Dial("tcp", "localhost:6600")
if err != nil {
return err
}
defer conn.Close()

err = conn.Add("playlists/" + playlist_id)
if err != nil {
return err
}

err = conn.Play(-1)
if err != nil {
return err
}

return nil
}

func PlaylistStop(req *Map, res *Map) error {
conn, err := mpd.Dial("tcp", "localhost:6600")
if err != nil {
return err
}
defer conn.Close()

err = conn.Clear()
if err != nil {
return err
}

return nil
}

func M3u(req *Map, res *Map) error {
playlist_id, err := req.GetString("id")
if err != nil {
Expand Down

0 comments on commit a428cce

Please sign in to comment.