From 139ce07d244776101b72ecc02885ebf74f8faac5 Mon Sep 17 00:00:00 2001 From: Carsten Burgard Date: Sun, 13 Feb 2022 13:10:59 +0100 Subject: [PATCH] fix bug related to empty playlists --- PlexBot/bot.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/PlexBot/bot.py b/PlexBot/bot.py index 6bdee04..b1e5bce 100644 --- a/PlexBot/bot.py +++ b/PlexBot/bot.py @@ -437,7 +437,7 @@ class Plex(commands.Cog): return embed, art_file @staticmethod - def _build_embed_playlist(self, playlist): + def _build_embed_playlist(self, playlist, title, descrip): """ Creates a pretty embed card for playlists @@ -456,13 +456,14 @@ class Plex(commands.Cog): None """ # Grab the relevant thumbnail - img_stream = requests.get(self.pms.url(playlist.composite, True), stream=True).raw - img = io.BytesIO(img_stream.read()) + try: + img_stream = requests.get(self.pms.url(playlist.composite, True), stream=True).raw + img = io.BytesIO(img_stream.read()) + except: + raise MediaNotFoundError("no image available") # Attach to discord embed art_file = discord.File(img, filename="image0.png") - title = "Added playlist to queue" - descrip = f"{playlist.title}" embed = discord.Embed( title=title, description=descrip, colour=discord.Color.red() @@ -615,13 +616,17 @@ class Plex(commands.Cog): except VoiceChannelError: pass - bot_log.debug("Added to queue - %s", title) - embed, img = self._build_embed_playlist(self, playlist) - await ctx.send(embed=embed, file=img) + try: + embed, img = self._build_embed_playlist(self, playlist, "Added playlist to queue", playlist.title) + await ctx.send(embed=embed, file=img) - for item in playlist.items(): - if (item.TYPE == "track"): - await self.play_queue.put(item) + for item in playlist.items(): + if (item.TYPE == "track"): + await self.play_queue.put(item) + bot_log.debug("Added to queue - %s", title) + except MediaNotFoundError: + await ctx.send(message="Playlist "+title+" seems to be empty!") + bot_log.debug("Playlist empty - %s", title) @command() async def stop(self, ctx):