Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion daemon/track_meta_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion daemon/track_meta_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 10 additions & 2 deletions ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

Expand Down
1 change: 1 addition & 0 deletions ids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}

Expand Down
19 changes: 11 additions & 8 deletions spclient/context_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading