11import { capitalizeReleaseType } from '@/harmonizer/release_types.ts' ;
2- import { ApiAccessToken , type CacheEntry , MetadataApiProvider , ReleaseApiLookup } from '@/providers/base.ts' ;
2+ import {
3+ type ApiAccessToken ,
4+ type ApiQueryOptions ,
5+ type CacheEntry ,
6+ MetadataApiProvider ,
7+ ReleaseApiLookup ,
8+ } from '@/providers/base.ts' ;
39import { DurationPrecision , FeatureQuality , FeatureQualityMap } from '@/providers/features.ts' ;
410import { getFromEnv } from '@/utils/config.ts' ;
511import { formatCopyrightSymbols } from '@/utils/copyright.ts' ;
@@ -76,12 +82,12 @@ export default class SpotifyProvider extends MetadataApiProvider {
7682 return [ 'free streaming' ] ;
7783 }
7884
79- async query < Data > ( apiUrl : URL , maxTimestamp ?: number ) : Promise < CacheEntry < Data > > {
85+ async query < Data > ( apiUrl : URL , options : ApiQueryOptions ) : Promise < CacheEntry < Data > > {
8086 try {
8187 await this . requestDelay ;
8288 const accessToken = await this . cachedAccessToken ( this . requestAccessToken ) ;
8389 const cacheEntry = await this . fetchJSON < Data > ( apiUrl , {
84- policy : { maxTimestamp } ,
90+ policy : { maxTimestamp : options . snapshotMaxTimestamp } ,
8591 requestInit : {
8692 headers : {
8793 'Authorization' : `Bearer ${ accessToken } ` ,
@@ -100,7 +106,7 @@ export default class SpotifyProvider extends MetadataApiProvider {
100106 this . handleRateLimit ( response ) ;
101107 // Retry API query when we encounter a 429 rate limit error.
102108 if ( response . status === 429 ) {
103- return this . query ( apiUrl , maxTimestamp ) ;
109+ return this . query ( apiUrl , options ) ;
104110 }
105111 try {
106112 // Clone the response so the body of the original response can be
@@ -149,7 +155,7 @@ export class SpotifyReleaseLookup extends ReleaseApiLookup<SpotifyProvider, Albu
149155 const query = new URLSearchParams ( ) ;
150156
151157 if ( method === 'gtin' ) {
152- lookupUrl = new URL ( ` search` , this . provider . apiBaseUrl ) ;
158+ lookupUrl = new URL ( ' search' , this . provider . apiBaseUrl ) ;
153159 query . set ( 'type' , 'album' ) ;
154160 query . set ( 'q' , `upc:${ value } ` ) ;
155161 if ( region ) {
@@ -178,10 +184,9 @@ export class SpotifyReleaseLookup extends ReleaseApiLookup<SpotifyProvider, Albu
178184 this . lookup . value = albumId ;
179185 }
180186
181- const cacheEntry = await this . provider . query < Album > (
182- this . constructReleaseApiUrl ( ) ,
183- this . options . snapshotMaxTimestamp ,
184- ) ;
187+ const cacheEntry = await this . provider . query < Album > ( this . constructReleaseApiUrl ( ) , {
188+ snapshotMaxTimestamp : this . options . snapshotMaxTimestamp ,
189+ } ) ;
185190 const release = cacheEntry . content ;
186191
187192 this . updateCacheTime ( cacheEntry . timestamp ) ;
@@ -198,10 +203,9 @@ export class SpotifyReleaseLookup extends ReleaseApiLookup<SpotifyProvider, Albu
198203 this . lookup . region = region ;
199204 for ( const gtin of gtins ) {
200205 this . lookup . value = gtin ;
201- const cacheEntry = await this . provider . query < SearchResult > (
202- this . constructReleaseApiUrl ( ) ,
203- this . options . snapshotMaxTimestamp ,
204- ) ;
206+ const cacheEntry = await this . provider . query < SearchResult > ( this . constructReleaseApiUrl ( ) , {
207+ snapshotMaxTimestamp : this . options . snapshotMaxTimestamp ,
208+ } ) ;
205209 this . updateCacheTime ( cacheEntry . timestamp ) ;
206210 const releases = cacheEntry . content ?. albums ?. items ;
207211 if ( releases ?. length ) {
@@ -223,10 +227,9 @@ export class SpotifyReleaseLookup extends ReleaseApiLookup<SpotifyProvider, Albu
223227 // tracks with separate requests if needed.
224228 let nextUrl = rawRelease . tracks . next ;
225229 while ( nextUrl && allTracks . length < rawRelease . tracks . total ) {
226- const cacheEntry = await this . provider . query < ResultList < SimplifiedTrack > > (
227- new URL ( nextUrl ) ,
228- this . options . snapshotMaxTimestamp ,
229- ) ;
230+ const cacheEntry = await this . provider . query < ResultList < SimplifiedTrack > > ( new URL ( nextUrl ) , {
231+ snapshotMaxTimestamp : this . options . snapshotMaxTimestamp ,
232+ } ) ;
230233 this . updateCacheTime ( cacheEntry . timestamp ) ;
231234 allTracks . push ( ...cacheEntry . content . items ) ;
232235 nextUrl = cacheEntry . content . next ;
@@ -256,11 +259,9 @@ export class SpotifyReleaseLookup extends ReleaseApiLookup<SpotifyProvider, Albu
256259 const apiUrl = new URL ( 'tracks' , this . provider . apiBaseUrl ) ;
257260 for ( let index = 0 ; index < trackIds . length ; index += maxResults ) {
258261 apiUrl . searchParams . set ( 'ids' , trackIds . slice ( index , index + maxResults ) . join ( ',' ) ) ;
259- apiUrl . search = apiUrl . searchParams . toString ( ) ;
260- const cacheEntry = await this . provider . query < TrackList > (
261- apiUrl ,
262- this . options . snapshotMaxTimestamp ,
263- ) ;
262+ const cacheEntry = await this . provider . query < TrackList > ( apiUrl , {
263+ snapshotMaxTimestamp : this . options . snapshotMaxTimestamp ,
264+ } ) ;
264265 this . updateCacheTime ( cacheEntry . timestamp ) ;
265266 allTracks . push ( ...cacheEntry . content . tracks ) ;
266267 }
0 commit comments