mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Renaming modules, removing useless and changing logic of bot initialization
This commit is contained in:
48
vulkan/music/Searcher.py
Normal file
48
vulkan/music/Searcher.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from vulkan.music.Types import Provider
|
||||
from vulkan.music.Spotify import SpotifySearch
|
||||
from vulkan.music.utils import is_url
|
||||
|
||||
|
||||
class Searcher():
|
||||
"""Turn the user input into list of musics names, support youtube and spotify"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.__Spotify = SpotifySearch()
|
||||
|
||||
def search(self, music: str) -> list:
|
||||
"""Return a list with the song names or an URL
|
||||
|
||||
Arg -> User Input, a string with the
|
||||
Return -> A list of musics names and Provider Type
|
||||
"""
|
||||
url_type = self.__identify_source(music)
|
||||
|
||||
if url_type == Provider.YouTube:
|
||||
return [music], Provider.YouTube
|
||||
|
||||
elif url_type == Provider.Spotify:
|
||||
if self.__Spotify.connected == True:
|
||||
musics = self.__Spotify.search(music)
|
||||
return musics, Provider.Name
|
||||
else:
|
||||
return [], Provider.Unknown
|
||||
|
||||
elif url_type == Provider.Name:
|
||||
return [music], Provider.Name
|
||||
|
||||
elif url_type == Provider.Unknown:
|
||||
return None, Provider.Unknown
|
||||
|
||||
def __identify_source(self, music) -> Provider:
|
||||
"""Identify the provider of a music"""
|
||||
if not is_url(music):
|
||||
return Provider.Name
|
||||
|
||||
if "https://www.youtu" in music or "https://youtu.be" in music:
|
||||
return Provider.YouTube
|
||||
|
||||
if "https://open.spotify.com" in music:
|
||||
return Provider.Spotify
|
||||
|
||||
# If no match
|
||||
return Provider.Unknown
|
||||
Reference in New Issue
Block a user