fix bug related to empty playlists

This commit is contained in:
Carsten Burgard 2022-02-13 13:10:59 +01:00
parent 5f9c83b75e
commit 139ce07d24

View File

@ -437,7 +437,7 @@ class Plex(commands.Cog):
return embed, art_file return embed, art_file
@staticmethod @staticmethod
def _build_embed_playlist(self, playlist): def _build_embed_playlist(self, playlist, title, descrip):
""" """
Creates a pretty embed card for playlists Creates a pretty embed card for playlists
@ -456,13 +456,14 @@ class Plex(commands.Cog):
None None
""" """
# Grab the relevant thumbnail # Grab the relevant thumbnail
img_stream = requests.get(self.pms.url(playlist.composite, True), stream=True).raw try:
img = io.BytesIO(img_stream.read()) 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 # Attach to discord embed
art_file = discord.File(img, filename="image0.png") art_file = discord.File(img, filename="image0.png")
title = "Added playlist to queue"
descrip = f"{playlist.title}"
embed = discord.Embed( embed = discord.Embed(
title=title, description=descrip, colour=discord.Color.red() title=title, description=descrip, colour=discord.Color.red()
@ -615,13 +616,17 @@ class Plex(commands.Cog):
except VoiceChannelError: except VoiceChannelError:
pass pass
bot_log.debug("Added to queue - %s", title) try:
embed, img = self._build_embed_playlist(self, playlist) embed, img = self._build_embed_playlist(self, playlist, "Added playlist to queue", playlist.title)
await ctx.send(embed=embed, file=img) await ctx.send(embed=embed, file=img)
for item in playlist.items(): for item in playlist.items():
if (item.TYPE == "track"): if (item.TYPE == "track"):
await self.play_queue.put(item) 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() @command()
async def stop(self, ctx): async def stop(self, ctx):