fix: reverted changes to music downloader so it at least works while I fix it properly
This commit is contained in:
parent
cf6e86d93e
commit
28c9373fdd
1 changed files with 35 additions and 42 deletions
|
@ -3,7 +3,6 @@ import re
|
|||
import discord
|
||||
import os
|
||||
import sqlite3
|
||||
import concurrent.futures
|
||||
from yt_dlp import YoutubeDL, utils
|
||||
from redbot.core import commands, checks, Config, data_manager
|
||||
|
||||
|
@ -67,8 +66,26 @@ class MusicDownloader(commands.Cog):
|
|||
elif os.path.exists(data_path) is False:
|
||||
await ctx.send("The path you've provided doesn't exist!")
|
||||
|
||||
def youtube_download(self, url: str, path: str):
|
||||
"""This method does the actual downloading of the YouTube Video."""
|
||||
@commands.command(aliases=["dl"])
|
||||
async def download(self, ctx: commands.Context, url: str, delete: bool = False, subfolder: str = None):
|
||||
"""This command downloads a YouTube Video as an `m4a` and uploads the file to discord.
|
||||
|
||||
If you're considered a bot owner, you will be able to save downloaded files to the data path set in the `[p]change_data_path` command.
|
||||
|
||||
**Arguments**
|
||||
|
||||
- The `url` argument is just the url of the YouTube Video you're downloading.
|
||||
|
||||
- The `delete` argument will automatically delete the audio file after uploading it to Discord. If set to False, it will only save the file if you are a bot owner.
|
||||
|
||||
- The `subfolder` argument only does anything if `delete` is set to False, but it allows you to save to a subfolder in the data path you've set previously without having to change said data path manually."""
|
||||
try:
|
||||
self.blacklist_checker(ctx.author.id)
|
||||
except self.UserBlacklisted as e:
|
||||
await ctx.send(f"You are blacklisted from running this command!\nReason: `{e}`")
|
||||
return
|
||||
def youtube_download(self, url: str, path: str, message: discord.Message):
|
||||
"""This function does the actual downloading of the YouTube Video."""
|
||||
class Logger:
|
||||
def debug(self, msg):
|
||||
if msg.startswith('[debug] '):
|
||||
|
@ -93,7 +110,7 @@ class MusicDownloader(commands.Cog):
|
|||
title = info['title']
|
||||
id = info['id']
|
||||
filename = title + f' [{id}].m4a'
|
||||
full_filename = os.path.join(path, filename)
|
||||
full_filename = os.path.join(data_path, filename)
|
||||
if os.path.isfile(full_filename):
|
||||
previously_existed = True
|
||||
else:
|
||||
|
@ -101,30 +118,6 @@ class MusicDownloader(commands.Cog):
|
|||
error_code = ydl.download(url)
|
||||
previously_existed = False
|
||||
return filename, previously_existed
|
||||
|
||||
async def download_file(self, url: str, path: str):
|
||||
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||
result = await self.bot.loop.run_in_executor(executor, self.youtube_download, url, path)
|
||||
return result
|
||||
|
||||
@commands.command(aliases=["dl"])
|
||||
async def download(self, ctx: commands.Context, url: str, delete: bool = False, subfolder: str = None):
|
||||
"""This command downloads a YouTube Video as an `m4a` and uploads the file to discord.
|
||||
|
||||
If you're considered a bot owner, you will be able to save downloaded files to the data path set in the `[p]change_data_path` command.
|
||||
|
||||
**Arguments**
|
||||
|
||||
- The `url` argument is just the url of the YouTube Video you're downloading.
|
||||
|
||||
- The `delete` argument will automatically delete the audio file after uploading it to Discord. If set to False, it will only save the file if you are a bot owner.
|
||||
|
||||
- The `subfolder` argument only does anything if `delete` is set to False, but it allows you to save to a subfolder in the data path you've set previously without having to change said data path manually."""
|
||||
try:
|
||||
self.blacklist_checker(ctx.author.id)
|
||||
except self.UserBlacklisted as e:
|
||||
await ctx.send(f"You are blacklisted from running this command!\nReason: `{e}`")
|
||||
return
|
||||
data_path = await self.config.save_directory()
|
||||
if subfolder and await self.bot.is_owner(ctx.author):
|
||||
data_path = os.path.join(data_path, subfolder)
|
||||
|
@ -156,7 +149,7 @@ class MusicDownloader(commands.Cog):
|
|||
msg = ctx.send
|
||||
message = await msg("YouTube Downloader started!")
|
||||
try:
|
||||
ytdlp_output = await self.download_file(url, data_path)
|
||||
ytdlp_output = youtube_download(self, url, data_path, message)
|
||||
except utils.DownloadError or utils.ExtractorError:
|
||||
await message.edit(content="Please provide a link to YouTube and not another site.\nThe site you've linked to is known for using DRM protection, so MusicDownloader cannot download from it.")
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue