Youtube videos technically queable/playable

This commit is contained in:
rainbow napkin 2025-05-06 07:48:24 -04:00
parent 0ce0685fd5
commit 9d9aa5672f
5 changed files with 24 additions and 9 deletions

View file

@ -18,9 +18,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
const media = require('./media');
module.exports = class extends media{
constructor(title, fileName, url, id, type, duration, startTime, startTimeStamp, earlyEnd, uuid){
constructor(title, fileName, url, id, type, duration, rawLink, startTime, startTimeStamp, earlyEnd, uuid){
//Call derived constructor
super(title, fileName, url, id, type, duration);
super(title, fileName, url, id, type, duration, rawLink);
//Set media start time
this.startTime = startTime;
//Set the media start time stamp
@ -50,6 +50,7 @@ module.exports = class extends media{
media.id,
media.type,
media.duration,
media.rawLink,
startTime,
startTimeStamp);
}

View file

@ -74,7 +74,7 @@ module.exports.socketExceptionHandler = function(socket, err){
module.exports.localExceptionHandler(err);
//if not yell at the browser for fucking up
return module.exports.socketErrorHandler(socket, "Caught Exception", "Caught Exception");
return module.exports.socketErrorHandler(socket, "Server Error!", "An unexpected server crash was just prevented. You should probably report this to an admin.");
}
}

View file

@ -30,6 +30,8 @@ module.exports.yankMedia = async function(url, title){
case "ia":
//return media object list from IA module
return await iaUtil.fetchMetadata(pullType.id, title);
case "yt":
return await ytdlpUtil.fetchYoutubeVideoMetadata(pullType.id, title);
default:
//return null to signify a bad url
return null;
@ -37,17 +39,20 @@ module.exports.yankMedia = async function(url, title){
}
//I'd be lying if this didn't take at least some inspiration/regex patterns from extractQueryParam() in cytube/forest's browser-side 'util.js'
//Still this has some improvements like url pre-checks and the fact that it's handled serverside, recuing possibility of bad requests
//Still this has some improvements like url pre-checks and the fact that it's handled serverside, recuing possibility of bad requests.
//Some of the regex expressions for certain services have also been improved, such as youtube, and the fore.st-unique archive.org
module.exports.getMediaType = async function(url){
//Check if we have a valid url, encode it on the fly in case it's too humie-friendly
if(!validator.isURL(encodeURI(url))){
//If not toss the fucker out
return {
type: null,
id: url
id: null
}
}
//If we have link to a resource from archive.org
}else if(match = url.match(/archive\.org\/(?:details|download)\/([a-zA-Z0-9\/._-\s\%]+)/)){
if(match = url.match(/archive\.org\/(?:details|download)\/([a-zA-Z0-9\/._-\s\%]+)/)){
//return internet archive code
return {
type: "ia",
@ -55,9 +60,18 @@ module.exports.getMediaType = async function(url){
}
}
//If we have a match to a youtube video
if((match = url.match(/youtube\.com\/watch\?v=([a-zA-Z0-9_-]{11})/)) || (match = url.match(/youtu\.be\/([a-zA-Z0-9_-]{11})/))){
//return youtube video id
return {
type: "yt",
id: match[1]
}
}
//If we fell through all of our media types without a match
return{
type: null,
id: url
id: null
}
}

View file

@ -265,7 +265,7 @@ class rawFileHandler extends rawFileBase{
start(){
//Set video
this.video.src = this.nowPlaying.id;
this.video.src = this.nowPlaying.rawLink;
//Set video volume
this.video.volume = this.player.volume;

View file

@ -87,7 +87,7 @@ class player{
//Otherwise
}else{
//If we have a raw-file compatible source
if(data.media.type == 'ia' || data.media.type == 'raw'){
if(data.media.type == 'ia' || data.media.type == 'raw' || data.media.type == 'yt'){
//Create a new raw file handler for it
this.mediaHandler = new rawFileHandler(client, this, data.media);
//Sync to time stamp