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