mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Moving is_url function to utils.py
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import re
|
|
||||||
from vulkanbot.music.Types import Provider
|
from vulkanbot.music.Types import Provider
|
||||||
from vulkanbot.music.Spotify import SpotifySearch
|
from vulkanbot.music.Spotify import SpotifySearch
|
||||||
|
from vulkanbot.music.utils import is_url
|
||||||
|
|
||||||
|
|
||||||
class Searcher():
|
class Searcher():
|
||||||
@@ -11,9 +11,10 @@ class Searcher():
|
|||||||
print(f'Spotify Connected: {self.__Spotify.connect()}')
|
print(f'Spotify Connected: {self.__Spotify.connect()}')
|
||||||
|
|
||||||
def search(self, music: str) -> list:
|
def search(self, music: str) -> list:
|
||||||
"""Return a list with the track name of a music or playlist
|
"""Return a list with the song names or an URL
|
||||||
|
|
||||||
Return -> A list of musics names
|
Arg -> User Input, a string with the
|
||||||
|
Return -> A list of musics names and Provider Type
|
||||||
"""
|
"""
|
||||||
url_type = self.__identify_source(music)
|
url_type = self.__identify_source(music)
|
||||||
|
|
||||||
@@ -27,9 +28,12 @@ class Searcher():
|
|||||||
elif url_type == Provider.Name:
|
elif url_type == Provider.Name:
|
||||||
return [music], Provider.Name
|
return [music], Provider.Name
|
||||||
|
|
||||||
|
elif url_type == Provider.Unknown:
|
||||||
|
return None, Provider.Unknown
|
||||||
|
|
||||||
def __identify_source(self, music) -> Provider:
|
def __identify_source(self, music) -> Provider:
|
||||||
"""Identify the provider of a music"""
|
"""Identify the provider of a music"""
|
||||||
if not self.__is_url(music):
|
if not is_url(music):
|
||||||
return Provider.Name
|
return Provider.Name
|
||||||
|
|
||||||
if "https://www.youtu" in music or "https://youtu.be" in music:
|
if "https://www.youtu" in music or "https://youtu.be" in music:
|
||||||
@@ -41,12 +45,3 @@ class Searcher():
|
|||||||
# If no match
|
# If no match
|
||||||
return Provider.Unknown
|
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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user