Skip to content
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

Use YouTube source plugin over the deprecated built-in source #6373

Open
wants to merge 3 commits into
base: V3/develop
Choose a base branch
from
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
14 changes: 14 additions & 0 deletions redbot/cogs/audio/core/commands/audioset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,20 @@ async def command_audioset_settings(self, ctx: commands.Context):
if is_owner:
msg += _("Localtracks path: [{localpath}]\n").format(**global_data)

if (
is_owner
and not global_data["use_external_lavalink"]
and self.managed_node_controller.plugins
):
plugins = self.managed_node_controller.plugins
msg += f"\n---{_('Lavalink Plugin Versions')}---"
plugin_name_max_len = 0
for plugin_name, __ in plugins.items():
plugin_name_max_len = max(plugin_name_max_len, len(plugin_name))
for plugin_name, plugin_version in plugins.items():
key = f"{plugin_name}:".ljust(plugin_name_max_len + 5)
msg += f"\n{key} [{plugin_version}]"

await self.send_embed_msg(ctx, description=box(msg, lang="ini"))

@command_audioset.command(name="logs")
Expand Down
31 changes: 27 additions & 4 deletions redbot/cogs/audio/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@
_ = Translator("Audio", pathlib.Path(__file__))
log = getLogger("red.Audio.manager")

_FAILED_TO_START: Final[Pattern] = re.compile(rb"Web server failed to start\. (.*)")
_LL_READY_LOG: Final[bytes] = b"Lavalink is ready to accept connections."
_LL_PLUGIN_LOG: Final[Pattern[bytes]] = re.compile(
rb"Found plugin '(?P<name>.+)' version (?P<version>\S+)$", re.MULTILINE
)
_FAILED_TO_START: Final[Pattern[bytes]] = re.compile(rb"Web server failed to start\. (.*)")

# Version regexes
#
Expand Down Expand Up @@ -295,11 +299,14 @@ def __ge__(self, other: object) -> bool:

class ServerManager:
JAR_VERSION: Final[str] = LavalinkVersion(3, 7, 11, red=3)
YT_PLUGIN_VERSION: Final[str] = "1.1.0"

LAVALINK_DOWNLOAD_URL: Final[str] = (
"https://github.com/Cog-Creators/Lavalink-Jars/releases/download/"
f"{JAR_VERSION}/"
"Lavalink.jar"
)
YT_PLUGIN_REPOSITORY: Final[str] = "https://maven.lavalink.dev/releases"

_java_available: ClassVar[Optional[bool]] = None
_java_version: ClassVar[Optional[Tuple[int, int]]] = None
Expand All @@ -323,6 +330,7 @@ def __init__(self, config: Config, cog: "Audio", timeout: Optional[int] = None)
self.cog = cog
self._args = []
self._pipe_task = None
self.plugins: dict[str, str] = {}

@property
def lavalink_download_dir(self) -> pathlib.Path:
Expand Down Expand Up @@ -422,7 +430,20 @@ async def _start(self, java_path: str) -> None:

async def process_settings(self):
data = change_dict_naming_convention(await self._config.yaml.all())
with open(self.lavalink_app_yml, "w") as f:
ll_config = data["lavalink"]
sources = ll_config["server"]["sources"]
plugins = ll_config.setdefault("plugins", [])

enable_yt_plugin = sources["youtube"]
if enable_yt_plugin:
sources["youtube"] = False
yt_plugin = {
"dependency": f"dev.lavalink.youtube:youtube-plugin:{self.YT_PLUGIN_VERSION}",
"repository": self.YT_PLUGIN_REPOSITORY,
}
plugins.append(yt_plugin)

with open(self.lavalink_app_yml, "w", encoding="utf-8") as f:
yaml.safe_dump(data, f)

async def _get_jar_args(self) -> Tuple[List[str], Optional[str]]:
Expand Down Expand Up @@ -518,12 +539,14 @@ async def _wait_for_launcher(self) -> None:
log.info("Waiting for Managed Lavalink node to be ready")
for i in itertools.cycle(range(50)):
line = await self._proc.stdout.readline()
if b"Lavalink is ready to accept connections." in line:
if _LL_READY_LOG in line:
self.ready.set()
log.info("Managed Lavalink node is ready to receive requests.")
self._pipe_task = asyncio.create_task(self._pipe_output())
break
if _FAILED_TO_START.search(line):
if match := _LL_PLUGIN_LOG.search(line):
self.plugins[match["name"].decode()] = match["version"].decode()
elif _FAILED_TO_START.search(line):
raise ManagedLavalinkStartFailure(
f"Lavalink failed to start: {line.decode().strip()}"
)
Expand Down
Loading