mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
paginate artist album fetching for deezer and qobuz
This commit is contained in:
@@ -203,7 +203,7 @@ func (c *Client) GetMetadata(ctx context.Context, item, mediaType string) (map[s
|
||||
resp["tracks"] = map[string]any{"items": items}
|
||||
return resp, nil
|
||||
case "artist":
|
||||
resp, err := c.apiGet(ctx, "/artist/"+item+"/albums", nil)
|
||||
resp, err := c.getArtistAlbums(ctx, item)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -224,6 +224,35 @@ func (c *Client) GetMetadata(ctx context.Context, item, mediaType string) (map[s
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) getArtistAlbums(ctx context.Context, artistID string) (map[string]any, error) {
|
||||
const pageSize = 100
|
||||
index := 0
|
||||
total := -1
|
||||
all := make([]any, 0)
|
||||
for {
|
||||
params := url.Values{}
|
||||
params.Set("limit", strconv.Itoa(pageSize))
|
||||
params.Set("index", strconv.Itoa(index))
|
||||
resp, err := c.apiGet(ctx, "/artist/"+strings.TrimSpace(artistID)+"/albums", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data, _ := resp["data"].([]any)
|
||||
all = append(all, data...)
|
||||
if total < 0 {
|
||||
total = intFromAny(resp["total"])
|
||||
}
|
||||
if len(data) < pageSize {
|
||||
break
|
||||
}
|
||||
index += len(data)
|
||||
if total > 0 && index >= total {
|
||||
break
|
||||
}
|
||||
}
|
||||
return map[string]any{"data": all, "total": total}, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetDownloadable(ctx context.Context, item string, _ int) (*provider.Downloadable, error) {
|
||||
if strings.TrimSpace(c.license) == "" {
|
||||
if strings.TrimSpace(c.arl) != "" {
|
||||
|
||||
Reference in New Issue
Block a user