added functions to get info on a downloaded (or downloading) file

bug fixed where videos with quotations would not properly stream
pull/11/head
Isaac Grynsztein 6 years ago
parent 31394fa98c
commit d595de5786

@ -194,6 +194,40 @@ function deleteVideoFile(name) {
fs.unlinkSync(jsonPath);
}
function getAudioInfos(fileNames) {
let result = [];
for (let i = 0; i < fileNames.length; i++) {
let fileName = fileNames[i];
let fileLocation = audioFolderPath+fileName+'.mp3.info.json';
if (fs.existsSync(fileLocation)) {
let data = fs.readFileSync(fileLocation);
try {
result.push(JSON.parse(data));
} catch {
console.log(`ERROR: Could not find info for file ${fileName}.mp3`);
}
}
}
return result;
}
function getVideoInfos(fileNames) {
let result = [];
for (let i = 0; i < fileNames.length; i++) {
let fileName = fileNames[i];
let fileLocation = videoFolderPath+fileName+'.info.json';
if (fs.existsSync(fileLocation)) {
let data = fs.readFileSync(fileLocation);
try {
result.push(JSON.parse(data));
} catch {
console.log(`ERROR: Could not find info for file ${fileName}.mp4`);
}
}
}
return result;
}
app.post('/tomp3', function(req, res) {
var url = req.body.url;
var date = Date.now();
@ -490,7 +524,8 @@ app.get('/video/:id', function(req , res){
app.get('/audio/:id', function(req , res){
var head;
const path = "audio/" + req.params.id;
let path = "audio/" + req.params.id;
path = path.replace(/\"/g, '\'');
const stat = fs.statSync(path)
const fileSize = stat.size
const range = req.headers.range
@ -519,7 +554,23 @@ app.get('/audio/:id', function(req , res){
fs.createReadStream(path).pipe(res)
}
});
app.post('/getVideoInfos', function(req, res) {
let fileNames = req.body.fileNames;
let type = req.body.type;
let result = null;
if (type === 'audio') {
result = getAudioInfos(fileNames)
} else if (type === 'video') {
result = getVideoInfos(fileNames);
}
res.send({
result: result,
success: !!result
})
});

Loading…
Cancel
Save