🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
deletePlaylist
Deluana27803a4d16f
diff --git a/api/playlists.go b/api/playlists.goindex 1c9a2a35d..d632f522e 100644--- a/api/playlists.go+++ b/api/playlists.go@@ -67,6 +67,16 @@ func (c *PlaylistsController) Create() {c.SendEmptyResponse()}+func (c *PlaylistsController) Delete() {+ id := c.RequiredParamString("id", "Required parameter id is missing")+ err := c.pls.Delete(id)+ if err != nil {+ beego.Error(err)+ c.SendError(responses.ErrorGeneric, "Internal Error")+ }+ c.SendEmptyResponse()+}+func (c *PlaylistsController) buildPlaylist(d *engine.PlaylistInfo) *responses.PlaylistWithSongs {pls := &responses.PlaylistWithSongs{}pls.Id = d.Iddiff --git a/conf/router.go b/conf/router.goindex b94f37b3f..5afaa14a5 100644--- a/conf/router.go+++ b/conf/router.go@@ -42,6 +42,7 @@ func mapEndpoints() {beego.NSRouter("/getPlaylists.view", &api.PlaylistsController{}, "*:GetAll"),beego.NSRouter("/getPlaylist.view", &api.PlaylistsController{}, "*:Get"),beego.NSRouter("/createPlaylist.view", &api.PlaylistsController{}, "*:Create"),+ beego.NSRouter("/deletePlaylist.view", &api.PlaylistsController{}, "*:Delete"),beego.NSRouter("/getUser.view", &api.UsersController{}, "*:GetUser"),)diff --git a/engine/playlists.go b/engine/playlists.goindex d4cecfb17..45c792e5e 100644--- a/engine/playlists.go+++ b/engine/playlists.go@@ -12,6 +12,7 @@ type Playlists interface {GetAll() (domain.Playlists, error)Get(id string) (*PlaylistInfo, error)Create(name string, ids []string) error+ Delete(id string) error}func NewPlaylists(itunes itunesbridge.ItunesControl, pr domain.PlaylistRepository, mr domain.MediaFileRepository) Playlists {@@ -47,6 +48,15 @@ func (p *playlists) Create(name string, ids []string) error {return nil}+func (p *playlists) Delete(id string) error {+ err := p.itunes.DeletePlaylist(id)+ if err != nil {+ return err+ }+ beego.Info(fmt.Sprintf("Deleted playlist with id '%s'", id))+ return nil+}+func (p *playlists) Get(id string) (*PlaylistInfo, error) {pl, err := p.plsRepo.Get(id)if err != nil {diff --git a/itunesbridge/itunes.go b/itunesbridge/itunes.goindex 3a30d63c6..4b0ebe1b3 100644--- a/itunesbridge/itunes.go+++ b/itunesbridge/itunes.go@@ -14,6 +14,7 @@ type ItunesControl interface {SetTrackRating(trackId string, rating int) errorSetAlbumRating(trackId string, rating int) errorCreatePlaylist(name string, ids []string) (string, error)+ DeletePlaylist(id string) error}func NewItunesControl() ItunesControl {@@ -39,6 +40,14 @@ func (c *itunesControl) CreatePlaylist(name string, ids []string) (string, errorreturn strings.TrimSuffix(pid, "\n"), nil}+func (c *itunesControl) DeletePlaylist(id string) error {+ script := Script{+ fmt.Sprintf(`set pls to the first item of (every playlist whose persistent ID is equal to "%s")`, id),+ `delete pls`,+ }+ return script.Run()+}+func (c *itunesControl) MarkAsPlayed(trackId string, playDate time.Time) error {script := Script{fmt.Sprintf(`set theTrack to the first item of (every track whose persistent ID is equal to "%s")`, trackId),