diff --git a/docs/API.md b/docs/API.md index 5ad5ccc..9d38cff 100644 --- a/docs/API.md +++ b/docs/API.md @@ -26,6 +26,12 @@ Search for users, tracks or playlists. Query parameters are: For example: `/_/api/search?q=test&type=tracks` to search for `tracks` named `test` +## GET `/_/api/track/:id` + +Get track by ID. + +For example: `/_/api/track/2014143543` to get track with ID `2014143543` + ## GET `/_/api/track/:id/related` Get related tracks by ID. Pagination is supported here. Initial request returns upto 20 tracks @@ -44,6 +50,12 @@ Get playlist by permalinks. For example: `/_/api/playlistByPermalink/lucybedroque/sets/unmusique` to get `unmusique` playlist from `lucybedroque` +## GET `/_/api/playlistByPermalink/:author/sets/:playlist/tracks` + +Get list of track IDs in playlist. + +For example: `/_/api/playlistByPermalink/lucybedroque/sets/unmusique/tracks` to get all IDs of the tracks in playlist `unmusique` from `lucybedroque` + # Other automation Doesn't require API to be enabled diff --git a/lib/api/init.go b/lib/api/init.go index a7c0828..499ed3f 100644 --- a/lib/api/init.go +++ b/lib/api/init.go @@ -79,6 +79,31 @@ func Load(a *fiber.App) { return c.JSON(p) }) + r.Get("/playlistByPermalink/:author/sets/:playlist/tracks", func(c fiber.Ctx) error { + p, err := sc.GetPlaylist("", c.Params("author")+"/sets/"+c.Params("playlist")) + if err != nil { + log.Printf("[API] error getting %s playlist tracks from %s: %s\n", c.Params("playlist"), c.Params("author"), err) + return err + } + + tracks := make([]json.Number, len(p.Tracks)) + for i, t := range p.Tracks { + tracks[i] = t.ID + } + + return c.JSON(tracks) + }) + + r.Get("/track/:id", func(c fiber.Ctx) error { + t, err := sc.GetTrackByID("", c.Params("id")) + if err != nil { + log.Printf("[API] error getting track %s: %s\n", c.Params("id"), err) + return err + } + + return c.JSON(t) + }) + r.Get("/tracks", func(c fiber.Ctx) error { ids := cfg.B2s(c.RequestCtx().QueryArgs().Peek("ids")) t, err := sc.GetTracks("", ids)