Add more commands
This commit is contained in:
@@ -1,14 +1,44 @@
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
/* eslint-disable no-await-in-loop */
|
||||
// const playdl = require('play-dl');
|
||||
// const youtube = require('./youtube');
|
||||
|
||||
const playdl = require('play-dl');
|
||||
// TODO ADD SPOTIFY SUPPORT
|
||||
async function getStream(query) {
|
||||
const youtube = require('./youtube');
|
||||
const musicQueue = require('../musicQueue'); // Import the musicQueue module
|
||||
|
||||
async function getStream(query, guildId) {
|
||||
// Check if the query is a Spotify playlist
|
||||
if (playdl.sp_validate(query) === 'playlist') {
|
||||
let firstTrack = {};
|
||||
// Get the playlist information
|
||||
const playlistInfo = await playdl.spotify(query);
|
||||
|
||||
// Loop through the tracks in the playlist
|
||||
// Get the tracks from the fetched_tracks Map
|
||||
const tracks = playlistInfo.fetched_tracks.get('1');
|
||||
|
||||
// Loop through the tracks in the playlist
|
||||
for (const track of tracks) {
|
||||
// save the first track in the queue
|
||||
if (tracks.indexOf(track) === 0) {
|
||||
firstTrack = await youtube.getStream(`${track.name} ${track.artists[0].name}`);
|
||||
} else {
|
||||
// Get a stream for the track using the youtube module
|
||||
const song = await youtube.getStream(`${track.name} ${track.artists[0].name}`);
|
||||
|
||||
// Add the song to the music queue
|
||||
musicQueue.addToQueue(guildId, song);
|
||||
}
|
||||
}
|
||||
|
||||
// Return null to indicate that a playlist was queued
|
||||
return firstTrack;
|
||||
}
|
||||
|
||||
// Handle single tracks as before
|
||||
const trackInfo = await playdl.spotify(query);
|
||||
|
||||
const searched = await play.search(`${trackInfo.name}`, {
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
const stream = await play.stream(searched[0].url);
|
||||
return stream;
|
||||
return youtube.getStream(`${trackInfo.name} ${trackInfo.artists[0].name}`);
|
||||
}
|
||||
|
||||
module.exports.getStream = getStream;
|
||||
@@ -1,5 +1,8 @@
|
||||
const ytsr = require('ytsr');
|
||||
const playdl = require('play-dl');
|
||||
const ConsolerLogger = require('../utils/logger');
|
||||
|
||||
const logger = new ConsolerLogger();
|
||||
|
||||
async function getStream(query) {
|
||||
try {
|
||||
@@ -35,7 +38,15 @@ async function getStream(query) {
|
||||
: await playdl.video_info(
|
||||
`https://www.youtube.com/watch?v=${videoId}`,
|
||||
);
|
||||
console.log('\x1b[36m', ' Id: ', videoId, 'Alternative search:', usingYtsr);
|
||||
|
||||
logger.info('Search request', { file: 'Youtube.JS',
|
||||
Id: videoId,
|
||||
alternativeSearch: usingYtsr,
|
||||
length: usingYtsr
|
||||
? infoResult.items[0].duration
|
||||
: infoResult.video_details.durationInSec / 60,
|
||||
SearchQuery: query });
|
||||
|
||||
return {
|
||||
title:
|
||||
(usingYtsr
|
||||
@@ -52,7 +63,7 @@ async function getStream(query) {
|
||||
userInput: query,
|
||||
};
|
||||
} catch (error) {
|
||||
console.log('\x1b[31m', error);
|
||||
logger.error(error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user