Added proxy options

This commit is contained in:
supositware 2020-08-27 19:57:27 +02:00
parent b722935561
commit ffc6fe1dd8
2 changed files with 103 additions and 80 deletions

View file

@ -1,16 +1,18 @@
'use strict' 'use strict'
const youtubedl = require('youtube-dl') const youtubedl = require('youtube-dl');
const fs = require('fs') const fs = require('fs');
const ffmpeg = require('fluent-ffmpeg') const ffmpeg = require('fluent-ffmpeg');
const { version } = require('../../../package.json'); const { version } = require('../../../package.json');
const Antl = use('Antl') const Antl = use('Antl');
const proxy = require('../../../proxy/proxy.json')
let viewCounter = 0; let viewCounter = 0;
let files = []; let files = [];
let day; let day;
let month; let month;
let announcementArray; 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 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 { class DownloadController {
async index ({ view, request, locale }) { async index ({ view, request, locale }) {
console.log(defaultViewOption)
viewCounter++; viewCounter++;
// Coudln't find a cleaner way to make it change with the browser locale defaultViewOption.viewCounter = viewCounter;
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')]; // 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 // 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 // Get date for some event
let today = new Date(); let today = new Date();
day = today.getDay(); defaultViewOption.day = today.getDay();
month = today.getMonth(); defaultViewOption.month = today.getMonth();
// If legacy link return // 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 = []; files = [];
let file = []; 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` }); 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 }) { async download({ view, request, response }) {
@ -91,18 +96,17 @@ class DownloadController {
quality: request.input('quality'), quality: request.input('quality'),
format: request.input('format'), format: request.input('format'),
alt: request.input('alt'), alt: request.input('alt'),
feed: request.input('feed') feed: request.input('feed'),
proxy: request.input('proxy')
} }
console.log(data.proxy);
if (!data.url) { if (!data.url) {
return view.render(page, { let viewOption = {...defaultViewOption};
version: version, viewOption.error = true;
viewCounter: viewCounter, viewOption.errormsg = 'bruh moment, you didin\'t input a link.';
file: files, return view.render(page, viewOption);
day: day, month: month, announcement: announcement ,
error: true,
errormsg: 'bruh moment, you didin\'t input a link.'
});
} }
// Youtube-dl quality settings // 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) { if (err) {
console.error(err); console.error(err);
return response.send(view.render(page, { let viewOption = {...defaultViewOption};
version: version, viewOption.error = true;
viewCounter: viewCounter, viewOption.errormsg = err;
file: files, return view.render(page, viewOption);
day: day, month: month, announcement: announcement ,
error: true,
errormsg: err
}));
} }
return response.attachment(altFolder); return response.attachment(altFolder);
}); });
} else { } else {
// Download as mp4 if possible // 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) { video.on('error', function(err) {
console.error(err); console.error(err);
return response.send(view.render(page, { let viewOption = {...defaultViewOption};
version: version, viewOption.error = true;
viewCounter: viewCounter, viewOption.errormsg = err;
file: files, return view.render(page, viewOption);
day: day, month: month, announcement: announcement ,
error: true,
errormsg: err
}));
}) })
let ext; let ext;

View file

@ -95,10 +95,9 @@
</div> </div>
</div> </div>
<div class="field is-horizontal"> <div class="field is-horizontal level">
<div class="field-body">
<div class="field is-horizontal"> <div class="control level-left">
<div class="control">
<label class="radio" for="mp4"> <label class="radio" for="mp4">
<input class="radio" type="radio" name="format" value="mp4" id="mp4" checked> <input class="radio" type="radio" name="format" value="mp4" id="mp4" checked>
Video? Video?
@ -109,17 +108,33 @@
MP3? MP3?
</label> </label>
<label class="radio" for="flac"> <label class="radio" for="flac" title="This is pure placebo">
<input class="radio" type="radio" name="format" value="flac" id="flac"> <input class="radio" type="radio" name="format" value="flac" id="flac" title="This is pure placebo">
FLAC? FLAC?
</label> </label>
</div> </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> </div>
</div> </div>
</form> </form>
<div class="contaianer"> <div class="container">
<div id="msg"></div> <div id="msg"></div>
@if(error) @if(error)
<div class="notification is-danger fadein" id="error"> <div class="notification is-danger fadein" id="error">
@ -251,7 +266,7 @@
} }
} }
// If user press enter do samething as if pressing the button // If user press enter do same thing as if pressing the button
let input = document.getElementById("URL"); let input = document.getElementById("URL");
input.addEventListener("keyup", function(event) { input.addEventListener("keyup", function(event) {
if (event.keyCode === 13) { if (event.keyCode === 13) {