-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: | ||
| 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: | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| class MusicPlayer(object): | ||
| def __init__(self, ctx, music, **kwargs): | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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"} | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.voice.stop() | ||
| try: | ||
| new = self.music.queue[self.ctx.guild.id][0] | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if self.on_loop_toggle_func: | ||
| await self.on_loop_toggle_func(self.ctx, song) | ||
| return song | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| while True: | ||
| if self.timeout > 0: | ||
| try: | ||
|
|
@@ -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]: | ||
|
|
@@ -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) | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| while True: | ||
| if self.timeout > 0: | ||
| try: | ||
|
|
@@ -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: | ||
|
|
@@ -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) | ||
|
|
@@ -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) | ||
|
|
@@ -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: | ||
|
|
@@ -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) | ||
|
|
@@ -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: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
get_video_datarefactored with the following changes:hoist-statement-from-if)remove-redundant-if)This removes the following comments ( why? ):