mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Refactoring Song completly, now uses one identifier
This commit is contained in:
parent
de535eccbc
commit
a45e54663e
@ -1,25 +1,25 @@
|
|||||||
from discord.embeds import Embed
|
from discord import Embed
|
||||||
|
import datetime
|
||||||
|
from vulkanbot.music.Interfaces import ISong, IPlaylist
|
||||||
|
from config import config
|
||||||
|
|
||||||
|
|
||||||
class Song():
|
class Song(ISong):
|
||||||
"""Store the usefull information about a Song"""
|
"""Store the usefull information about a Song"""
|
||||||
|
|
||||||
def __init__(self, url: str, title: str) -> None:
|
def __init__(self, identifier: str, playlist: IPlaylist) -> None:
|
||||||
"""Create a song with only the URL to the youtube song"""
|
"""Create a song with only the URL to the youtube song"""
|
||||||
self.__url = url
|
self.__identifier = identifier
|
||||||
self.__title = title
|
|
||||||
self.__info = {}
|
self.__info = {}
|
||||||
|
self.__playlist: IPlaylist = playlist
|
||||||
|
|
||||||
def finish_down(self, info: dict) -> None:
|
def finish_down(self, info: dict) -> None:
|
||||||
"""Get and store the full information of the song"""
|
"""Get and store the full information of the song"""
|
||||||
self.__usefull_keys = ['url', 'duration',
|
self.__usefull_keys = ['url', 'duration',
|
||||||
'description', 'webpage_url',
|
'title', 'webpage_url',
|
||||||
'channel', 'id', 'uploader',
|
'channel', 'id', 'uploader',
|
||||||
'thumbnail']
|
'thumbnail', 'original_url']
|
||||||
self.__extract_info(info)
|
|
||||||
|
|
||||||
def __extract_info(self, info) -> None:
|
|
||||||
"""Extract the usefull information returned by the Downloader"""
|
|
||||||
for key in self.__usefull_keys:
|
for key in self.__usefull_keys:
|
||||||
try:
|
try:
|
||||||
self.__info[key] = info[key]
|
self.__info[key] = info[key]
|
||||||
@ -27,38 +27,63 @@ class Song():
|
|||||||
print(e)
|
print(e)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def embed(self) -> Embed:
|
|
||||||
"""Configure and return the info to create the embed for this song"""
|
|
||||||
info = {
|
|
||||||
'title': self.__title,
|
|
||||||
'url': self.__url,
|
|
||||||
'uploader': self.__info['uploader']
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'thumbnail' in self.__info.keys():
|
|
||||||
info['thumbnail'] = self.__info['thumbnail']
|
|
||||||
|
|
||||||
if 'duration' in self.__info.keys():
|
|
||||||
info['duration'] = self.__info['duration']
|
|
||||||
|
|
||||||
return info
|
|
||||||
|
|
||||||
@property
|
|
||||||
def info(self) -> dict:
|
|
||||||
"""Return the compiled info of this song"""
|
|
||||||
if self.__info:
|
|
||||||
return self.__info
|
|
||||||
|
|
||||||
@property
|
|
||||||
def title(self) -> str:
|
|
||||||
return self.__title
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source(self) -> str:
|
def source(self) -> str:
|
||||||
"""Return the Song Source URL to play"""
|
"""Return the Song Source URL to play"""
|
||||||
if 'url' in self.__info.keys():
|
if 'url' in self.__info.keys():
|
||||||
return self.__info['url']
|
return self.__info['url']
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url(self) -> str:
|
def title(self) -> str:
|
||||||
return self.__url
|
"""Return the Song Title"""
|
||||||
|
if 'title' in self.__info.keys():
|
||||||
|
return self.__info['title']
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def duration(self) -> str:
|
||||||
|
"""Return the Song Title"""
|
||||||
|
if 'duration' in self.__info.keys():
|
||||||
|
return self.__info['duration']
|
||||||
|
else:
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def identifier(self) -> str:
|
||||||
|
return self.__identifier
|
||||||
|
|
||||||
|
def destroy(self) -> None:
|
||||||
|
"""Destroy the song from the playlist due to any type of error"""
|
||||||
|
self.__playlist.destroy_song(self)
|
||||||
|
del self
|
||||||
|
|
||||||
|
def embed(self, title: str) -> Embed:
|
||||||
|
"""Configure the embed to show the song information"""
|
||||||
|
|
||||||
|
embedvc = Embed(
|
||||||
|
title=title,
|
||||||
|
description=f"[{self.__info['title']}]({self.__info['original_url']})",
|
||||||
|
color=config.COLOURS['blue']
|
||||||
|
)
|
||||||
|
|
||||||
|
embedvc.add_field(name=config.SONGINFO_UPLOADER,
|
||||||
|
value=self.__info['uploader'],
|
||||||
|
inline=False)
|
||||||
|
|
||||||
|
if 'thumbnail' in self.__info.keys():
|
||||||
|
embedvc.set_thumbnail(url=self.__info['thumbnail'])
|
||||||
|
|
||||||
|
if 'duration' in self.__info.keys():
|
||||||
|
duration = str(datetime.timedelta(seconds=self.__info['duration']))
|
||||||
|
embedvc.add_field(name=config.SONGINFO_DURATION,
|
||||||
|
value=f"{duration}",
|
||||||
|
inline=False)
|
||||||
|
else:
|
||||||
|
embedvc.add_field(name=config.SONGINFO_DURATION,
|
||||||
|
value=config.SONGINFO_UNKNOWN_DURATION,
|
||||||
|
inline=False)
|
||||||
|
|
||||||
|
return embedvc
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user