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
|
|
@ -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