diff --git a/vulkanbot/music/Song.py b/vulkanbot/music/Song.py index 7287dca..4cabce5 100644 --- a/vulkanbot/music/Song.py +++ b/vulkanbot/music/Song.py @@ -1,12 +1,68 @@ +import discord +import datetime +from config import config + + class Song(): - """Deal with information of a song""" + """Store the usefull information about a Song""" - def __init__(self, source) -> None: - self.__source = source - self.__get_info() + def __init__(self, info: dict) -> None: + if type(info) != dict: + return - def __get_info(self): - pass + self.__usefull_keys = ['url', 'title', 'duration', + 'description', 'webpage_url', + 'channel', 'id', 'uploader', + 'thumbnail'] + self.__extract_info(info) - def info(): + def __extract_info(self, info): + """Extract the usefull information returned by the Downloader""" + self.__info = {} + for key in self.__usefull_keys: + try: + self.__info[key] = info[key] + except Exception as e: + print(e) + raise e + + @property + def info(self): """Return the compiled info of this song""" + return self.__info + + @property + def title(self): + return self.__info['title'] + + @property + def source(self): + """Return the Song Source URL to play""" + return self.__info['url'] + + def embed(self): + """Configure and return the embed to show this song in discord chat""" + embed = discord.Embed(title='Music Playing', + description=f"[{self.__info['title']}]({self.__info['webpage_url']})", + color=config.COLOURS['blue']) + + if self.thumbnail is not None: + embed.set_thumbnail(url=self.thumbnail) + + embed.add_field(name=config.SONGINFO_UPLOADER, + value=self.__info['uploader'], + inline=False) + + if self.duration is not None: + duration = str(datetime.timedelta(seconds=self.__info['duration'])) + + embed.add_field(name=config.SONGINFO_DURATION, + value=f"{duration}", + inline=False) + + else: + embed.add_field(name=config.SONGINFO_DURATION, + value=config.SONGINFO_UNKNOWN_DURATION, + inline=False) + + return embed