From 9d9aa5672f7d7b998661cfe0823e9f7152b21a12 Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Tue, 6 May 2025 07:48:24 -0400 Subject: [PATCH] Youtube videos technically queable/playable --- src/app/channel/media/queuedMedia.js | 5 +++-- src/utils/loggerUtils.js | 2 +- src/utils/media/yanker.js | 22 ++++++++++++++++++---- www/js/channel/mediaHandler.js | 2 +- www/js/channel/player.js | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/app/channel/media/queuedMedia.js b/src/app/channel/media/queuedMedia.js index 0babd9e..85fc365 100644 --- a/src/app/channel/media/queuedMedia.js +++ b/src/app/channel/media/queuedMedia.js @@ -18,9 +18,9 @@ along with this program. If not, see .*/ 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); } diff --git a/src/utils/loggerUtils.js b/src/utils/loggerUtils.js index 4858618..23aeb96 100644 --- a/src/utils/loggerUtils.js +++ b/src/utils/loggerUtils.js @@ -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."); } } diff --git a/src/utils/media/yanker.js b/src/utils/media/yanker.js index 581448a..ccdf84a 100644 --- a/src/utils/media/yanker.js +++ b/src/utils/media/yanker.js @@ -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 } } \ No newline at end of file diff --git a/www/js/channel/mediaHandler.js b/www/js/channel/mediaHandler.js index aaed2bc..209cd8f 100644 --- a/www/js/channel/mediaHandler.js +++ b/www/js/channel/mediaHandler.js @@ -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; diff --git a/www/js/channel/player.js b/www/js/channel/player.js index 750a45e..dbf1d70 100644 --- a/www/js/channel/player.js +++ b/www/js/channel/player.js @@ -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