diff --git a/commands/now_playing.py b/commands/now_playing.py index 325f720..26af24b 100644 --- a/commands/now_playing.py +++ b/commands/now_playing.py @@ -60,22 +60,47 @@ def setup(bot: bot.Bot): except Exception as e: print(e) await ctx.send(u.error_msg("Unknown database error.")) - if not username: await ctx.send(u.error_msg("Please provide an `artist - album` query or set your Last.fm username with `/setfm`.")) + if not username: await ctx.send(u.error_msg("Please provide an `artist | album` query or set your Last.fm username with `/setfm`.")) else: try: user = bot.lastfm.get_user(username) if not user.get_now_playing: last_played = user.get_recent_tracks(limit=1) - album = last_played[0].get_album() + albumobj = last_played[0].get_album() else: - album = user.get_now_playing().get_album() - - cover_art = album.get_cover_image() + albumobj = user.get_now_playing().get_album() - if not cover_art: await ctx.send(u.error_msg(f"**{album.get_name()}** does not seem to have cover art.")) - else: await ctx.send(f"Here's the cover art for **[{album.get_name()}]({album.get_url()})**:\n{cover_art}") + cover_art = albumobj.get_cover_image() + + if not cover_art: await ctx.send(u.error_msg(f"**{albumobj.get_name()}** does not seem to have cover art.")) + else: await ctx.send(f"Here's the cover art for **[{albumobj.get_name()}]({albumobj.get_url()})**:\ + {cover_art}") except Exception as e: print(e) await ctx.send(u.error_msg("Unknown error.")) + else: + try: + if "|" not in album: + await ctx.send(u.error_msg("Please search using the format `artist | album name`.")) + else: + artist = ' '.join(album).split(sep="|")[0] + albumtitle = ' '.join(album).split(sep="|")[1] + if not artist or not albumtitle: + await ctx.send(u.error_msg("Please enter a valid artist and album name.")) + else: + albumobj = bot.lastfm.get_album(artist=artist, title=albumtitle) + cover_art = albumobj.get_cover_image() + + if not cover_art: await ctx.send(u.error_msg(f"**{albumobj.get_name()}** does not seem to have cover art.")) + else: await ctx.send( + f"Here's the cover art for **[{albumobj.get_name(properly_capitalized=True)}]({albumobj.get_url()})**:\ + {cover_art}" + ) + except pylast.WSError as e: + print(e) + await ctx.send(u.error_msg(e)) + except Exception as e: + print(e) + await ctx.send(u.error_msg("Unknown parsing error."))