I'm creating a program in Python that through the Spotify API and by connecting your Spotify account, every time the song being played changes, it sends a notification with the title of the song and the name of the author with the win10toast library for notifications and spotipy for the spotify APIs. However, I would like to add that next to the notification add the cover image of the song being played but I can't find any method to add it. I tried using the win11toast library which has a good documentation page, and it works very well too, except that it doesn't display the images, it creates space to put them but it doesn't show anything, as you can see in the image attached below. Could anyone help me?
<- Notification with win11toast, this is the code
<- Notification with win10toast, below is the code fully explained
Win10toast code
With this part of code I can assign the variables name, artist, cover and url the respective values of the song, the name of the song, the name of the artist, the URL of the cover image and the URL of the song.
client_id = "CLIENT_ID"
client_secret = "CLIENT_SECRET"
redirect_uri = "REDIRECT_URL"
auth_manager = spotipy.SpotifyOAuth(
client_id=client_id,
client_secret=client_secret,
redirect_uri=redirect_uri,
scope="user-read-currently-playing"
)
sp = spotipy.Spotify(auth_manager=auth_manager)
showing = False
results = sp.current_user_playing_track()
name = results['item']['name']
artist = results['item']['artists'][0]['name']
cover = results['item']['album']['images'][0]['url']
url = results['item']['external_urls']['spotify']
Next with this part of code I create a function to open the song link when clicking on the notification via the webbrowser library, then I assign the spotify logo to the file_icon variable and then I create the notification via the win10toast library assigning the name, artist, file_name, the duration of the notification and the function of opening the song URL values to the respective parameters.
def open_url():
try:
webbrowser.open_new(url)
print('Opening URL...')
except:
print('Failed to open URL. Unsupported variable type.')
file_name = 'logo.ico'
toaster = ToastNotifier()
toaster.show_toast(
name,
artist,
icon_path=file_name,'
duration=5,
callback_on_click=open_url
)
Win11toast code
The part of code to connect to the spotify account via the API and the part of code to get the various values is the same as the code for win10toast
With this part of code I create the notification for windows, as I said at the beginning as you can see it is much simpler, the only problem as you can see at the beginning is that it does not show either the icon or the image on the side, however he creates the space to put it, only he can't seem to fit the image.
toast(name, artist, icon=cover, on_click=url, audio={'silent': 'true'})
The problem can't be the URL because I also tried with the examples in their documentation but it still doesn't work, most likely it doesn't work with Windows 10.
P.S: I tested my script on a virtual machine with windows 11 and in fact it works as you can see below.
