diff --git a/kabot/kabot/kabot.py b/kabot/kabot/kabot.py index 3346a8e..fe5f702 100644 --- a/kabot/kabot/kabot.py +++ b/kabot/kabot/kabot.py @@ -16,6 +16,8 @@ import requests import youtube_dl import configparser import argparse +import typing +import functools from bs4 import BeautifulSoup as bs from discord.ext import tasks, commands @@ -40,6 +42,7 @@ stream_handler = logging.StreamHandler() stream_handler.setLevel(logging.INFO) logger.addHandler(stream_handler) + class Mybot(commands.Cog): #Fonctions necesaires pour Kabot. def __init__( @@ -348,11 +351,12 @@ class Mybot(commands.Cog): }], } with youtube_dl.YoutubeDL(ydl_opts) as ydl: - ydl.download([url]) - info_dict = ydl.extract_info(url, download=False) - out_file = ydl.prepare_filename(info_dict) - extension = out_file.split('.')[-1] - out_file = out_file.replace(extension, 'mp3') + info_dict = ydl.extract_info(url, download=False) + out_file = ydl.prepare_filename(info_dict) + extension = out_file.split('.')[-1] + out_file = out_file.replace(extension, 'mp3') + if not os.path.isfile(out_file): + await asyncio.get_running_loop().run_in_executor(None, ydl.download,[url]) self.sounds.append((out_file, ctx)) @commands.command()