From ffa4855e7974ba08f81bc75d620ba01685a93f53 Mon Sep 17 00:00:00 2001 From: GoodOne Date: Sun, 21 Jul 2024 21:26:40 +0300 Subject: [PATCH] Add cookies support --- actions/play_music_MOD.js | 98 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 91 insertions(+), 7 deletions(-) diff --git a/actions/play_music_MOD.js b/actions/play_music_MOD.js index 6b239ab7..e228252a 100644 --- a/actions/play_music_MOD.js +++ b/actions/play_music_MOD.js @@ -8,7 +8,19 @@ module.exports = { authorUrl: 'https://github.com/dbm-network/mods', downloadURL: 'https://github.com/dbm-network/mods/blob/master/actions/play_music_MOD.js', }, - fields: ['query', 'voiceChannel', 'varName', 'storage', 'varName2', 'type', 'volume', 'leaveOnEmpty', 'leaveOnEnd'], + fields: [ + 'query', + 'voiceChannel', + 'varName', + 'storage', + 'varName2', + 'type', + 'volume', + 'leaveOnEmpty', + 'leaveOnEnd', + 'useCookies', + 'cookies', + ], subtitle(data) { return `${data.query}`; @@ -57,16 +69,80 @@ module.exports = { -


+


+ + +

NOTE:
- Supports both videos and playlists.
+ This action supports both videos and playlists.

+ + `; }, - init() {}, + init() { + const { document } = this; + + const cookiesCheckbox = document.getElementById('useCookies'); + const checkboxId2 = document.getElementById('checkboxId2'); + const cookiesSection = document.getElementById('cookiesSection'); + + const checkCookiesCheckbox = (checkbox) => { + if (checkbox.checked) { + cookiesSection.style.display = 'block'; + } else { + cookiesSection.style.display = 'none'; + } + }; + + checkCookiesCheckbox(checkboxId2); + + cookiesCheckbox.addEventListener('change', (event) => { + checkCookiesCheckbox(event.target); + }); + + const specificSpan = document.getElementById('link'); + + if (specificSpan) { + const url = specificSpan.getAttribute('data-url'); + if (url) { + specificSpan.setAttribute('title', url); + specificSpan.addEventListener('click', (e) => { + e.stopImmediatePropagation(); + console.log(`Launching URL: [${url}] in your default browser.`); + try { + require('child_process').execSync(`start ${url}`); + } catch (err) { + console.error('Error launching URL:', err); + } + }); + } + } + }, async action(cache) { const data = cache.actions[cache.index]; @@ -82,6 +158,12 @@ module.exports = { AudioPlayerStatus, VoiceConnectionStatus, } = require('@discordjs/voice'); + + let agent; + if (data.useCookies) { + const cookiesarray = JSON.parse(this.evalMessage(data.cookies, cache)); + agent = ytdl.createAgent(cookiesarray); + } const voiceChannel = await this.getVoiceChannelFromData(data.voiceChannel, data.varName, cache); if (!Bot.bot.queue) Bot.bot.queue = new Map(); @@ -102,10 +184,10 @@ module.exports = { let songs = []; - if (ytpl.validateID(query)) { + if (ytpl.validateID(query, { agent })) { let playlist; try { - playlist = await ytpl(query); + playlist = await ytpl(query, { agent }); } catch (error) { console.log(error); return this.callNextAction(cache); @@ -122,7 +204,7 @@ module.exports = { } else { let songInfo; try { - songInfo = await ytdl.getInfo(query); + songInfo = await ytdl.getInfo(query, { agent }); } catch (error) { console.log(error); return this.callNextAction(cache); @@ -177,6 +259,7 @@ module.exports = { dlChunkSize: 1024 * 1024, quality: 'lowestaudio', bitrate: 128, + agent, }); const resource = createAudioResource(stream, { inlineVolume: true }); resource.volume.setVolume(volume / 100); @@ -209,6 +292,7 @@ module.exports = { dlChunkSize: 1024 * 1024, quality: 'lowestaudio', bitrate: 128, + agent, }); const nextResource = createAudioResource(nextStream, { inlineVolume: true }); nextResource.volume.setVolume(volume / 100);