Finished adding JSDoc for src/utils
This commit is contained in:
parent
2303c89bcf
commit
7b8c44158f
12 changed files with 229 additions and 20 deletions
|
|
@ -22,6 +22,12 @@ const media = require('../../app/channel/media/media.js');
|
|||
const regexUtils = require('../regexUtils.js');
|
||||
const loggerUtils = require('../loggerUtils.js')
|
||||
|
||||
/**
|
||||
* Pulls metadate for a given archive.org item
|
||||
* @param {String} fullID - Full path of the requested upload
|
||||
* @param {String} title - Title to add to media object
|
||||
* @returns {Array} Generated list of media objects from given upload path
|
||||
*/
|
||||
module.exports.fetchMetadata = async function(fullID, title){
|
||||
//Split fullID by first slash
|
||||
const [itemID, requestedPath] = decodeURIComponent(fullID).split(/\/(.*)/);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,12 @@ const validator = require('validator');//No express here, so regular validator i
|
|||
const iaUtil = require('./internetArchiveUtils');
|
||||
const ytdlpUtil = require('./ytdlpUtils');
|
||||
|
||||
/**
|
||||
* Checks a given URL and runs the proper metadata fetching function to create a media object from any supported URL
|
||||
* @param {String} url - URL to yank media against
|
||||
* @param {String} title - Title to apply to yanked media
|
||||
* @returns
|
||||
*/
|
||||
module.exports.yankMedia = async function(url, title){
|
||||
//Get pull type
|
||||
const pullType = await this.getMediaType(url);
|
||||
|
|
@ -50,6 +56,13 @@ module.exports.yankMedia = async function(url, title){
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes raw links on relevant media objects
|
||||
*
|
||||
* Useful for sources like youtube, who only provide expiring raw links
|
||||
* @param {ScheduledMedia} mediaObj - Media Object to refresh
|
||||
* @returns {ScheduledMedia} Refreshed media object
|
||||
*/
|
||||
module.exports.refreshRawLink = async function(mediaObj){
|
||||
switch(mediaObj.type){
|
||||
case 'yt':
|
||||
|
|
@ -76,10 +89,16 @@ module.exports.refreshRawLink = async function(mediaObj){
|
|||
//Return null to tell the calling function there is no refresh required for this media type
|
||||
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.
|
||||
//Some of the regex expressions for certain services have also been improved, such as youtube, and the fore.st-unique archive.org
|
||||
/**
|
||||
* Detects media type by URL
|
||||
*
|
||||
* 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.
|
||||
* Some of the regex expressions for certain services have also been improved, such as youtube, and the fore.st-unique archive.org
|
||||
*
|
||||
* @param {String} url - URL to determine media type of
|
||||
* @returns {Object} containing URL type and clipped ID string
|
||||
*/
|
||||
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))){
|
||||
|
|
|
|||
|
|
@ -29,6 +29,12 @@ const media = require('../../app/channel/media/media.js');
|
|||
const regexUtils = require('../regexUtils.js');
|
||||
const loggerUtils = require('../loggerUtils.js')
|
||||
|
||||
/**
|
||||
* Pulls metadata for a single youtube video via YT-DLP
|
||||
* @param {String} id - Youtube Video ID
|
||||
* @param {String} title - Title to add to the given media object
|
||||
* @returns {Media} Media object containing relevant metadata
|
||||
*/
|
||||
module.exports.fetchYoutubeMetadata = async function(id, title){
|
||||
try{
|
||||
//Try to pull media from youtube id
|
||||
|
|
@ -50,6 +56,12 @@ module.exports.fetchYoutubeMetadata = async function(id, title){
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pulls metadata for a playlist of youtube videos via YT-DLP
|
||||
* @param {String} id - Youtube Playlist ID
|
||||
* @param {String} title - Title to add to the given media objects
|
||||
* @returns {Array} Array of Media objects containing relevant metadata
|
||||
*/
|
||||
module.exports.fetchYoutubePlaylistMetadata = async function(id, title){
|
||||
try{
|
||||
//Try to pull media from youtube id
|
||||
|
|
@ -71,15 +83,23 @@ module.exports.fetchYoutubePlaylistMetadata = async function(id, title){
|
|||
}
|
||||
}
|
||||
|
||||
/* This requires HLS embeds which, in-turn, require daily motion to add us to their CORS exception list
|
||||
* Not gonna happen, so we need to use their API for this, or proxy the video
|
||||
module.exports.fetchDailymotionMetadata = async function(id, title){
|
||||
//Pull media from dailymotion link
|
||||
const media = await fetchVideoMetadata(`https://dailymotion.com/video/${id}`, title, 'dm');
|
||||
|
||||
//Return found media;
|
||||
return media;
|
||||
}
|
||||
}*/
|
||||
|
||||
//Generic single video YTDLP function meant to be used by service-sepecific fetchers which will then be used to fetch video metadata
|
||||
/**
|
||||
* Generic single video YTDLP function meant to be used by service-sepecific fetchers which will then be used to fetch video metadata
|
||||
* @param {String} link - Link to video in question
|
||||
* @param {String} title - Title to add to the given media objects
|
||||
* @param {String} type - Link type to attach to the resulting media object
|
||||
* @returns {Array} Array of Media objects containing relevant metadata
|
||||
*/
|
||||
async function fetchVideoMetadata(link, title, type, format = 'b'){
|
||||
//Create media list
|
||||
const mediaList = [];
|
||||
|
|
@ -110,6 +130,12 @@ async function fetchVideoMetadata(link, title, type, format = 'b'){
|
|||
}*/
|
||||
|
||||
//Wrapper function for YT-DLP NPM package with pre-set cli-flags
|
||||
/**
|
||||
* Basic async YT-DLP Fetch wrapper, ensuring config
|
||||
* @param {String} link - Link to fetch using YT-DLP
|
||||
* @param {String} format - Format string to hand YT-DLP, defaults to 'b'
|
||||
* @returns {Object} Metadata dump from YT-DLP
|
||||
*/
|
||||
async function ytdlpFetch(link, format = 'b'){
|
||||
//return promise from ytdlp
|
||||
return ytdlp(link, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue