Add stop functionality, fix duration
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
const playdl = require('play-dl');
|
||||
const playdl = require("play-dl");
|
||||
|
||||
async function getStream(query) {
|
||||
let songInformation = await playdl.soundcloud(query) // Make sure that url is track url only. For playlist, make some logic.
|
||||
let songInformation = await playdl.soundcloud(query);
|
||||
let stream = await playdl.stream_from_info(songInformation, { quality: 2 });
|
||||
return {
|
||||
title: songInformation.name,
|
||||
stream: stream.stream,
|
||||
duration: songInformation.durationInSec / 1000,
|
||||
userInput: query
|
||||
}
|
||||
duration: songInformation.durationInSec * 1000,
|
||||
userInput: query,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.getStream = getStream;
|
||||
@@ -1,14 +1,13 @@
|
||||
const playdl = require('play-dl');
|
||||
|
||||
//TODO ADD SPOTIFY SUPPORT
|
||||
async function getStream(query) {
|
||||
const trackInfo = await playdl.spotify(query);
|
||||
|
||||
let searched = await play.search(`${trackInfo.name}`, {
|
||||
limit: 1
|
||||
}) // This will search the found track on youtube.
|
||||
|
||||
let stream = await play.stream(searched[0].url) // This will create stream from the above search
|
||||
})
|
||||
|
||||
let stream = await play.stream(searched[0].url)
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const ytsr = require('ytsr');
|
||||
const playdl = require('play-dl');
|
||||
const ytsr = require("ytsr");
|
||||
const playdl = require("play-dl");
|
||||
|
||||
async function getStream(query) {
|
||||
try {
|
||||
@@ -7,29 +7,48 @@ async function getStream(query) {
|
||||
const match = query.match(regex);
|
||||
let videoId;
|
||||
let usingYtsr = false;
|
||||
if(match == null) {
|
||||
let result = await playdl.search(query, { limit: 1});
|
||||
if (match == null) {
|
||||
let result = await playdl.search(query, { limit: 1 });
|
||||
videoId = result[0].id;
|
||||
|
||||
if (videoId == null) {
|
||||
usingYtsr = true;
|
||||
const searchResults = await ytsr(query, { page: 1, type: 'video' });
|
||||
const searchResults = await ytsr(query, {
|
||||
page: 1,
|
||||
type: "video",
|
||||
});
|
||||
videoId = searchResults.items[0].id;
|
||||
}
|
||||
} else {
|
||||
videoId = match[1];
|
||||
}
|
||||
|
||||
const streamResult = await playdl.stream(`https://www.youtube.com/watch?v=${videoId}`, { quality: 2 });
|
||||
const infoResult = usingYtsr ? await ytsr(`https://www.youtube.com/watch?v=${videoId}`, { limit: 1}) : await playdl.video_info(`https://www.youtube.com/watch?v=${videoId}`);
|
||||
console.log(infoResult)
|
||||
console.log("\x1b[36m",' Id: ', videoId, 'Alternative search:', usingYtsr)
|
||||
const streamResult = await playdl.stream(
|
||||
`https://www.youtube.com/watch?v=${videoId}`,
|
||||
{ quality: 2 }
|
||||
);
|
||||
const infoResult = usingYtsr
|
||||
? await ytsr(`https://www.youtube.com/watch?v=${videoId}`, {
|
||||
limit: 1,
|
||||
})
|
||||
: await playdl.video_info(
|
||||
`https://www.youtube.com/watch?v=${videoId}`
|
||||
);
|
||||
console.log("\x1b[36m"," Id: ", videoId, "Alternative search:", usingYtsr);
|
||||
return {
|
||||
title: (usingYtsr ? infoResult.items[0].title : infoResult.video_details.title) ?? 'Unknown, error fetching title.',
|
||||
duration: (usingYtsr ? infoResult.items[0].duration : infoResult.video_details.durationInSec) ?? 'Unknown, error fetching duration.',
|
||||
title:
|
||||
(usingYtsr
|
||||
? infoResult.items[0].title
|
||||
: infoResult.video_details.title) ??
|
||||
0,
|
||||
duration:
|
||||
(usingYtsr
|
||||
? infoResult.items[0].duration
|
||||
: (infoResult.video_details.durationInSec * 1000)) ??
|
||||
0,
|
||||
stream: streamResult.stream,
|
||||
type: streamResult.type,
|
||||
userInput: query
|
||||
userInput: query,
|
||||
};
|
||||
} catch (error) {
|
||||
console.log("\x1b[31m", error);
|
||||
@@ -37,4 +56,4 @@ async function getStream(query) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.getStream = getStream;
|
||||
module.exports.getStream = getStream;
|
||||
|
||||
Reference in New Issue
Block a user