From 964dc273083451389e6f134d76c6ffec50bb0b11 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Thu, 28 Sep 2023 21:59:23 -0600 Subject: [PATCH] music: woo! parsing hlswith regex! woo! yeah! --- src/modules/music.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/modules/music.js b/src/modules/music.js index af20805..3d34218 100644 --- a/src/modules/music.js +++ b/src/modules/music.js @@ -184,6 +184,7 @@ async function createVoiceConnection(guild_id, voice_id, text_id) { return state; } +const REGEX_HLS_AUDIO_TRACK = /#EXT-X-MEDIA:URI="(.+?)",TYPE=AUDIO,/; async function enqueue({ guild_id, voice_id, @@ -233,13 +234,22 @@ async function enqueue({ thumbnail = info?.thumbnailUrl; const hlsUrl = new URL(info.hls); + const hlsBase = await fetch(info.hls) + .then((res) => res.text()) + .then((data) => + data.replaceAll( + "/api/manifest/", + `https://${hlsUrl.hostname}/api/manifest/` + ) + ); + media = Readable.from( - await fetch(info.hls) + await fetch(hlsBase.match(REGEX_HLS_AUDIO_TRACK)[1]) .then((res) => res.text()) .then((data) => data.replaceAll( - "/api/manifest/", - `https://${hlsUrl.hostname}/api/manifest/` + "/videoplayback/", + `https://${hlsUrl.hostname}/videoplayback/` ) ) );