Skip to content

Commit

Permalink
Updates!
Browse files Browse the repository at this point in the history
  • Loading branch information
jantje19 committed Nov 28, 2017
1 parent 78f2a00 commit 8fa797d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
14 changes: 7 additions & 7 deletions fileHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = {
fs.readdir(path, (err, files) => {
if (err) reject(err);
else {
const addToVidArr = (path, fileName, ctime) => {
const addToVidArr = (path, fileName, mtime) => {
const getFolderFromPath = path => {
return path.replace(/\\/g, '/').split('/').filter(val => {return val.trim().length > 0}).pop();
}
Expand All @@ -64,9 +64,9 @@ module.exports = {
folderName = 'Root';

if (folderName in videosObj)
videosObj[folderName].push({path: path, fileName: fileName, lastChanged: ctime});
videosObj[folderName].push({path: path, fileName: fileName, lastChanged: mtime});
else
videosObj[folderName] = [{path: path, fileName: fileName, lastChanged: ctime}];
videosObj[folderName] = [{path: path, fileName: fileName, lastChanged: mtime}];
}

// Loop through all the files
Expand All @@ -75,13 +75,13 @@ module.exports = {
const fileExtention = utils.getFileExtention(object.toLowerCase());

fs.stat(path + object, (err, stats) => {
const ctime = new Date(stats.ctime.toString());
const mtime = new Date(stats.mtime.toString());

// Check if the file has a file extension that is in the arrays in index.js or that it is a playlist
// If it is a file just execute this function again
if (audioFileExtensions.includes(fileExtention)) songsArr.push({path: path, fileName: object, lastChanged: ctime});
else if (videoFileExtensions.includes(fileExtention)) addToVidArr(path, object, ctime);
else if (fileExtention == '.m3u') playlistsArr.push({path: path, fileName: object, lastChanged: ctime});
if (audioFileExtensions.includes(fileExtention)) songsArr.push({path: path, fileName: object, lastChanged: mtime});
else if (videoFileExtensions.includes(fileExtention)) addToVidArr(path, object, mtime);
else if (fileExtention == '.m3u') playlistsArr.push({path: path, fileName: object, lastChanged: mtime});
else if (!fileExtention && fs.lstatSync(path + object).isDirectory()) handleFolders(path + object + '/', utils);
else if (fileExtention && !silent) console.wrn('File extention not supported', object);
else if (fileExtention && silent);
Expand Down
37 changes: 37 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,43 @@ module.exports = {
} else response.send({success: false, error: 'No valid video id', info: 'The video id supplied cannot be from a youtube video'});
});

app.get('/cutFile*', (request, response) => {
const url = querystring.unescape(request.url);
const params = querystring.parse(URLModule.parse(url).query);

if ('filename' in params && ('start' in params || 'end' in params)) {
fileHandler.getJSON(fs, os, utils, settings.audioFileExtensions.val, settings.videoFileExtensions.val).then(json => {
const index = json.audio.songs.map(val => {
return val.fileName;
}).indexOf(params.filename);

if (index > -1) {
const file = json.audio.songs[index];
const ffmpeg = require('fluent-ffmpeg');
const ffmpegObj = ffmpeg(file.path + file.fileName);

if ('end' in params) ffmpegObj.setDuration(params.end);
if ('start' in params) ffmpegObj.setStartTime(params.start);

ffmpegObj.output(file.path + file.fileName);
ffmpegObj.on('end', err => {
if (err)
response.send({success: false, error: JSON.parse(err)});
else
response.send({success: true});
});

ffmpegObj.on('error', err => {
console.log("FFMPEG Error", err);
response.send({success: false, error: JSON.parse(err)});
});

ffmpegObj.run();
} else response.send({success: false, error: "File not found"});
});
} else response.send({success: false, error: "Parameters missing"});
});

app.post('/ytdl*', (request, response) => {
let body = '';

Expand Down

0 comments on commit 8fa797d

Please sign in to comment.