@@ -7,7 +7,6 @@ import { toast } from "react-toastify";
7
7
import ReactMarkdown from "react-markdown" ;
8
8
import SpotifyPlayer from "../common/brainzplayer/SpotifyPlayer" ;
9
9
import YoutubePlayer from "../common/brainzplayer/YoutubePlayer" ;
10
- import SpotifyAPIService from "./SpotifyAPIService" ;
11
10
import NamePill from "../personal-recommendations/NamePill" ;
12
11
import { GlobalAppContextT } from "./GlobalAppContext" ;
13
12
import APIServiceClass from "./APIService" ;
@@ -814,6 +813,31 @@ const getAlbumArtFromReleaseMBID = async (
814
813
return undefined ;
815
814
} ;
816
815
816
+ const getAlbumArtFromSpotifyTrackID = async (
817
+ spotifyTrackID : string ,
818
+ spotifyUser ?: SpotifyUser
819
+ ) : Promise < string | undefined > => {
820
+ const APIBaseURI = "https://api.spotify.com/v1" ;
821
+ if ( ! spotifyUser || ! spotifyTrackID ) {
822
+ return undefined ;
823
+ }
824
+ try {
825
+ const response = await fetch ( `${ APIBaseURI } /tracks/${ spotifyTrackID } ` , {
826
+ method : "GET" ,
827
+ headers : {
828
+ Authorization : `Bearer ${ spotifyUser ?. access_token } ` ,
829
+ } ,
830
+ } ) ;
831
+ if ( response . ok ) {
832
+ const track : SpotifyTrack = await response . json ( ) ;
833
+ return track . album ?. images ?. [ 0 ] ?. url ;
834
+ }
835
+ } catch ( error ) {
836
+ return undefined ;
837
+ }
838
+ return undefined ;
839
+ } ;
840
+
817
841
const getAlbumArtFromListenMetadata = async (
818
842
listen : BaseListenFormat ,
819
843
spotifyUser ?: SpotifyUser ,
@@ -825,9 +849,7 @@ const getAlbumArtFromListenMetadata = async (
825
849
SpotifyPlayer . hasPermissions ( spotifyUser )
826
850
) {
827
851
const trackID = SpotifyPlayer . getSpotifyTrackIDFromListen ( listen ) ;
828
- return new SpotifyAPIService ( spotifyUser ) . getAlbumArtFromSpotifyTrackID (
829
- trackID
830
- ) ;
852
+ return getAlbumArtFromSpotifyTrackID ( trackID , spotifyUser ) ;
831
853
}
832
854
if ( YoutubePlayer . isListenFromThisService ( listen ) ) {
833
855
const videoId = YoutubePlayer . getVideoIDFromListen ( listen ) ;
0 commit comments