Upgrading PlayController and Spotify Connection

This commit is contained in:
Rafael Vargas
2022-03-26 17:42:49 -04:00
parent f30513f710
commit 4c66c64041
15 changed files with 213 additions and 163 deletions

View File

@@ -1,40 +1,44 @@
from Exceptions.Exceptions import InvalidInput, SpotifyError
from Music.Downloader import Downloader
from Music.Types import Provider
from Music.Spotify import SpotifySearch
from Utils.Utils import is_url
from Utils.Utils import Utils
from Config.Messages import SearchMessages
class Searcher():
def __init__(self) -> None:
self.__Spotify = SpotifySearch()
self.__messages = SearchMessages()
self.__down = Downloader()
def search(self, music: str) -> list:
provider = self.__identify_source(music)
async def search(self, track: str) -> list:
provider = self.__identify_source(track)
if provider == Provider.Unknown:
raise InvalidInput(self.__messages.UNKNOWN_INPUT, self.__messages.UNKNOWN_INPUT_TITLE)
if provider == Provider.YouTube:
return [music], Provider.YouTube
elif provider == Provider.YouTube:
musics = await self.__down.extract_info(track)
return musics
elif provider == Provider.Spotify:
if self.__Spotify.connected == True:
musics = self.__Spotify.search(music)
return musics, Provider.Name
else:
print('DEVELOPER NOTE -> Spotify Not Connected')
return [], Provider.Unknown
try:
musics = self.__Spotify.search(track)
return musics
except:
raise SpotifyError(self.__messages.SPOTIFY_ERROR, self.__messages.GENERIC_TITLE)
elif provider == Provider.Name:
return [music], Provider.Name
return [track]
elif provider == Provider.Unknown:
return None, Provider.Unknown
def __identify_source(self, music) -> Provider:
if not is_url(music):
def __identify_source(self, track) -> Provider:
if not Utils.is_url(track):
return Provider.Name
if "https://www.youtu" in music or "https://youtu.be" in music or "https://music.youtube" in music:
if "https://www.youtu" in track or "https://youtu.be" in track or "https://music.youtube" in track:
return Provider.YouTube
if "https://open.spotify.com" in music:
if "https://open.spotify.com" in track:
return Provider.Spotify
return Provider.Unknown