fix: reverted changes to music downloader so it at least works while I fix it properly

This commit is contained in:
Seaswimmer 2023-08-05 18:29:35 -04:00
parent cf6e86d93e
commit 28c9373fdd
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -3,7 +3,6 @@ import re
import discord import discord
import os import os
import sqlite3 import sqlite3
import concurrent.futures
from yt_dlp import YoutubeDL, utils from yt_dlp import YoutubeDL, utils
from redbot.core import commands, checks, Config, data_manager 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: elif os.path.exists(data_path) is False:
await ctx.send("The path you've provided doesn't exist!") await ctx.send("The path you've provided doesn't exist!")
def youtube_download(self, url: str, path: str): @commands.command(aliases=["dl"])
"""This method does the actual downloading of the YouTube Video.""" 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: class Logger:
def debug(self, msg): def debug(self, msg):
if msg.startswith('[debug] '): if msg.startswith('[debug] '):
@ -93,7 +110,7 @@ class MusicDownloader(commands.Cog):
title = info['title'] title = info['title']
id = info['id'] id = info['id']
filename = title + f' [{id}].m4a' 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): if os.path.isfile(full_filename):
previously_existed = True previously_existed = True
else: else:
@ -101,30 +118,6 @@ class MusicDownloader(commands.Cog):
error_code = ydl.download(url) error_code = ydl.download(url)
previously_existed = False previously_existed = False
return filename, previously_existed 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() data_path = await self.config.save_directory()
if subfolder and await self.bot.is_owner(ctx.author): if subfolder and await self.bot.is_owner(ctx.author):
data_path = os.path.join(data_path, subfolder) data_path = os.path.join(data_path, subfolder)
@ -156,7 +149,7 @@ class MusicDownloader(commands.Cog):
msg = ctx.send msg = ctx.send
message = await msg("YouTube Downloader started!") message = await msg("YouTube Downloader started!")
try: 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: 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.") 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 return