Youtube videos technically queable/playable
This commit is contained in:
parent
0ce0685fd5
commit
9d9aa5672f
|
|
@ -18,9 +18,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
const media = require('./media');
|
const media = require('./media');
|
||||||
|
|
||||||
module.exports = class extends 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
|
//Call derived constructor
|
||||||
super(title, fileName, url, id, type, duration);
|
super(title, fileName, url, id, type, duration, rawLink);
|
||||||
//Set media start time
|
//Set media start time
|
||||||
this.startTime = startTime;
|
this.startTime = startTime;
|
||||||
//Set the media start time stamp
|
//Set the media start time stamp
|
||||||
|
|
@ -50,6 +50,7 @@ module.exports = class extends media{
|
||||||
media.id,
|
media.id,
|
||||||
media.type,
|
media.type,
|
||||||
media.duration,
|
media.duration,
|
||||||
|
media.rawLink,
|
||||||
startTime,
|
startTime,
|
||||||
startTimeStamp);
|
startTimeStamp);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ module.exports.socketExceptionHandler = function(socket, err){
|
||||||
module.exports.localExceptionHandler(err);
|
module.exports.localExceptionHandler(err);
|
||||||
|
|
||||||
//if not yell at the browser for fucking up
|
//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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ module.exports.yankMedia = async function(url, title){
|
||||||
case "ia":
|
case "ia":
|
||||||
//return media object list from IA module
|
//return media object list from IA module
|
||||||
return await iaUtil.fetchMetadata(pullType.id, title);
|
return await iaUtil.fetchMetadata(pullType.id, title);
|
||||||
|
case "yt":
|
||||||
|
return await ytdlpUtil.fetchYoutubeVideoMetadata(pullType.id, title);
|
||||||
default:
|
default:
|
||||||
//return null to signify a bad url
|
//return null to signify a bad url
|
||||||
return null;
|
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'
|
//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){
|
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
|
//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(!validator.isURL(encodeURI(url))){
|
||||||
//If not toss the fucker out
|
//If not toss the fucker out
|
||||||
return {
|
return {
|
||||||
type: null,
|
type: null,
|
||||||
id: url
|
id: null
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//If we have link to a resource from archive.org
|
//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 internet archive code
|
||||||
return {
|
return {
|
||||||
type: "ia",
|
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
|
//If we fell through all of our media types without a match
|
||||||
return{
|
return{
|
||||||
type: null,
|
type: null,
|
||||||
id: url
|
id: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -265,7 +265,7 @@ class rawFileHandler extends rawFileBase{
|
||||||
|
|
||||||
start(){
|
start(){
|
||||||
//Set video
|
//Set video
|
||||||
this.video.src = this.nowPlaying.id;
|
this.video.src = this.nowPlaying.rawLink;
|
||||||
|
|
||||||
//Set video volume
|
//Set video volume
|
||||||
this.video.volume = this.player.volume;
|
this.video.volume = this.player.volume;
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ class player{
|
||||||
//Otherwise
|
//Otherwise
|
||||||
}else{
|
}else{
|
||||||
//If we have a raw-file compatible source
|
//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
|
//Create a new raw file handler for it
|
||||||
this.mediaHandler = new rawFileHandler(client, this, data.media);
|
this.mediaHandler = new rawFileHandler(client, this, data.media);
|
||||||
//Sync to time stamp
|
//Sync to time stamp
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue