fix(musicdownloader): pylint fixes

This commit is contained in:
Seaswimmer 2023-09-24 20:34:16 -04:00
parent dbe10c53d1
commit 62a354b8c7
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -1,10 +1,11 @@
import asyncio
import re
import discord
import os
import re
import sqlite3
import discord
from redbot.core import Config, checks, commands, data_manager
from yt_dlp import YoutubeDL, utils
from redbot.core import commands, checks, Config, data_manager
class MusicDownloader(commands.Cog):
def __init__(self, bot):
@ -39,7 +40,7 @@ class MusicDownloader(commands.Cog):
db_path = os.path.join(data_path, "database.db")
con = sqlite3.connect(db_path)
cur = con.cursor()
cur.execute(f"SELECT user_id, reason FROM blacklist_log WHERE user_id = ?;", (user_id,))
cur.execute("SELECT user_id, reason FROM blacklist_log WHERE user_id = ?;", (user_id,))
result = cur.fetchone()
con.close()
if result:
@ -84,7 +85,7 @@ class MusicDownloader(commands.Cog):
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):
def youtube_download(self, url: str, path: str):
"""This function does the actual downloading of the YouTube Video."""
class Logger:
def debug(self, msg):
@ -108,14 +109,14 @@ class MusicDownloader(commands.Cog):
with YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url=url, download=False)
title = info['title']
id = info['id']
filename = title + f' [{id}].m4a'
Yid = info['id']
filename = title + f' [{Yid}].m4a'
full_filename = os.path.join(data_path, filename)
if os.path.isfile(full_filename):
previously_existed = True
else:
with YoutubeDL(ydl_opts) as ydl:
error_code = ydl.download(url)
ydl.download(url)
previously_existed = False
return filename, previously_existed
data_path = await self.config.save_directory()
@ -126,10 +127,8 @@ class MusicDownloader(commands.Cog):
pattern = "[" + re.escape(illegal_chars) + "]"
modified_subfolder = re.sub(pattern, r'__**\g<0>**__', subfolder)
await ctx.send(f"Your subfolder contains illegal characters: `{modified_subfolder}`")
return
elif os.path.isfile(data_path):
await ctx.send("Your 'subfolder' is a file, not a directory!")
return
elif os.path.exists(data_path) is False:
message = await ctx.send("Your subfolder does not exist yet, would you like to continue? It will be automatically created.")
def check(message):
@ -150,7 +149,7 @@ class MusicDownloader(commands.Cog):
message = await msg("YouTube Downloader started!")
try:
ytdlp_output = youtube_download(self, url, data_path, message)
except utils.DownloadError or utils.ExtractorError:
except (utils.DownloadError, 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
full_filename = os.path.join(data_path, ytdlp_output[0])
@ -185,7 +184,7 @@ class MusicDownloader(commands.Cog):
cur.execute("SELECT user_id, reason FROM blacklist_log WHERE user_id = ?;", (user.id,))
result = cur.fetchone()
if result:
user_id, reason = result
reason = result
await ctx.send(f"{user.mention} is in the blacklist for the following reason: `{reason}`", allowed_mentions = discord.AllowedMentions(users=False))
else:
await ctx.send(f"{user.mention} is not in the blacklist.", allowed_mentions = discord.AllowedMentions(users=False))