Skip to content

Commit 662e57e

Browse files
committed
Add support for a built-in cipher server
1 parent 015f5a0 commit 662e57e

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

redbot/cogs/audio/manager.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@
4545
)
4646
from ...core.utils import AsyncIter
4747

48+
try:
49+
from red_yt_cipher_solver import SolverServerProcess
50+
except ModuleNotFoundError:
51+
_HAS_CIPHER_SOLVER = False
52+
else:
53+
_HAS_CIPHER_SOLVER = True
54+
4855
if TYPE_CHECKING:
4956
from . import Audio
5057

@@ -146,6 +153,8 @@ def __init__(
146153
self._args = []
147154
self._pipe_task = None
148155
self.plugins: dict[str, str] = {}
156+
self.cipher_server: Optional[SolverServerProcess] = None
157+
self.cipher_server_task: Optional[asyncio.Task] = None
149158

150159
@property
151160
def lavalink_download_dir(self) -> pathlib.Path:
@@ -205,6 +214,17 @@ async def _start(self, java_path: str) -> None:
205214
raise ManagedLavalinkPreviouslyShutdownException(
206215
"Server manager has already been used - create another one"
207216
)
217+
218+
if _HAS_CIPHER_SOLVER:
219+
self.cipher_server = SolverServerProcess(
220+
log_file=self.lavalink_download_dir / "logs" / "solver-server.log"
221+
)
222+
# TODO: monitor the task
223+
self.cipher_server_task = asyncio.create_task(self.cipher_server.run())
224+
if not await self.cipher_server.wait_for_startup():
225+
log.warning("Failed to start the cipher server. Will continue without one.")
226+
self.cipher_server = None
227+
208228
await self.process_settings()
209229
await self.maybe_download_jar()
210230
args, msg = await self._get_jar_args()
@@ -245,6 +265,10 @@ async def _start(self, java_path: str) -> None:
245265

246266
async def process_settings(self):
247267
data = managed_node.generate_server_config(await self._config.yaml.all())
268+
if self.cipher_server is not None:
269+
plugin_config = data.setdefault("plugins", {}).setdefault("youtube", {})
270+
cipher_config = plugin_config.setdefault("remoteCipher", {})
271+
cipher_config["url"] = self.cipher_server.base_url
248272

249273
with open(self.lavalink_app_yml, "w", encoding="utf-8") as f:
250274
yaml.safe_dump(data, f)
@@ -378,6 +402,10 @@ async def shutdown(self) -> None:
378402
if self.start_monitor_task is not None:
379403
self.start_monitor_task.cancel()
380404
await self._partial_shutdown()
405+
if self.cipher_server:
406+
await self.cipher_server.close()
407+
if self.cipher_server_task:
408+
await self.cipher_server_task
381409

382410
async def _partial_shutdown(self) -> None:
383411
self.ready.clear()

requirements/base.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ schema
1818
typing_extensions
1919
yarl
2020
distro; sys_platform == "linux"
21+
Red-YT-Cipher-Solver; python_version >= '3.10' and ((sys_platform == 'win32' and platform_machine == 'AMD64') or (sys_platform == 'linux' and (platform_machine == 'x86_64' or platform_machine == 'aarch64')) or (sys_platform == 'darwin' and (platform_machine == 'x86_64' or platform_machine == 'arm64')))
2122
# https://github.com/MagicStack/uvloop/issues/702
2223
uvloop>=0.21.0,!=0.22.0,!=0.22.1; sys_platform != "win32" and platform_python_implementation == "CPython"
2324

requirements/base.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,19 @@ async-timeout==4.0.3; python_version != "3.11"
8282
# via aiohttp
8383
colorama==0.4.6; sys_platform == "win32"
8484
# via click
85+
deno==2.7.2; python_version >= '3.10' and ((sys_platform == 'win32' and platform_machine == 'AMD64') or (sys_platform == 'linux' and (platform_machine == 'x86_64' or platform_machine == 'aarch64')) or (sys_platform == 'darwin' and (platform_machine == 'x86_64' or platform_machine == 'arm64')))
86+
# via red-yt-cipher-solver
8587
distro==1.9.0; sys_platform == "linux" and sys_platform == "linux"
8688
# via -r base.in
8789
importlib-metadata==8.5.0; python_version != "3.10" and python_version != "3.11"
8890
# via markdown
8991
pytz==2026.1.post1; python_version == "3.8"
9092
# via babel
93+
red-yt-cipher-solver==0.3.0; python_version >= '3.10' and ((sys_platform == 'win32' and platform_machine == 'AMD64') or (sys_platform == 'linux' and (platform_machine == 'x86_64' or platform_machine == 'aarch64')) or (sys_platform == 'darwin' and (platform_machine == 'x86_64' or platform_machine == 'arm64')))
94+
# via -r base.in
9195
uvloop==0.21.0; (sys_platform != "win32" and platform_python_implementation == "CPython") and sys_platform != "win32"
9296
# via -r base.in
97+
yt-dlp-ejs==0.5.0; python_version >= '3.10' and ((sys_platform == 'win32' and platform_machine == 'AMD64') or (sys_platform == 'linux' and (platform_machine == 'x86_64' or platform_machine == 'aarch64')) or (sys_platform == 'darwin' and (platform_machine == 'x86_64' or platform_machine == 'arm64')))
98+
# via red-yt-cipher-solver
9399
zipp==3.20.2; python_version != "3.10" and python_version != "3.11"
94100
# via importlib-metadata

0 commit comments

Comments
 (0)