diff --git a/src/app/channel/media/media.js b/src/app/channel/media/media.js index a072e6e..609f1bf 100644 --- a/src/app/channel/media/media.js +++ b/src/app/channel/media/media.js @@ -26,9 +26,9 @@ class media{ * @param {String} id - Video ID from source (IE: youtube watch code/archive.org file path) * @param {String} type - Original video source * @param {Number} duration - Length of media in seconds - * @param {String} rawLink - URL to raw file copy of media, not applicable to all sources + * @param {String} rawLink - URLs to raw file copies of media, not applicable to all sources, not saved to the DB */ - constructor(title, fileName, url, id, type, duration, rawLink = url){ + constructor(title, fileName, url, id, type, duration, rawLink){ /** * Chosen title of media */ @@ -59,10 +59,18 @@ class media{ */ this.duration = duration; - /** - * URL to raw file copy of media, not applicable to all sources - */ - this.rawLink = rawLink; + if(rawLink == null){ + /** + * URL to raw file copy of media, not applicable to all sources + */ + this.rawLink = { + audio: [], + video: [], + combo: [['default',url]] + }; + }else{ + this.rawLink = rawLink; + } } } diff --git a/src/utils/media/yanker.js b/src/utils/media/yanker.js index 8072712..c5109ab 100644 --- a/src/utils/media/yanker.js +++ b/src/utils/media/yanker.js @@ -67,6 +67,8 @@ module.exports.yankMedia = async function(url, title){ module.exports.refreshRawLink = async function(mediaObj){ switch(mediaObj.type){ case 'yt': + console.log("lolnope"); + /* We're skipping this one for now... //Scrape expiration from query strings const expires = mediaObj.rawLink.match(/expire=([0-9]+)/); //Went with regex for speed, but I figure I'd keep this around in case we want the accuracy of a battle-tested implementation @@ -85,6 +87,7 @@ module.exports.refreshRawLink = async function(mediaObj){ //return media object return mediaObj; + */ } //Return null to tell the calling function there is no refresh required for this media type diff --git a/src/utils/media/ytdlpUtils.js b/src/utils/media/ytdlpUtils.js index 075189a..e6bfcd6 100644 --- a/src/utils/media/ytdlpUtils.js +++ b/src/utils/media/ytdlpUtils.js @@ -100,7 +100,7 @@ module.exports.fetchDailymotionMetadata = async function(id, title){ * @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'){ +async function fetchVideoMetadata(link, title, type, format = 'ba,bv'){ //Create media list const mediaList = []; @@ -109,16 +109,40 @@ async function fetchVideoMetadata(link, title, type, format = 'b'){ //Pull data from rawMetadata, sanatizing title to prevent XSS const name = validator.escape(validator.trim(rawMetadata.title)); - const rawLink = rawMetadata.requested_downloads[0].url; + + //Create new raw link object (should we make a class? Probably over kill for a fucking method-less hashtable) + const rawLinks = { + audio: [], + video: [], + combo: [] + } + + //for each item + for(const link of rawMetadata.requested_downloads){ + //if there isn't video included + if(link.vcodec == 'none'){ + //Add the link under the format within the audio map + rawLinks.audio.push([link.format_note, link.url]); + //if there isn't audio included + }else if(link.acodec == 'none'){ + //Add the link under the format within the video map + rawLinks.video.push([link.format_note, link.url]); + //otherwise, it includes audio and video + }else{ + //Add the link under the format within the combo map + rawLinks.combo.push([link.format_note, link.url]); + } + } + const id = rawMetadata.id; //if we where handed a null title if(title == null || title == ''){ //Create new media object from file info substituting filename for title - mediaList.push(new media(name, name, link, id, type, Number(rawMetadata.duration), rawLink)); + mediaList.push(new media(name, name, link, id, type, Number(rawMetadata.duration), rawLinks)); }else{ //Create new media object from file info - mediaList.push(new media(title, name, link, id, type, Number(rawMetadata.duration), rawLink)); + mediaList.push(new media(title, name, link, id, type, Number(rawMetadata.duration), rawLinks)); } //Return list of media @@ -136,10 +160,10 @@ async function fetchVideoMetadata(link, title, type, format = 'b'){ * @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'){ +async function ytdlpFetch(link, format = 'ba,ogg'){ //return promise from ytdlp return ytdlp(link, { + format, dumpSingleJson: true, - format }); } \ No newline at end of file