Take random announcement from array and accept webm

This commit is contained in:
loicbersier 2019-12-18 19:30:30 +01:00
parent cc99673081
commit 7a8fd2e380

View file

@ -8,12 +8,16 @@ let viewCounter = 0;
let files = []; let files = [];
let day; let day;
let month; let month;
let announcement = 'Twitter download seems to work fine now!'; let announcementArray = ['Twitter download seems to work fine now!', 'u lookin hot today vro', 'I am not responsible for what you download', 'If you want to support me you can donate through my paypal at the bottom of the page', 'Did you know this website is open source?', 'Did you know this website can download from other website than youtube?']
let announcement
let title = `le epic downloader v${pJson.version}`; let title = `le epic downloader v${pJson.version}`;
class DownloadController { class DownloadController {
async index ({ view, response }) { async index ({ view, response }) {
// Get random announcement
announcement = announcementArray[Math.floor(Math.random() * announcementArray.length)];
// Get date for some event // Get date for some event
let today = new Date(); let today = new Date();
day = today.getDay(); day = today.getDay();
@ -29,7 +33,7 @@ class DownloadController {
} }
// get the 5 most recent files // get the 5 most recent files
file = file.sort(function(a, b) { file = file.sort(function(a, b) {
if (((a || b).endsWith('.mp4') || (a || b).endsWith('.mp3') || (a || b).endsWith('.flac')) && !(a || b).startsWith('HIDE')) { if (((a || b).endsWith('.mp4') || (a || b).endsWith('.webm') || (a || b).endsWith('.mp3') || (a || b).endsWith('.flac')) && !(a || b).startsWith('HIDE')) {
let time1 = fs.statSync(`./public/uploads/${b}`).ctime; let time1 = fs.statSync(`./public/uploads/${b}`).ctime;
let time2 = fs.statSync(`./public/uploads/${a}`).ctime; let time2 = fs.statSync(`./public/uploads/${a}`).ctime;
if (time1 < time2) return -1; if (time1 < time2) return -1;
@ -40,9 +44,10 @@ class DownloadController {
file.forEach((file) => { file.forEach((file) => {
// If mp4 and is not to be hidden from the recent feed // If mp4 and is not to be hidden from the recent feed
if (file.endsWith('.mp4') && !file.startsWith('HIDE')) { if ((file.endsWith('.mp4') || file.endsWith('.webm')) && !file.startsWith('HIDE')) {
let fileInfo = fs.statSync(`./public/uploads/${file}`); let fileInfo = fs.statSync(`./public/uploads/${file}`);
// Take screenshot at the first frame of the mp4 file // Take screenshot at the first frame of the mp4 file
ffmpeg(`./public/uploads/${file}`) ffmpeg(`./public/uploads/${file}`)
.takeScreenshots({ count: 1, timemarks: [ 1 ], size: '720x480', filename: file + '.png' }, 'public/thumbnail') .takeScreenshots({ count: 1, timemarks: [ 1 ], size: '720x480', filename: file + '.png' }, 'public/thumbnail')
.on('error', (err) => { .on('error', (err) => {
@ -125,7 +130,7 @@ class DownloadController {
return response.attachment('./public/uploads/alt.mp4'); return response.attachment('./public/uploads/alt.mp4');
}); });
} else { } else {
// Download as mp4 // Download as mp4 if possible
let video = youtubedl(data.url, ['--format=mp4', '-f', option]); let video = youtubedl(data.url, ['--format=mp4', '-f', option]);
video.on('error', function(err) { video.on('error', function(err) {
@ -140,23 +145,25 @@ class DownloadController {
}); });
}) })
let ext;
video.on('info', function(info) { video.on('info', function(info) {
// Set file name // Set file name
ext = info.ext;
let title = info.title.slice(0,80); let title = info.title.slice(0,80);
DLFile = `${title.replace(/\s/g, '_')}.${info.ext}`; DLFile = `${title.replace(/\s/g, '_')}.${ext}`;
// If no title use the ID // If no title use the ID
if (title == '_') title = `_${info.id}`; if (title == '_') title = `_${info.id}`;
// If user want to hide from the feed // If user want to hide from the feed
if (data.feed == 'on') if (data.feed == 'on')
DLFile = `HIDE${title.replace(/\s/g, '_')}.${info.ext}`; DLFile = `HIDE${title.replace(/\s/g, '_')}.${ext}`;
DLFile = DLFile.replace(/[()]/g, '_'); DLFile = DLFile.replace(/[()]/g, '_');
video.pipe(fs.createWriteStream(`./public/uploads/${DLFile}`)); video.pipe(fs.createWriteStream(`./public/uploads/${DLFile}`));
}); });
video.on('end', function() { video.on('end', function() {
if (data.format == 'mp4') { if (data.format == 'mp4' || data.format == 'webm') {
// If user requested mp4 directly attach the file // If user requested mp4 directly attach the file
return response.attachment(`./public/uploads/${DLFile}`) return response.attachment(`./public/uploads/${DLFile}`)
} else { } else {
@ -167,10 +174,10 @@ class DownloadController {
.audioFrequency('44100') .audioFrequency('44100')
.audioBitrate('320k') .audioBitrate('320k')
.format(data.format) .format(data.format)
.save(`./public/uploads/${DLFile.replace('.mp4', `.${data.format}`)}`) .save(`./public/uploads/${DLFile.replace(ext, `.${data.format}`)}`)
.on('end', () => { .on('end', () => {
fs.unlinkSync(`./public/uploads/${DLFile}`); fs.unlinkSync(`./public/uploads/${DLFile}`);
return response.attachment(`./public/uploads/${DLFile.replace('.mp4', `.${data.format}`)}`); return response.attachment(`./public/uploads/${DLFile.replace(ext, `.${data.format}`)}`);
}) })
} }
}); });