Adding new classes to upgrade the music code organization

This commit is contained in:
Rafael Vargas 2021-12-24 19:05:03 -04:00
parent 29998997bc
commit 4ba03ff8bc
17 changed files with 140 additions and 8 deletions

View File

@ -4,10 +4,11 @@ CETUS_API = dotenv_values('.env')['CETUS_API']
BOT_TOKEN = dotenv_values('.env')['BOT_TOKEN']
SPOTIFY_ID = dotenv_values('.env')['SPOTIFY_ID']
SPOTIFY_SECRET = dotenv_values('.env')['SPOTIFY_SECRET']
SECRET_MESSAGE = dotenv_values('.env')['SECRET_MESSAGE']
BOT_PREFIX = '!'
INITIAL_EXTENSIONS = {'vulkan.commands.Phrases', 'vulkan.commands.Warframe',
'vulkan.general.Filter', 'vulkan.general.Control', 'vulkan.music.Music'}
INITIAL_EXTENSIONS = {'vulkanbot.commands.Phrases', 'vulkanbot.commands.Warframe',
'vulkanbot.general.Filter', 'vulkanbot.general.Control', 'vulkanbot.music.Music'}
VC_TIMEOUT = 600 # seconds
VC_TIMEOUT_DEFAULT = True

View File

@ -3,7 +3,7 @@ import discord
from config import config
from discord.ext import commands
from vulkan.ErrorHandler import ErrorHandler
from vulkanbot.ErrorHandler import ErrorHandler
intents = discord.Intents.default()

View File

@ -1,6 +1,7 @@
import requests
import json
import discord
from config import config
from discord.ext import commands
from random import random as rand
@ -47,9 +48,8 @@ class Phrases(commands.Cog):
async def calculate_rgn(self, ctx):
x = rand()
print(x)
if x < 0.15:
await ctx.send('Se leu seu cu é meu\nBy: Minha Pica')
await ctx.send(config.SECRET_MESSAGE)
return True
else:
return False

View File

View File

View File

@ -0,0 +1,13 @@
class Downloader():
"""Download music source from Youtube with a music name"""
def __init__(self) -> None:
pass
def download(self, track_name: str) -> str:
if type(track_name) != str:
return
def download_many(self, track_list: list) -> list:
if type(track_list) != list:
return

View File

@ -1,10 +1,10 @@
import discord
from discord import colour
from discord.embeds import Embed
from discord.ext import commands
from discord.ext.commands.core import command
from youtube_dl import YoutubeDL
from vulkanbot.music.Downloader import Downloader
from vulkanbot.music.Searcher import Searcher
colours = {
'red': 0xDC143C,
'green': 0x00FF7F,
@ -15,6 +15,9 @@ colours = {
class Music(commands.Cog):
def __init__(self, client):
self.__searcher = Searcher()
self.__downloader = Downloader()
self.client = client
self.is_playing = False
self.repetingOne = False

View File

@ -0,0 +1,9 @@
class Playlist():
"""Class to manage and control the musics to play"""
def __init__(self) -> None:
self.queue = []
self.history = []
def next_music():
pass

View File

@ -0,0 +1,43 @@
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"""
url_type = self.__identify_source(music)
if url_type == Provider.Name:
return [music]
elif url_type == Provider.YouTube:
musics = self.__Youtube.search(music)
return musics
elif url_type == Provider.Spotify:
musics = self.__Spotify.search(music)
return musics
def __identify_source(self, music):
if 'http' not in music:
return Provider.Name
if "https://www.youtu" in music or "https://youtu.be" in music:
return Provider.YouTube
if "https://open.spotify.com/track" in music:
return Provider.Spotify
if "https://open.spotify.com/playlist" in music or "https://open.spotify.com/album" in music:
return Provider.Spotify_Playlist
# If no match
return Provider.Unknown

12
vulkanbot/music/Song.py Normal file
View File

@ -0,0 +1,12 @@
class Song():
"""Deal with information of a song"""
def __init__(self, source) -> None:
self.__source = source
self.__get_info()
def __get_info(self):
pass
def info():
"""Return the compiled info of this song"""

View File

@ -0,0 +1,22 @@
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
from config import config
class SpotifySearch():
"""Search and return musics names from Spotify"""
def __init__(self) -> None:
pass
def connect(self) -> bool:
try:
# Initialize the connection with Spotify API
self.__sp_api = spotipy.Spotify(auth_manager=SpotifyClientCredentials(
client_id=config.SPOTIFY_ID, client_secret=config.SPOTIFY_SECRET))
return True
except:
return False
def search(self, music) -> list:
pass

21
vulkanbot/music/Types.py Normal file
View File

@ -0,0 +1,21 @@
from enum import Enum
class Provider(Enum):
"""Store Enum Types of the Providers"""
Spotify = "Spotify"
Spotify_Playlist = "Spotify Playlist"
YouTube = "YouTube"
Name = 'Track Name'
Unknown = "Unknown"
class Playlist_Types(Enum):
Spotify_Playlist = "Spotify Playlist"
YouTube_Playlist = "YouTube Playlist"
Unknown = "Unknown"
class Origins(Enum):
Default = "Default"
Playlist = "Playlist"

View File

@ -0,0 +1,8 @@
class YoutubeSearch():
"""Search for tracks in youtube"""
def __init__(self) -> None:
pass
def search(self, track):
pass