Halfbroken fixes

This commit is contained in:
Myx
2023-06-28 03:02:41 +02:00
parent 6a001604ab
commit f533e38333
18 changed files with 545 additions and 421 deletions

View File

@@ -1,14 +1,14 @@
const playdl = require("play-dl");
const playdl = require('play-dl');
async function getStream(query) {
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,
};
const songInformation = await playdl.soundcloud(query);
const stream = await playdl.stream_from_info(songInformation, { quality: 2 });
return {
title: songInformation.name,
stream: stream.stream,
duration: songInformation.durationInSec * 1000,
userInput: query,
};
}
module.exports.getStream = getStream;

View File

@@ -1,14 +1,14 @@
const playdl = require('play-dl');
//TODO ADD SPOTIFY SUPPORT
// TODO ADD SPOTIFY SUPPORT
async function getStream(query) {
const trackInfo = await playdl.spotify(query);
const trackInfo = await playdl.spotify(query);
let searched = await play.search(`${trackInfo.name}`, {
limit: 1
})
const searched = await play.search(`${trackInfo.name}`, {
limit: 1,
});
let stream = await play.stream(searched[0].url)
return stream;
const stream = await play.stream(searched[0].url);
return stream;
}
module.exports.getStream = getStream;

View File

@@ -1,59 +1,60 @@
const ytsr = require("ytsr");
const playdl = require("play-dl");
const ytsr = require('ytsr');
const playdl = require('play-dl');
async function getStream(query) {
try {
const regex = /(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([^?&\n]+)/;
const match = query.match(regex);
let videoId;
let usingYtsr = false;
if (match == null) {
let result = await playdl.search(query, { limit: 1 });
videoId = result[0].id;
try {
const regex = /(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([^?&\n]+)/;
const match = query.match(regex);
let videoId;
let usingYtsr = false;
if (match == null) {
const 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",
});
videoId = searchResults.items[0].id;
}
} else {
videoId = match[1];
}
if (videoId == null) {
usingYtsr = true;
const searchResults = await ytsr(query, {
page: 1,
type: 'video',
});
videoId = searchResults.items[0].id;
}
} else {
// use array destructing to get the video id
[, videoId] = match;
}
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) ??
0,
duration:
(usingYtsr
? infoResult.items[0].duration
: (infoResult.video_details.durationInSec * 1000)) ??
0,
stream: streamResult.stream,
type: streamResult.type,
userInput: query,
};
} catch (error) {
console.log("\x1b[31m", error);
return null;
}
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)
?? 0,
duration:
(usingYtsr
? infoResult.items[0].duration
: (infoResult.video_details.durationInSec * 1000))
?? 0,
stream: streamResult.stream,
type: streamResult.type,
userInput: query,
};
} catch (error) {
console.log('\x1b[31m', error);
return null;
}
}
module.exports.getStream = getStream;
module.exports.getStream = getStream;