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

Add cookies support #1048

Merged
merged 1 commit into from
Jul 22, 2024
Merged
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
98 changes: 91 additions & 7 deletions actions/play_music_MOD.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@
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}`;
Expand Down Expand Up @@ -57,16 +69,80 @@
<store-in-variable dropdownLabel="Store In" selectId="storage" variableContainerId="varNameContainer2" variableInputId="varName2"></store-in-variable>
</div>

<br><br><br>
<br><br><br>
<dbm-checkbox style="padding-top: 8px;" id="useCookies" label="Use Cookies (Optional)"></dbm-checkbox>
<div style="padding-top: 8px; display: none;" id="cookiesSection">
<span class="dbminputlabel">Cookies</span><br>
<textarea id="cookies" rows="9" name="cookiesarea" style="white-space: nowrap; resize: none;"></textarea>
<br>
<p>
<u><b><span style="color: white;">How to get cookies:</span></b></u><br>
&#x2022; Install <span class="wrexlink" id="link" data-url="https://www.editthiscookie.com/">EditThisCookie</span> extension for your browser.<br>
&#x2022; Go to YouTube.<br>
&#x2022; Log in to your account. (You should use a new account for this purpose)<br>
&#x2022; Click on the extension icon and click "Export" icon.<br>
&#x2022; Your cookie will be added to your clipboard and paste it into cookies area above.
</p>
<div style="border-top: 3px solid #c7c8c8;"></div>
</div>
<p style="padding-top: 14px;">
<u><b><span style="color: white;">NOTE:</span></b></u><br>
Supports both videos and playlists.<br>
This action supports both videos and playlists.<br>
</p>
</div>

<style>
span.wrexlink {
color: #99b3ff;
text-decoration:underline;
cursor:pointer;
}
span.wrexlink:hover {
color:#4676b9;
}
</style>
`;
},

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];
Expand All @@ -82,6 +158,12 @@
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();
Expand All @@ -102,10 +184,10 @@

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);
Expand All @@ -122,7 +204,7 @@
} else {
let songInfo;
try {
songInfo = await ytdl.getInfo(query);
songInfo = await ytdl.getInfo(query, { agent });
} catch (error) {
console.log(error);
return this.callNextAction(cache);
Expand Down Expand Up @@ -177,6 +259,7 @@
dlChunkSize: 1024 * 1024,
quality: 'lowestaudio',
bitrate: 128,
agent,
});
const resource = createAudioResource(stream, { inlineVolume: true });
resource.volume.setVolume(volume / 100);
Expand Down Expand Up @@ -209,6 +292,7 @@
dlChunkSize: 1024 * 1024,
quality: 'lowestaudio',
bitrate: 128,
agent,
});
const nextResource = createAudioResource(nextStream, { inlineVolume: true });
nextResource.volume.setVolume(volume / 100);
Expand All @@ -216,7 +300,7 @@
});

if (leaveOnEmpty) {
Bot.bot.on('voiceStateUpdate', (oldState, newState) => {

Check warning on line 303 in actions/play_music_MOD.js

View workflow job for this annotation

GitHub Actions / ESLint

'oldState' is defined but never used

Check warning on line 303 in actions/play_music_MOD.js

View workflow job for this annotation

GitHub Actions / ESLint

'newState' is defined but never used
const botChannel = connection.joinConfig.channelId;
if (!botChannel) return;

Expand Down
Loading