diff --git a/src/modules/music.js b/src/modules/music.js index 0fcf3d9..088ec37 100644 --- a/src/modules/music.js +++ b/src/modules/music.js @@ -1,6 +1,7 @@ const {Collection} = require("oceanic.js"); const { AudioPlayerStatus, + StreamType, createAudioPlayer, createAudioResource, } = require("@discordjs/voice"); @@ -189,6 +190,25 @@ async function createVoiceConnection(guild_id, voice_id, text_id) { return state; } +async function processUrl(url) { + const res = await fetch(url); + const contentType = res.headers.get("Content-Type"); + + let type = StreamType.Arbitrary; + if (contentType == "video/webm" || contentType == "audio/webm") { + type = StreamType.WebmOpus; + } else if (contentType == "audio/ogg" || contentType == "video/ogg") { + type = StreamType.OggOpus; + } else if (contentType == "audio/opus") { + type = StreamType.Opus; + } + + return { + stream: await res.body(), + type, + }; +} + async function enqueue({ guild_id, voice_id, @@ -249,7 +269,7 @@ async function enqueue({ title = info.title; length = info.duration; thumbnail = info.artwork_url; - media = await playdl.stream(streamUrl); + media = await processUrl(streamUrl); } else if (type == "file") { title = url; let info; @@ -275,7 +295,7 @@ async function enqueue({ } length = info.duration ? Math.floor(info.duration) * 1000 : 0; - media = await playdl.stream(url); + media = await processUrl(url); } if (connection.status && connection.status != AudioPlayerStatus.Idle) {