Lightweight node app to use in place of plex to self host your video and movie collections. Running on just under 50MB of ram this is ideal for people looking to host videos on minimal hardware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

125 lines
4.0 KiB

const configManager = require('./configManager');
const recursive = require('./recursiveTraversal');
const filepreview = require('filepreview');
const fs = require('fs');
var privateVideos = null;
var publicVideos = null;
module.exports =
{
indexVideos: function(rootDir, videos, templateKey)
{
return new Promise(function(resolve, reject)
{
recursive(rootDir, function (err, files)
{
console.log(files);
files.forEach(file =>
{
var splitArray = file.split('/');
var name = splitArray[splitArray.length -1];
const icon = './icon/' + templateKey + '/' + name + ".png";
if (!fs.existsSync(icon))
{
var options = {
width: 200,
quality: 50
};
filepreview.generate(file, icon, options,function(error) {
if (error) {
return console.log(error);
}
console.log('File preview is located ' + icon);
});
}
videos.push({name: file.replace(rootDir, '')});
});
resolve();
});
}).catch(function(error)
{
console.log(error);
})
},
getVideosForTemplate: function(templateContext, templateKey)
{
return new Promise(function(resolve, reject)
{
var videos, rootDir;
if(templateKey === "public")
{
videos = publicVideos;
rootDir = configManager.getPublicDirectory();
}
else
{
videos = privateVideos;
rootDir = configManager.getRootDirectory();
}
if(videos === null)
{
videos = [];
module.exports.indexVideos(rootDir, videos, templateKey)
.then(function()
{
templateContext[templateKey] = videos;
if(templateKey === "public")
publicVideos = videos;
else
privateVideos = videos;
resolve();
})
}
else
{
templateContext[templateKey] = videos;
resolve();
}
})
},
isPublicVideo: function(videoName)
{
if(publicVideos == null)
{
publicVideos = [];
rootDir = configManager.getPublicDirectory();
module.exports.indexVideos(rootDir, publicVideos, "public").then(function()
{
for(var i = 0; i < publicVideos.length; i++)
{
const splitArray = publicVideos[i].name.split('/');
const name = splitArray[splitArray.length -1];
if(name === videoName)
{
return true;
}
}
return false;
});
}
else
{
for(var i = 0; i < publicVideos.length; i++)
{
const splitArray = publicVideos[i].name.split('/');
const name = splitArray[splitArray.length -1];
if(name === videoName)
{
return true;
}
}
return false;
}
}
};