diff --git a/daemon/track_meta_cache.go b/daemon/track_meta_cache.go index e091a3b3..8d27a045 100644 --- a/daemon/track_meta_cache.go +++ b/daemon/track_meta_cache.go @@ -561,7 +561,7 @@ func (p *AppPlayer) scheduleContextMetaPrefetch(contextUri string) { if p.meta == nil || !p.app.cfg.Metadata.ContextSweep { return } - if contextUri == "" || contextUri == librespot.WebApiTrackListUri || contextUri == p.lastFullMetaContext { + if contextUri == "" || librespot.IsWebApiTrackListUri(contextUri) || contextUri == p.lastFullMetaContext { return } diff --git a/daemon/track_meta_cache_test.go b/daemon/track_meta_cache_test.go index 7e418aaf..783331a8 100644 --- a/daemon/track_meta_cache_test.go +++ b/daemon/track_meta_cache_test.go @@ -413,7 +413,7 @@ func TestContextSweepSkipsBareTrackLists(t *testing.T) { }) p.app.cfg.Metadata.ContextSweep = true - for _, uri := range []string{"", librespot.WebApiTrackListUri} { + for _, uri := range []string{"", librespot.WebApiTrackListUri, librespot.WebApiTrackListUri + ":2rTTCnsdFHFb5KvCEsY2lb"} { p.scheduleContextMetaPrefetch(uri) require.Empty(t, p.lastFullMetaContext, "no context sweep for %q", uri) } diff --git a/ids.go b/ids.go index eb081cb1..29b40ece 100644 --- a/ids.go +++ b/ids.go @@ -71,9 +71,17 @@ func InferSpotifyIdTypeFromContextUri(uri string) SpotifyIdType { // WebApiTrackListUri is the uri the Web API now gives the list of items it // plays for a request naming "uris" rather than a "context_uri"; it used to // give none. It names no context that could be resolved: the items come -// inline, as they do without it. +// inline, as they do without it. The Web API may follow it with an id of its +// own, as in "spotify:webapi:2rTTCnsdFHFb5KvCEsY2lb", which names no context +// either (see IsWebApiTrackListUri). const WebApiTrackListUri = "spotify:webapi" +// IsWebApiTrackListUri reports whether uri is WebApiTrackListUri, with or +// without an id after it. +func IsWebApiTrackListUri(uri string) bool { + return uri == WebApiTrackListUri || strings.HasPrefix(uri, WebApiTrackListUri+":") +} + // InferSpotifyIdTypeFromContext is InferSpotifyIdTypeFromContextUri for a whole // context, which also covers the one kind that has no uri of its own: a bare // list of items. The Web API plays one for a request naming "uris" rather than @@ -82,7 +90,7 @@ const WebApiTrackListUri = "spotify:webapi" // whose uri names a track or an episode; on a transfer the items carry only // gids, and are taken to be tracks. func InferSpotifyIdTypeFromContext(ctx *connectpb.Context) SpotifyIdType { - if uri := ctx.GetUri(); uri != "" && uri != WebApiTrackListUri { + if uri := ctx.GetUri(); uri != "" && !IsWebApiTrackListUri(uri) { return InferSpotifyIdTypeFromContextUri(uri) } diff --git a/ids_test.go b/ids_test.go index bce0282d..46f7225c 100644 --- a/ids_test.go +++ b/ids_test.go @@ -104,6 +104,7 @@ func TestInferSpotifyIdTypeFromContext(t *testing.T) { {"web api gids", webApi(&connectpb.ContextTrack{Gid: gid}), librespot.SpotifyIdTypeTrack}, {"no uri, no items", &connectpb.Context{Pages: []*connectpb.ContextPage{{}}}, librespot.SpotifyIdTypeUnknown}, {"web api, no items", &connectpb.Context{Uri: librespot.WebApiTrackListUri}, librespot.SpotifyIdTypeUnknown}, + {"web api with an id", &connectpb.Context{Uri: librespot.WebApiTrackListUri + ":2rTTCnsdFHFb5KvCEsY2lb", Pages: []*connectpb.ContextPage{{Tracks: []*connectpb.ContextTrack{{Uri: "spotify:episode:512ojhOuo1ktJprKbVcKyQ"}}}}}, librespot.SpotifyIdTypeEpisode}, {"nothing", &connectpb.Context{}, librespot.SpotifyIdTypeUnknown}, } diff --git a/spclient/context_resolver_test.go b/spclient/context_resolver_test.go index c9fa9caf..4bdba748 100644 --- a/spclient/context_resolver_test.go +++ b/spclient/context_resolver_test.go @@ -31,16 +31,19 @@ func TestNewContextResolverBareUris(t *testing.T) { // The Web API now names such a list with a uri of its own, which it cannot // resolve. The tracks are still inline, so there is nothing to resolve. +// It may follow that uri with an id, which names no context either. func TestNewContextResolverWebApiUris(t *testing.T) { - spotCtx := &connectpb.Context{Uri: librespot.WebApiTrackListUri, Pages: []*connectpb.ContextPage{{Tracks: []*connectpb.ContextTrack{ - {Uri: "spotify:track:1BdI8NEvZx61tnkbuAxC5x"}, - {Uri: "spotify:track:4u615SPuJfGtPaEUSKwuK4"}, - }}}} + for _, uri := range []string{librespot.WebApiTrackListUri, librespot.WebApiTrackListUri + ":2rTTCnsdFHFb5KvCEsY2lb"} { + spotCtx := &connectpb.Context{Uri: uri, Pages: []*connectpb.ContextPage{{Tracks: []*connectpb.ContextTrack{ + {Uri: "spotify:track:1BdI8NEvZx61tnkbuAxC5x"}, + {Uri: "spotify:track:4u615SPuJfGtPaEUSKwuK4"}, + }}}} - r, err := NewContextResolver(context.Background(), &librespot.NullLogger{}, nil, spotCtx) - require.NoError(t, err) - require.Equal(t, librespot.SpotifyIdTypeTrack, r.Type()) - require.Equal(t, librespot.WebApiTrackListUri, r.Uri()) + r, err := NewContextResolver(context.Background(), &librespot.NullLogger{}, nil, spotCtx) + require.NoError(t, err, uri) + require.Equal(t, librespot.SpotifyIdTypeTrack, r.Type(), uri) + require.Equal(t, uri, r.Uri()) + } } func TestHasResolvablePages(t *testing.T) {