add api to get playlist tracks and just track

This commit is contained in:
laptopcat
2025-07-08 18:45:29 +03:00
parent a28968af97
commit 92500f4a41
2 changed files with 37 additions and 0 deletions

View File

@@ -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

View File

@@ -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)