Refactored media link parsing, started work on YT-DLP integration.

This commit is contained in:
rainbow napkin 2025-05-06 06:32:16 -04:00
parent 67c687a8d3
commit 0ce0685fd5
7 changed files with 98 additions and 30 deletions

View file

@ -19,37 +19,45 @@ const validator = require('validator');//No express here, so regular validator i
//local import
const iaUtil = require('./internetArchiveUtils');
const ytdlpUtil = require('./ytdlpUtils');
module.exports.yankMedia = async function(url, title){
//Get pull type
const pullType = await this.getMediaType(url);
//Check pull type
switch(pullType){
switch(pullType.type){
case "ia":
//return media object list from IA module
return await iaUtil.fetchMetadata(url, title);
return await iaUtil.fetchMetadata(pullType.id, title);
default:
//return null to signify a bad url
return null;
}
}
//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
module.exports.getMediaType = async function(url){
//Encode URI in-case we where handed something a little too humie friendly
url = encodeURI(url);
//Check if we have a valid url
if(!validator.isURL(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 null;
}
return {
type: null,
id: url
}
//If we have link to a resource from archive.org
if(url.match(/^https\:\/\/archive.org\//g)){
}else if(match = url.match(/archive\.org\/(?:details|download)\/([a-zA-Z0-9\/._-\s\%]+)/)){
//return internet archive code
return "ia";
return {
type: "ia",
id: match[1]
}
}
return null;
//If we fell through all of our media types without a match
return{
type: null,
id: url
}
}