Fixed issues with IA utils, continued work on playlist mgmt UI
This commit is contained in:
parent
3da88aea2a
commit
f4db10fbc3
7 changed files with 142 additions and 56 deletions
|
|
@ -46,6 +46,7 @@ playlistMediaProperties.pre('save', async function (next){
|
|||
});
|
||||
|
||||
//methods
|
||||
//Rehydrate to a full phat media object
|
||||
playlistMediaProperties.methods.rehydrate = function(){
|
||||
//Return item as a full phat, standard media object
|
||||
return new media(
|
||||
|
|
@ -58,4 +59,14 @@ playlistMediaProperties.methods.rehydrate = function(){
|
|||
);
|
||||
}
|
||||
|
||||
//Dehydrate to minified flat network-friendly object
|
||||
playlistMediaProperties.methods.dehydrate = function(){
|
||||
return {
|
||||
title: this.title,
|
||||
url: this.url,
|
||||
duration: this.duration,
|
||||
uuid: this.uuid.toString()
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = mediaSchema.discriminator('saved', playlistMediaProperties);
|
||||
|
|
@ -41,11 +41,7 @@ playlistSchema.methods.dehydrate = function(){
|
|||
|
||||
//Fill media array
|
||||
for(let media of this.media){
|
||||
mediaArray.push({
|
||||
title: media.title,
|
||||
url: media.url,
|
||||
duration: media.duration
|
||||
});
|
||||
mediaArray.push(media.dehydrate());
|
||||
}
|
||||
|
||||
//return dehydrated playlist
|
||||
|
|
|
|||
|
|
@ -16,11 +16,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
|
||||
//Node Imports
|
||||
const url = require("node:url");
|
||||
const validator = require('validator');
|
||||
|
||||
//Local Imports
|
||||
const regexUtils = require('../regexUtils');
|
||||
const media = require('../../app/channel/media/media');
|
||||
|
||||
module.exports.fetchMetadata = async function(link){
|
||||
module.exports.fetchMetadata = async function(link, title){
|
||||
//Parse link
|
||||
const parsedLink = new url.URL(link);
|
||||
//Split link path
|
||||
|
|
@ -31,6 +33,10 @@ module.exports.fetchMetadata = async function(link){
|
|||
splitPath.splice(0,3)
|
||||
//Join remaining link path back together to get requested file path within the given archive.org upload
|
||||
const requestedPath = decodeURIComponent(splitPath.join('/'));
|
||||
//Create empty list to hold media objects
|
||||
const mediaList = [];
|
||||
//Create empty variable to hold return data object
|
||||
let data;
|
||||
|
||||
//Create metadata link from itemID
|
||||
const metadataLink = `https://archive.org/metadata/${itemID}`;
|
||||
|
|
@ -55,23 +61,48 @@ module.exports.fetchMetadata = async function(link){
|
|||
//Filter out any in-compatible files
|
||||
const compatibleFiles = rawMetadata.files.filter(compatibilityFilter);
|
||||
|
||||
|
||||
//If we're requesting an empty path
|
||||
if(requestedPath == ''){
|
||||
//Return item metadata and compatible files
|
||||
return {
|
||||
data = {
|
||||
files: compatibleFiles,
|
||||
metadata: rawMetadata.metadata
|
||||
}
|
||||
//Other wise
|
||||
}else{
|
||||
//Return item metadata and matching compatible files
|
||||
return {
|
||||
data = {
|
||||
//Filter files out that don't match requested path and return remaining list
|
||||
files: compatibleFiles.filter(pathFilter),
|
||||
metadata: rawMetadata.metadata
|
||||
}
|
||||
}
|
||||
|
||||
//for every compatible and relevant file returned from IA
|
||||
for(let file of data.files){
|
||||
//Split file path by directories
|
||||
const path = file.name.split('/');
|
||||
|
||||
//pull filename from path and escape in-case someone put something nasty in there
|
||||
const name = validator.escape(validator.trim(path[path.length - 1]));
|
||||
|
||||
//Construct link from pulled info
|
||||
const link = `https://archive.org/download/${data.metadata.identifier}/${file.name}`;
|
||||
|
||||
//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, link, 'ia', Number(file.length)));
|
||||
}else{
|
||||
//Create new media object from file info
|
||||
mediaList.push(new media(title, name, link, link, 'ia', Number(file.length)));
|
||||
}
|
||||
}
|
||||
|
||||
//return media object list
|
||||
return mediaList;
|
||||
|
||||
function compatibilityFilter(file){
|
||||
//return true for all files that match for web-safe formats
|
||||
return file.format == "h.264 IA" || file.format == "h.264" || file.format == "Ogg Video" || file.format.match("MPEG4");
|
||||
|
|
|
|||
|
|
@ -19,43 +19,19 @@ const validator = require('validator');//No express here, so regular validator i
|
|||
|
||||
//local import
|
||||
const iaUtil = require('./internetArchiveUtils');
|
||||
const media = require('../../app/channel/media/media');
|
||||
|
||||
module.exports.yankMedia = async function(url, title){
|
||||
//Get pull type
|
||||
const pullType = await this.getMediaType(url);
|
||||
|
||||
if(pullType == 'ia'){
|
||||
//Create empty list to hold media objects
|
||||
const mediaList = [];
|
||||
//Pull metadata from IA
|
||||
const mediaInfo = await iaUtil.fetchMetadata(url);
|
||||
|
||||
//for every compatible and relevant file returned from IA
|
||||
for(let file of mediaInfo.files){
|
||||
//Split file path by directories
|
||||
const path = file.name.split('/');
|
||||
|
||||
//pull filename from path
|
||||
const name = path[path.length - 1];
|
||||
|
||||
//Construct link from pulled info
|
||||
const link = `https://archive.org/download/${mediaInfo.metadata.identifier}/${file.name}`;
|
||||
|
||||
//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, link, 'ia', Number(file.length)));
|
||||
}else{
|
||||
//Create new media object from file info
|
||||
mediaList.push(new media(title, name, link, link, 'ia', Number(file.length)));
|
||||
}
|
||||
}
|
||||
|
||||
//return media object list
|
||||
return mediaList;
|
||||
}else{
|
||||
//return null to signify a bad url
|
||||
return null;
|
||||
//Check pull type
|
||||
switch(pullType){
|
||||
case "ia":
|
||||
//return media object list from IA module
|
||||
return await iaUtil.fetchMetadata(url, title);
|
||||
default:
|
||||
//return null to signify a bad url
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +45,6 @@ module.exports.getMediaType = async function(url){
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
//If we have link to a resource from archive.org
|
||||
if(url.match(/^https\:\/\/archive.org\//g)){
|
||||
//return internet archive code
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue