Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 17 additions & 41 deletions DiscordUtils/Music.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,49 +48,29 @@ async def get_video_data(url, search, bettersearch, loop):
title = data["title"]
description = data["description"]
likes = data["like_count"]
#dislikes = data["dislike_count"]
views = data["view_count"]
duration = data["duration"]
thumbnail = data["thumbnail"]
channel = data["uploader"]
channel_url = data["uploader_url"]
return Song(source, url, title, description, views, duration, thumbnail, channel, channel_url, False)
else:
if bettersearch:
url = await ytbettersearch(url)
data = await loop.run_in_executor(None, lambda: ydl.extract_info(url, download=False))
source = data["url"]
url = "https://www.youtube.com/watch?v="+data["id"]
title = data["title"]
description = data["description"]
#likes = data["like_count"]
#dislikes = data["dislike_count"]
views = data["view_count"]
duration = data["duration"]
thumbnail = data["thumbnail"]
channel = data["uploader"]
channel_url = data["uploader_url"]
return Song(source, url, title, description, views, duration, thumbnail, channel, channel_url, False)
elif search:
else:
Comment on lines -51 to +55
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_video_data refactored with the following changes:

This removes the following comments ( why? ):

#dislikes = data["dislike_count"]
#likes = data["like_count"]

ytdl = youtube_dl.YoutubeDL({"format": "bestaudio/best", "restrictfilenames": True, "noplaylist": True, "nocheckcertificate": True, "ignoreerrors": True, "logtostderr": False, "quiet": True, "no_warnings": True, "default_search": "auto", "source_address": "0.0.0.0"})
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=False))
try:
data = data["entries"][0]
except KeyError or TypeError:
pass
del ytdl
source = data["url"]
url = "https://www.youtube.com/watch?v="+data["id"]
title = data["title"]
description = data["description"]
#likes = data["like_count"]
#dislikes = data["dislike_count"]
views = data["view_count"]
duration = data["duration"]
thumbnail = data["thumbnail"]
channel = data["uploader"]
channel_url = data["uploader_url"]
return Song(source, url, title, description, views, duration, thumbnail, channel, channel_url, False)
source = data["url"]
url = "https://www.youtube.com/watch?v="+data["id"]
title = data["title"]
description = data["description"]
#dislikes = data["dislike_count"]
views = data["view_count"]
duration = data["duration"]
thumbnail = data["thumbnail"]
channel = data["uploader"]
channel_url = data["uploader_url"]
return Song(source, url, title, description, views, duration, thumbnail, channel, channel_url, False)

def check_queue(ctx, opts, music, after, on_play, loop):
if not has_voice:
Expand Down Expand Up @@ -143,8 +123,7 @@ def get_player(self, **kwargs):
return player
elif not channel and guild and player.ctx.guild.id == guild:
return player
else:
return None
return None
Comment on lines -146 to +126
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Music.get_player refactored with the following changes:


class MusicPlayer(object):
def __init__(self, ctx, music, **kwargs):
Expand All @@ -160,7 +139,7 @@ def __init__(self, ctx, music, **kwargs):
self.after_func = check_queue
self.on_play_func = self.on_queue_func = self.on_skip_func = self.on_stop_func = self.on_pause_func = self.on_resume_func = self.on_loop_toggle_func = self.on_volume_change_func = self.on_remove_from_queue_func = None
ffmpeg_error = kwargs.get("ffmpeg_error_betterfix", kwargs.get("ffmpeg_error_fix"))
if ffmpeg_error and "ffmpeg_error_betterfix" in kwargs.keys():
if ffmpeg_error and "ffmpeg_error_betterfix" in kwargs:
Comment on lines -163 to +142
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MusicPlayer.__init__ refactored with the following changes:

self.ffmpeg_opts = {"options": "-vn -loglevel quiet -hide_banner -nostats", "before_options": "-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 0 -nostdin"}
elif ffmpeg_error:
self.ffmpeg_opts = {"options": "-vn", "before_options": "-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 0 -nostdin"}
Expand Down Expand Up @@ -202,11 +181,11 @@ async def play(self):
async def skip(self, force=False):
if len(self.music.queue[self.ctx.guild.id]) == 0:
raise NotPlaying("Cannot loop because nothing is being played")
elif not len(self.music.queue[self.ctx.guild.id]) > 1 and not force:
elif len(self.music.queue[self.ctx.guild.id]) <= 1 and not force:
raise EmptyQueue("Cannot skip because queue is empty")
else:
old = self.music.queue[self.ctx.guild.id][0]
old.is_looping = False if old.is_looping else False
old.is_looping = False
Comment on lines -205 to +188
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MusicPlayer.skip refactored with the following changes:

