Adding the Downloader class

This commit is contained in:
Rafael Vargas
2021-12-25 07:17:48 -04:00
parent 7775f259af
commit 35c2f2b16e
4 changed files with 114 additions and 19 deletions

View File

@@ -1,18 +1,20 @@
import re
from vulkanbot.music.Types import Provider
from vulkanbot.music.Spotify import SpotifySearch
from vulkanbot.music.Youtube import YoutubeSearch
class Searcher():
"""Turn the user input into list of musics names, support youtube and spotify"""
def __init__(self) -> None:
self.__Youtube = YoutubeSearch()
self.__Spotify = SpotifySearch()
print(f'Spotify Connected: {self.__Spotify.connect()}')
def search(self, music: str) -> list:
"""Return a list with the track name of a music or playlist"""
"""Return a list with the track name of a music or playlist
Return -> A list of musics names
"""
url_type = self.__identify_source(music)
if url_type == Provider.Name:
@@ -26,8 +28,9 @@ class Searcher():
musics = self.__Spotify.search(music)
return musics
def __identify_source(self, music):
if 'http' not in music:
def __identify_source(self, music) -> Provider:
"""Identify the provider of a music"""
if not self.__is_url(music):
return Provider.Name
if "https://www.youtu" in music or "https://youtu.be" in music:
@@ -38,3 +41,13 @@ class Searcher():
# If no match
return Provider.Unknown
def __is_url(self, string) -> bool:
"""Verify if a string is a url"""
regex = re.compile(
"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+")
if re.search(regex, string):
return True
else:
return False