fix youtube dl timeout

This commit is contained in:
Milka64 2021-12-14 15:16:04 +01:00
parent 84dd36208f
commit d1f7d91485

View file

@ -16,6 +16,8 @@ import requests
import youtube_dl import youtube_dl
import configparser import configparser
import argparse import argparse
import typing
import functools
from bs4 import BeautifulSoup as bs from bs4 import BeautifulSoup as bs
from discord.ext import tasks, commands from discord.ext import tasks, commands
@ -40,6 +42,7 @@ stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.INFO) stream_handler.setLevel(logging.INFO)
logger.addHandler(stream_handler) logger.addHandler(stream_handler)
class Mybot(commands.Cog): class Mybot(commands.Cog):
#Fonctions necesaires pour Kabot. #Fonctions necesaires pour Kabot.
def __init__( def __init__(
@ -348,11 +351,12 @@ class Mybot(commands.Cog):
}], }],
} }
with youtube_dl.YoutubeDL(ydl_opts) as ydl: with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url]) info_dict = ydl.extract_info(url, download=False)
info_dict = ydl.extract_info(url, download=False) out_file = ydl.prepare_filename(info_dict)
out_file = ydl.prepare_filename(info_dict) extension = out_file.split('.')[-1]
extension = out_file.split('.')[-1] out_file = out_file.replace(extension, 'mp3')
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)) self.sounds.append((out_file, ctx))
@commands.command() @commands.command()