mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 18:27:59 -05:00
Audio Fixes (#4492)
* handles #4491 * add typing indicators to audio playlists commands like discussed with aika. * recheck perms upon change of token to avoid needing a reload. * Ensure the player lock is always released... on rewrite to this as a callback to the task. * ffs * resolves#4495 * missed one * aaaaaaaaa * fix https://canary.discord.com/channels/133049272517001216/387398816317440000/766711707921678396 * some tweaks * Clear errors to users around YouTube Quota
This commit is contained in:
@@ -3,6 +3,7 @@ import logging
|
||||
import math
|
||||
import re
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from typing import List, Optional
|
||||
|
||||
@@ -11,16 +12,17 @@ import lavalink
|
||||
|
||||
from discord.embeds import EmptyEmbed
|
||||
from redbot.core import commands
|
||||
from redbot.core.i18n import Translator
|
||||
from redbot.core.utils import AsyncIter
|
||||
from redbot.core.utils.chat_formatting import box, escape
|
||||
|
||||
from ...audio_dataclasses import LocalPath, Query
|
||||
from ...audio_logging import IS_DEBUG
|
||||
from ..abc import MixinMeta
|
||||
from ..cog_utils import CompositeMetaClass, _
|
||||
from ..cog_utils import CompositeMetaClass
|
||||
|
||||
log = logging.getLogger("red.cogs.Audio.cog.Utilities.formatting")
|
||||
|
||||
_ = Translator("Audio", Path(__file__))
|
||||
RE_SQUARE = re.compile(r"[\[\]]")
|
||||
|
||||
|
||||
@@ -157,7 +159,7 @@ class FormattingUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
if not await self.is_query_allowed(
|
||||
self.config,
|
||||
ctx,
|
||||
f"{search_choice.title} {search_choice.author} {search_choice.uri} " f"{str(query)}",
|
||||
f"{search_choice.title} {search_choice.author} {search_choice.uri} {str(query)}",
|
||||
query_obj=query,
|
||||
):
|
||||
if IS_DEBUG:
|
||||
@@ -295,7 +297,7 @@ class FormattingUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
if shorten:
|
||||
string = f"{track.author} - {track.title}"
|
||||
if len(string) > 40:
|
||||
string = "{}...".format((string[:40]).rstrip(" "))
|
||||
string = f"{(string[:40]).rstrip(' ')}..."
|
||||
string = f'**{escape(f"{string}", formatting=True)}**'
|
||||
else:
|
||||
string = (
|
||||
@@ -306,7 +308,7 @@ class FormattingUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
if shorten:
|
||||
string = f"{track.title}"
|
||||
if len(string) > 40:
|
||||
string = "{}...".format((string[:40]).rstrip(" "))
|
||||
string = f"{(string[:40]).rstrip(' ')}..."
|
||||
string = f'**{escape(f"{string}", formatting=True)}**'
|
||||
else:
|
||||
string = f'**{escape(f"{track.title}", formatting=True)}**' + escape(
|
||||
@@ -315,7 +317,7 @@ class FormattingUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
else:
|
||||
string = query.to_string_user()
|
||||
if shorten and len(string) > 40:
|
||||
string = "{}...".format((string[:40]).rstrip(" "))
|
||||
string = f"{(string[:40]).rstrip(' ')}..."
|
||||
string = f'**{escape(f"{string}", formatting=True)}**'
|
||||
else:
|
||||
if track.is_stream:
|
||||
@@ -330,13 +332,13 @@ class FormattingUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
title = track.title
|
||||
string = f"{title}"
|
||||
if shorten and len(string) > 40:
|
||||
string = "{}...".format((string[:40]).rstrip(" "))
|
||||
string = f"{(string[:40]).rstrip(' ')}..."
|
||||
string = re.sub(RE_SQUARE, "", string)
|
||||
string = f"**[{escape(string, formatting=True)}]({track.uri}) **"
|
||||
elif hasattr(track, "to_string_user") and track.is_local:
|
||||
string = track.to_string_user() + " "
|
||||
if shorten and len(string) > 40:
|
||||
string = "{}...".format((string[:40]).rstrip(" "))
|
||||
string = f"{(string[:40]).rstrip(' ')}..."
|
||||
string = f'**{escape(f"{string}", formatting=True)}**'
|
||||
return string
|
||||
|
||||
@@ -391,7 +393,7 @@ class FormattingUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
async def draw_time(self, ctx) -> str:
|
||||
player = lavalink.get_player(ctx.guild.id)
|
||||
paused = player.paused
|
||||
pos = player.position
|
||||
pos = player.position or 1
|
||||
dur = getattr(player.current, "length", player.position or 1)
|
||||
sections = 12
|
||||
loc_time = round((pos / dur if dur != 0 else pos) * sections)
|
||||
|
||||
@@ -8,14 +8,16 @@ import lavalink
|
||||
|
||||
from fuzzywuzzy import process
|
||||
from redbot.core import commands
|
||||
from redbot.core.i18n import Translator
|
||||
from redbot.core.utils import AsyncIter
|
||||
|
||||
from ...audio_dataclasses import LocalPath, Query
|
||||
from ...errors import TrackEnqueueError
|
||||
from ..abc import MixinMeta
|
||||
from ..cog_utils import CompositeMetaClass, _
|
||||
from ..cog_utils import CompositeMetaClass
|
||||
|
||||
log = logging.getLogger("red.cogs.Audio.cog.Utilities.local_tracks")
|
||||
_ = Translator("Audio", Path(__file__))
|
||||
|
||||
|
||||
class LocalTrackUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
|
||||
@@ -5,6 +5,7 @@ import functools
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
from typing import Any, Final, Mapping, MutableMapping, Pattern, Union, cast
|
||||
|
||||
@@ -14,16 +15,17 @@ import lavalink
|
||||
from discord.embeds import EmptyEmbed
|
||||
from redbot.core import bank, commands
|
||||
from redbot.core.commands import Context
|
||||
from redbot.core.i18n import Translator
|
||||
from redbot.core.utils import AsyncIter
|
||||
from redbot.core.utils.chat_formatting import humanize_number
|
||||
|
||||
from ...apis.playlist_interface import get_all_playlist_for_migration23
|
||||
from ...utils import PlaylistScope, task_callback
|
||||
from ..abc import MixinMeta
|
||||
from ..cog_utils import CompositeMetaClass, _
|
||||
from ..cog_utils import CompositeMetaClass
|
||||
|
||||
log = logging.getLogger("red.cogs.Audio.cog.Utilities.miscellaneous")
|
||||
|
||||
_ = Translator("Audio", Path(__file__))
|
||||
_RE_TIME_CONVERTER: Final[Pattern] = re.compile(r"(?:(\d+):)?([0-5]?[0-9]):([0-5][0-9])")
|
||||
_prefer_lyrics_cache = {}
|
||||
|
||||
@@ -204,11 +206,8 @@ class MiscellaneousUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
|
||||
async def queue_duration(self, ctx: commands.Context) -> int:
|
||||
player = lavalink.get_player(ctx.guild.id)
|
||||
duration = []
|
||||
async for i in AsyncIter(range(len(player.queue))):
|
||||
if not player.queue[i].is_stream:
|
||||
duration.append(player.queue[i].length)
|
||||
queue_dur = sum(duration)
|
||||
dur = [i.length async for i in AsyncIter(player.queue, steps=50)]
|
||||
queue_dur = sum(dur)
|
||||
if not player.queue:
|
||||
queue_dur = 0
|
||||
try:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from typing import List, Optional, Tuple, Union
|
||||
|
||||
@@ -9,6 +10,7 @@ import lavalink
|
||||
|
||||
from discord.embeds import EmptyEmbed
|
||||
from redbot.core import commands
|
||||
from redbot.core.i18n import Translator
|
||||
from redbot.core.utils import AsyncIter
|
||||
from redbot.core.utils.chat_formatting import bold, escape
|
||||
|
||||
@@ -17,9 +19,10 @@ from ...audio_logging import IS_DEBUG, debug_exc_log
|
||||
from ...errors import QueryUnauthorized, SpotifyFetchError, TrackEnqueueError
|
||||
from ...utils import Notifier
|
||||
from ..abc import MixinMeta
|
||||
from ..cog_utils import CompositeMetaClass, _
|
||||
from ..cog_utils import CompositeMetaClass
|
||||
|
||||
log = logging.getLogger("red.cogs.Audio.cog.Utilities.player")
|
||||
_ = Translator("Audio", Path(__file__))
|
||||
|
||||
|
||||
class PlayerUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
@@ -279,6 +282,9 @@ class PlayerUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
return await self.send_embed_msg(
|
||||
ctx, title=error.message.format(prefix=ctx.prefix)
|
||||
)
|
||||
except Exception as e:
|
||||
self.update_player_lock(ctx, False)
|
||||
raise e
|
||||
self.update_player_lock(ctx, False)
|
||||
try:
|
||||
if enqueue_tracks:
|
||||
@@ -327,16 +333,21 @@ class PlayerUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
"\nUse `{prefix}audioset spotifyapi` for instructions."
|
||||
).format(prefix=ctx.prefix),
|
||||
)
|
||||
except Exception as e:
|
||||
self.update_player_lock(ctx, False)
|
||||
raise e
|
||||
elif query.is_album or query.is_playlist:
|
||||
self.update_player_lock(ctx, True)
|
||||
track_list = await self.fetch_spotify_playlist(
|
||||
ctx,
|
||||
"album" if query.is_album else "playlist",
|
||||
query,
|
||||
enqueue_tracks,
|
||||
forced=forced,
|
||||
)
|
||||
self.update_player_lock(ctx, False)
|
||||
try:
|
||||
self.update_player_lock(ctx, True)
|
||||
track_list = await self.fetch_spotify_playlist(
|
||||
ctx,
|
||||
"album" if query.is_album else "playlist",
|
||||
query,
|
||||
enqueue_tracks,
|
||||
forced=forced,
|
||||
)
|
||||
finally:
|
||||
self.update_player_lock(ctx, False)
|
||||
return track_list
|
||||
else:
|
||||
return await self.send_embed_msg(
|
||||
@@ -387,6 +398,9 @@ class PlayerUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
"try again in a few minutes."
|
||||
),
|
||||
)
|
||||
except Exception as e:
|
||||
self.update_player_lock(ctx, False)
|
||||
raise e
|
||||
tracks = result.tracks
|
||||
playlist_data = result.playlist_info
|
||||
if not enqueue:
|
||||
@@ -581,6 +595,9 @@ class PlayerUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
if await self.bot.is_owner(ctx.author):
|
||||
desc = _("Please check your console or logs for details.")
|
||||
return await self.send_embed_msg(ctx, title=title, description=desc)
|
||||
except Exception as e:
|
||||
self.update_player_lock(ctx, False)
|
||||
raise e
|
||||
description = await self.get_track_description(
|
||||
single_track, self.local_folder_current_path
|
||||
)
|
||||
@@ -659,7 +676,8 @@ class PlayerUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
except Exception as e:
|
||||
self.update_player_lock(ctx, False)
|
||||
raise e
|
||||
self.update_player_lock(ctx, False)
|
||||
finally:
|
||||
self.update_player_lock(ctx, False)
|
||||
return track_list
|
||||
|
||||
async def set_player_settings(self, ctx: commands.Context) -> None:
|
||||
|
||||
@@ -4,6 +4,7 @@ import datetime
|
||||
import json
|
||||
import logging
|
||||
import math
|
||||
from pathlib import Path
|
||||
|
||||
from typing import List, MutableMapping, Optional, Tuple, Union
|
||||
|
||||
@@ -12,6 +13,7 @@ import lavalink
|
||||
|
||||
from discord.embeds import EmptyEmbed
|
||||
from redbot.core import commands
|
||||
from redbot.core.i18n import Translator
|
||||
from redbot.core.utils import AsyncIter
|
||||
from redbot.core.utils.chat_formatting import box
|
||||
from redbot.core.utils.menus import start_adding_reactions
|
||||
@@ -23,9 +25,10 @@ from ...audio_logging import debug_exc_log
|
||||
from ...errors import TooManyMatches, TrackEnqueueError
|
||||
from ...utils import Notifier, PlaylistScope
|
||||
from ..abc import MixinMeta
|
||||
from ..cog_utils import CompositeMetaClass, _
|
||||
from ..cog_utils import CompositeMetaClass
|
||||
|
||||
log = logging.getLogger("red.cogs.Audio.cog.Utilities.playlists")
|
||||
_ = Translator("Audio", Path(__file__))
|
||||
|
||||
|
||||
class PlaylistUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
@@ -413,6 +416,9 @@ class PlaylistUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
"try again in a few minutes."
|
||||
),
|
||||
)
|
||||
except Exception as e:
|
||||
self.update_player_lock(ctx, False)
|
||||
raise e
|
||||
|
||||
track = result.tracks[0]
|
||||
except Exception as err:
|
||||
@@ -599,6 +605,9 @@ class PlaylistUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
"minutes."
|
||||
),
|
||||
)
|
||||
except Exception as e:
|
||||
self.update_player_lock(ctx, False)
|
||||
raise e
|
||||
|
||||
tracks = result.tracks
|
||||
if not tracks:
|
||||
@@ -625,6 +634,9 @@ class PlaylistUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
"minutes."
|
||||
),
|
||||
)
|
||||
except Exception as e:
|
||||
self.update_player_lock(ctx, False)
|
||||
raise e
|
||||
|
||||
tracks = result.tracks
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import math
|
||||
from pathlib import Path
|
||||
|
||||
from typing import List, Tuple
|
||||
|
||||
@@ -8,14 +9,16 @@ import lavalink
|
||||
|
||||
from fuzzywuzzy import process
|
||||
from redbot.core import commands
|
||||
from redbot.core.i18n import Translator
|
||||
from redbot.core.utils import AsyncIter
|
||||
from redbot.core.utils.chat_formatting import humanize_number
|
||||
|
||||
from ...audio_dataclasses import LocalPath, Query
|
||||
from ..abc import MixinMeta
|
||||
from ..cog_utils import CompositeMetaClass, _
|
||||
from ..cog_utils import CompositeMetaClass
|
||||
|
||||
log = logging.getLogger("red.cogs.Audio.cog.Utilities.queue")
|
||||
_ = Translator("Audio", Path(__file__))
|
||||
|
||||
|
||||
class QueueUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
|
||||
Reference in New Issue
Block a user