self.voice.stop()
try:
new = self.music.queue[self.ctx.guild.id][0]
Expand Down Expand Up @@ -259,10 +238,7 @@ async def toggle_song_loop(self):
song = self.music.queue[self.ctx.guild.id][0]
except:
raise NotPlaying("Cannot loop because nothing is being played")
if not song.is_looping:
song.is_looping = True
else:
song.is_looping = False
song.is_looping = not song.is_looping
Comment on lines -262 to +241
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MusicPlayer.toggle_song_loop refactored with the following changes:

if self.on_loop_toggle_func:
await self.on_loop_toggle_func(self.ctx, song)
return song
Expand Down
25 changes: 10 additions & 15 deletions DiscordUtils/Pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async def run(self, embeds, send_to=None):
msg = await msg.channel.fetch_message(msg.id)
def check(reaction, user):
return user == wait_for and reaction.message.id == msg.id and str(reaction.emoji) in self.control_emojis

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AutoEmbedPaginator.run refactored with the following changes:

while True:
if self.timeout > 0:
try:
Expand All @@ -42,7 +43,6 @@ def check(reaction, user):
except:
pass
return msg
break
else:
reaction, user = await self.bot.wait_for("reaction_add",check=check)
if str(reaction.emoji) == self.control_emojis[0]:
Expand All @@ -57,7 +57,7 @@ def check(reaction, user):
await msg.edit(embed=self.embeds[0])
elif str(reaction.emoji) == self.control_emojis[1]:
self.current_page = self.current_page-1
self.current_page = 0 if self.current_page<0 else self.current_page
self.current_page = max(self.current_page, 0)
if self.remove_reactions:
try:
await msg.remove_reaction(str(reaction.emoji), user)
Expand All @@ -75,7 +75,6 @@ def check(reaction, user):
except:
pass
return msg
break
elif str(reaction.emoji) == self.control_emojis[3]:
self.current_page = self.current_page + 1
self.current_page = len(self.embeds)-1 if self.current_page > len(self.embeds)-1 else self.current_page
Expand Down Expand Up @@ -149,6 +148,7 @@ async def run(self, embeds, send_to=None):
msg = await msg.channel.fetch_message(msg.id)
def check(reaction, user):
return user == wait_for and reaction.message.id == msg.id and str(reaction.emoji) in self.control_emojis

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CustomEmbedPaginator.run refactored with the following changes:

while True:
if self.timeout > 0:
try:
Expand All @@ -162,7 +162,6 @@ def check(reaction, user):
pass
self.current_page = 0
return msg
break
else:
reaction, user = await self.bot.wait_for("reaction_add",check=check)
for emoji in self.control_emojis:
Expand Down Expand Up @@ -191,7 +190,7 @@ def check(reaction, user):
await msg.edit(embed=self.embeds[len(self.embeds)-1])
elif cmd.lower() == "next":
self.current_page += 1
self.current_page = len(self.embeds)-1 if self.current_page > len(self.embeds)-1 else self.current_page
self.current_page = min(self.current_page, len(self.embeds)-1)
if self.remove_reactions:
try:
await msg.remove_reaction(str(reaction.emoji), user)
Expand All @@ -202,7 +201,7 @@ def check(reaction, user):
await msg.edit(embed=self.embeds[self.current_page])
elif cmd.lower() == "back":
self.current_page = self.current_page-1
self.current_page = 0 if self.current_page<0 else self.current_page
self.current_page = max(self.current_page, 0)
if self.remove_reactions:
try:
await msg.remove_reaction(str(reaction.emoji), user)
Expand All @@ -215,8 +214,7 @@ def check(reaction, user):
self.current_page = 0
await msg.delete()
return msg
break
elif cmd.lower() == "clear" or cmd.lower() == "lock":
elif cmd.lower() in ["clear", "lock"]:
self.current_page = 0
for reaction in msg.reactions:
try:
Expand All @@ -229,15 +227,12 @@ def check(reaction, user):
except:
pass
return msg
break
elif cmd.startswith("page"):
shit = cmd.split()
pg = int(shit[1])
self.current_page = pg
if pg > len(embeds)-1:
pg = len(embeds)-1
if pg < 0:
pg = 0
pg = min(pg, len(embeds)-1)
pg = max(pg, 0)
if self.remove_reactions:
try:
await msg.remove_reaction(str(reaction.emoji), user)
Expand All @@ -252,8 +247,8 @@ def check(reaction, user):
something = things[0]
if something.isdigit():
index = int(something)
index = len(self.control_emojis)-1 if index > len(self.control_emojis)-1 else index
index = 0 if index < 0 else index
index = min(index, len(self.control_emojis)-1)
index = max(index, 0)
emoji = self.control_emojis[index]
if self.remove_reactions:
try:
Expand Down