Added proxy options
This commit is contained in:
parent
b722935561
commit
ffc6fe1dd8
2 changed files with 103 additions and 80 deletions
|
@ -1,16 +1,18 @@
|
|||
'use strict'
|
||||
const youtubedl = require('youtube-dl')
|
||||
const fs = require('fs')
|
||||
const ffmpeg = require('fluent-ffmpeg')
|
||||
const youtubedl = require('youtube-dl');
|
||||
const fs = require('fs');
|
||||
const ffmpeg = require('fluent-ffmpeg');
|
||||
const { version } = require('../../../package.json');
|
||||
const Antl = use('Antl')
|
||||
const Antl = use('Antl');
|
||||
const proxy = require('../../../proxy/proxy.json')
|
||||
|
||||
let viewCounter = 0;
|
||||
let files = [];
|
||||
let day;
|
||||
let month;
|
||||
let announcementArray;
|
||||
let announcement
|
||||
let announcement;
|
||||
let defaultViewOption = { version: version, viewCounter: viewCounter, file: files, day: day, month: month, announcement: announcement, proxy: proxy }
|
||||
|
||||
|
||||
function formatBytes(bytes, decimals = 2) { // https://stackoverflow.com/a/18650828
|
||||
|
@ -28,18 +30,20 @@ function formatBytes(bytes, decimals = 2) { // https://stackoverflow.com/a/18650
|
|||
class DownloadController {
|
||||
|
||||
async index ({ view, request, locale }) {
|
||||
console.log(defaultViewOption)
|
||||
viewCounter++;
|
||||
// Coudln't find a cleaner way to make it change with the browser locale
|
||||
announcementArray = [Antl.forLocale(locale).formatMessage('announcement.1'), Antl.forLocale(locale).formatMessage('announcement.2'), Antl.forLocale(locale).formatMessage('announcement.3'), Antl.forLocale(locale).formatMessage('announcement.4'), Antl.forLocale(locale).formatMessage('announcement.5'), Antl.forLocale(locale).formatMessage('announcement.6')];
|
||||
defaultViewOption.viewCounter = viewCounter;
|
||||
// Couldn't find a cleaner way to make it change with the browser locale
|
||||
announcementArray = [Antl.forLocale(locale).formatMessage('announcement.1'), Antl.forLocale(locale).formatMessage('announcement.2'), Antl.forLocale(locale).formatMessage('announcement.3'), Antl.forLocale(locale).formatMessage('announcement.4'), Antl.forLocale(locale).formatMessage('announcement.5'), Antl.forLocale(locale).formatMessage('announcement.6'), Antl.forLocale(locale).formatMessage('announcement.7')];
|
||||
// Get random announcement
|
||||
announcement = announcementArray[Math.floor(Math.random() * announcementArray.length)];
|
||||
defaultViewOption.announcement = announcementArray[Math.floor(Math.random() * announcementArray.length)];
|
||||
|
||||
// Get date for some event
|
||||
let today = new Date();
|
||||
day = today.getDay();
|
||||
month = today.getMonth();
|
||||
defaultViewOption.day = today.getDay();
|
||||
defaultViewOption.month = today.getMonth();
|
||||
// If legacy link return
|
||||
if (request.url() == '/legacy') return view.render('legacy', { version: version, viewCounter: viewCounter, day: day, month: month, announcement: announcement});
|
||||
if (request.url() == '/legacy') return view.render('legacy', defaultViewOption);
|
||||
|
||||
files = [];
|
||||
let file = [];
|
||||
|
@ -75,7 +79,8 @@ class DownloadController {
|
|||
files.push({ name: f.split('.').slice(0, -1).join('.'), size: fileInfo[0], unit: fileInfo[1], date: fs.statSync(`./public/uploads/${f}`).ctime, location: `uploads/${f}`, ext: f.split('.').pop(), img: `/asset/music.png` });
|
||||
}
|
||||
}
|
||||
return view.render('index', { version: version, viewCounter: viewCounter, file: files, day: day, month: month, announcement: announcement});
|
||||
defaultViewOption.file = files;
|
||||
return view.render('index', defaultViewOption);
|
||||
}
|
||||
|
||||
async download({ view, request, response }) {
|
||||
|
@ -91,18 +96,17 @@ class DownloadController {
|
|||
quality: request.input('quality'),
|
||||
format: request.input('format'),
|
||||
alt: request.input('alt'),
|
||||
feed: request.input('feed')
|
||||
feed: request.input('feed'),
|
||||
proxy: request.input('proxy')
|
||||
}
|
||||
|
||||
console.log(data.proxy);
|
||||
|
||||
if (!data.url) {
|
||||
return view.render(page, {
|
||||
version: version,
|
||||
viewCounter: viewCounter,
|
||||
file: files,
|
||||
day: day, month: month, announcement: announcement ,
|
||||
error: true,
|
||||
errormsg: 'bruh moment, you didin\'t input a link.'
|
||||
});
|
||||
let viewOption = {...defaultViewOption};
|
||||
viewOption.error = true;
|
||||
viewOption.errormsg = 'bruh moment, you didin\'t input a link.';
|
||||
return view.render(page, viewOption);
|
||||
}
|
||||
|
||||
// Youtube-dl quality settings
|
||||
|
@ -126,35 +130,39 @@ class DownloadController {
|
|||
});
|
||||
}
|
||||
|
||||
return youtubedl.exec(data.url, ['--format=mp4', '-o', altFolder], {}, function(err, output) {
|
||||
let options = ['--format=mp4', '-o', altFolder];
|
||||
if (data.proxy !== "none") {
|
||||
options.push('--proxy');
|
||||
options.push(data.proxy);
|
||||
}
|
||||
|
||||
return youtubedl.exec(data.url, options, {}, function(err, output) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return response.send(view.render(page, {
|
||||
version: version,
|
||||
viewCounter: viewCounter,
|
||||
file: files,
|
||||
day: day, month: month, announcement: announcement ,
|
||||
error: true,
|
||||
errormsg: err
|
||||
}));
|
||||
let viewOption = {...defaultViewOption};
|
||||
viewOption.error = true;
|
||||
viewOption.errormsg = err;
|
||||
return view.render(page, viewOption);
|
||||
}
|
||||
|
||||
return response.attachment(altFolder);
|
||||
});
|
||||
} else {
|
||||
// Download as mp4 if possible
|
||||
let video = youtubedl(data.url, ['--format=mp4', '-f', option]);
|
||||
let options = ['--format=mp4', '-f', option];
|
||||
if (data.proxy !== "none") {
|
||||
options.push('--proxy');
|
||||
options.push(data.proxy);
|
||||
}
|
||||
|
||||
let video = youtubedl(data.url, options);
|
||||
|
||||
video.on('error', function(err) {
|
||||
console.error(err);
|
||||
return response.send(view.render(page, {
|
||||
version: version,
|
||||
viewCounter: viewCounter,
|
||||
file: files,
|
||||
day: day, month: month, announcement: announcement ,
|
||||
error: true,
|
||||
errormsg: err
|
||||
}));
|
||||
let viewOption = {...defaultViewOption};
|
||||
viewOption.error = true;
|
||||
viewOption.errormsg = err;
|
||||
return view.render(page, viewOption);
|
||||
})
|
||||
|
||||
let ext;
|
||||
|
|
|
@ -95,10 +95,9 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field is-horizontal">
|
||||
<div class="field-body">
|
||||
<div class="field is-horizontal">
|
||||
<div class="control">
|
||||
<div class="field is-horizontal level">
|
||||
|
||||
<div class="control level-left">
|
||||
<label class="radio" for="mp4">
|
||||
<input class="radio" type="radio" name="format" value="mp4" id="mp4" checked>
|
||||
Video?
|
||||
|
@ -109,17 +108,33 @@
|
|||
MP3?
|
||||
</label>
|
||||
|
||||
<label class="radio" for="flac">
|
||||
<input class="radio" type="radio" name="format" value="flac" id="flac">
|
||||
<label class="radio" for="flac" title="This is pure placebo">
|
||||
<input class="radio" type="radio" name="format" value="flac" id="flac" title="This is pure placebo">
|
||||
FLAC?
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="field-body level-right">
|
||||
<div class="field is-horizontal">
|
||||
<div class="control">
|
||||
<span>Proxy options:</span>
|
||||
<label class="radio" for="none">
|
||||
<input class="radio" type="radio" name="proxy" value="none" id="none" checked>
|
||||
None
|
||||
</label>
|
||||
@each(proxy in proxy)
|
||||
<label class="radio" for="{{ proxy.ip }}">
|
||||
<input class="radio" type="radio" name="proxy" value="{{ proxy.ip }}" id="{{ proxy.ip }}">
|
||||
{{ proxy.ip.substring(0, proxy.ip.length - 5) }} - {{ proxy.country }}
|
||||
</label>
|
||||
@endeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="contaianer">
|
||||
<div class="container">
|
||||
<div id="msg"></div>
|
||||
@if(error)
|
||||
<div class="notification is-danger fadein" id="error">
|
||||
|
|
Loading…
Reference in a new issue