Skip to content

Commit

Permalink
Minor suggested songs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
stekc committed Oct 10, 2024
1 parent 9b15bce commit 7deb88e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cogs/songs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import json
import os
import re
Expand Down Expand Up @@ -94,6 +95,8 @@ async def check_enabled(self, site: str, config, guild_id: int = None):

@cached(ttl=86400)
async def suggested_songs(self, artist: str, track: str):
loop = asyncio.get_event_loop()
start_time = loop.time()
async with aiohttp.ClientSession() as session:
async with session.get(
f"https://ws.audioscrobbler.com/2.0/?method=track.getsimilar&artist={quote_plus(artist)}&track={quote_plus(track)}&api_key={os.getenv('LASTFM_TOKEN')}&format=json"
Expand All @@ -106,6 +109,8 @@ async def suggested_songs(self, artist: str, track: str):
spotify_url = await self.lastfm_to_spotify(track["url"])
if spotify_url:
links = await self.get_song_links(spotify_url)
if links is None:
continue
song_links = []
for platform, url in [
("Apple Music", links.get("appleMusic")),
Expand All @@ -124,6 +129,8 @@ async def suggested_songs(self, artist: str, track: str):
"links": " ".join(song_links),
}
)
end_time = loop.time()
print(f"Suggested songs fetched in {end_time - start_time} seconds.")
return suggested_songs

@commands.Cog.listener()
Expand Down

0 comments on commit 7deb88e

Please sign in to comment.