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,19 +30,21 @@ 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 = [];
for (let f of fs.readdirSync('./public/uploads')) { for (let f of fs.readdirSync('./public/uploads')) {
@ -50,21 +54,21 @@ class DownloadController {
file = file.sort((a, b) => { file = file.sort((a, b) => {
if ((a || b).endsWith('.mp4') || (a || b).endsWith('.webm') || (a || b).endsWith('.mp3') || (a || b).endsWith('.flac')) { if ((a || b).endsWith('.mp4') || (a || b).endsWith('.webm') || (a || b).endsWith('.mp3') || (a || b).endsWith('.flac')) {
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;
if (time1 > time2) return 1; if (time1 > time2) return 1;
} }
return 0; return 0;
}).slice(0, 5) }).slice(0, 5)
// Save space by deleting file that doesn't appear in the recent feed // Save space by deleting file that doesn't appear in the recent feed
for (let f of fs.readdirSync('./public/uploads')) { for (let f of fs.readdirSync('./public/uploads')) {
if (!file.includes(f) && (f != 'hidden' && f != '.keep')) { if (!file.includes(f) && (f != 'hidden' && f != '.keep')) {
fs.unlinkSync(`./public/uploads/${f}`); fs.unlinkSync(`./public/uploads/${f}`);
} }
} }
for (let f of file) { for (let f of file) {
if (f.endsWith('.mp4') || f.endsWith('.webm')) { if (f.endsWith('.mp4') || f.endsWith('.webm')) {
// Send file name, file size in MB relative path for the file // Send file name, file size in MB relative path for the file
let fileInfo = formatBytes(fs.statSync(`./public/uploads/${f}`).size).split(' '); let fileInfo = formatBytes(fs.statSync(`./public/uploads/${f}`).size).split(' ');
@ -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
@ -125,36 +129,40 @@ class DownloadController {
if (err); if (err);
}); });
} }
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;
@ -167,8 +175,8 @@ class DownloadController {
// 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 = `hidden/${title}.${ext}`; DLFile = `hidden/${title}.${ext}`;
video.pipe(fs.createWriteStream(`./public/uploads/${DLFile}`)); video.pipe(fs.createWriteStream(`./public/uploads/${DLFile}`));

View file

@ -33,7 +33,7 @@
@endif @endif
<p class="subtitle">{{ announcement }}</p> <p class="subtitle">{{ announcement }}</p>
</div> </div>
</div> </div>
@endif @endif
</div> </div>
</section> </section>
@ -45,26 +45,26 @@
<h1 class="title has-text-light">{{ antl.formatMessage('messages.title') }} v{{ version }}</h1> <h1 class="title has-text-light">{{ antl.formatMessage('messages.title') }} v{{ version }}</h1>
<form name="download-form" method="POST" action="/"> <form name="download-form" method="POST" action="/">
{{ csrfField() }} {{ csrfField() }}
<div class="field is-horizontal"> <div class="field is-horizontal">
<div class="field-body"> <div class="field-body">
<div class="field is-horizontal"> <div class="field is-horizontal">
<div class="control"> <div class="control">
<label class="radio" for="small"> <label class="radio" for="small">
<input class="radio" type="radio" name="quality" id="small" value="small"> <input class="radio" type="radio" name="quality" id="small" value="small">
{{ antl.formatMessage('messages.LQ') }} {{ antl.formatMessage('messages.LQ') }}
</label> </label>
<label class="radio" for="high"> <label class="radio" for="high">
<input class="radio" type="radio" name="quality" id="high" value="high" checked> <input class="radio" type="radio" name="quality" id="high" value="high" checked>
{{ antl.formatMessage('messages.HQ') }} {{ antl.formatMessage('messages.HQ') }}
</label> </label>
<label class="checkbox" for="alt"> <label class="checkbox" for="alt">
<input class="checkbox" type="checkbox" name="alt" id="alt" title="Use this if download dosen't work"> <input class="checkbox" type="checkbox" name="alt" id="alt" title="Use this if download dosen't work">
{{ antl.formatMessage('messages.altDL') }} {{ antl.formatMessage('messages.altDL') }}
</label> </label>
<label class="checkbox" for="feed"> <label class="checkbox" for="feed">
<input class="checkbox" type="checkbox" name="feed" id="feed" title="Use this if you don't want the video you are downloading to be public"> <input class="checkbox" type="checkbox" name="feed" id="feed" title="Use this if you don't want the video you are downloading to be public">
{{ antl.formatMessage('messages.feed') }} {{ antl.formatMessage('messages.feed') }}
@ -72,8 +72,8 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="field-body"> <div class="field-body">
<div class="field is-expanded"> <div class="field is-expanded">
<div class="field has-addons"> <div class="field has-addons">
@ -86,41 +86,56 @@
</div> </div>
</div> </div>
</div> </div>
<div class="field has-addon"> <div class="field has-addon">
<div class="control"> <div class="control">
</div> </div>
<div class="control"> <div class="control">
</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?
</label> </label>
<label class="radio" for="mp3"> <label class="radio" for="mp3">
<input class="radio" type="radio" name="format" value="mp3" id="mp3"> <input class="radio" type="radio" name="format" value="mp3" id="mp3">
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">
<button class="delete" onclick="fadeout('error')"></button> <button class="delete" onclick="fadeout('error')"></button>
@ -133,7 +148,7 @@
</section> </section>
@if(file != "") @if(file != "")
<p class="title has-text-light has-text-centered">{{ antl.formatMessage('messages.recentFeed') }}</p> <p class="title has-text-light has-text-centered">{{ antl.formatMessage('messages.recentFeed') }}</p>
<section class="section"> <section class="section">
<div class="columns is-vcentered is-multiline fadein"> <div class="columns is-vcentered is-multiline fadein">
@each(file in file) @each(file in file)
@ -152,7 +167,7 @@
<p class="control"> <p class="control">
<a class="button is-link is-rounded" href="{{ file.location }}" download>{{ antl.formatMessage('messages.recentDownload') }}<i class="fas fa-fw fa-file-download" aria-hidden="true"></i></a> <a class="button is-link is-rounded" href="{{ file.location }}" download>{{ antl.formatMessage('messages.recentDownload') }}<i class="fas fa-fw fa-file-download" aria-hidden="true"></i></a>
</p> </p>
<p class="control"> <p class="control">
<button class="button is-link is-rounded" onclick="toClipboard('https:\/\/namejeff.xyz\/{{ file.location }}')">{{ antl.formatMessage('messages.recentCopy') }}<i class="fas fa-fw fa-clipboard" aria-hidden="true"></i></button> <button class="button is-link is-rounded" onclick="toClipboard('https:\/\/namejeff.xyz\/{{ file.location }}')">{{ antl.formatMessage('messages.recentCopy') }}<i class="fas fa-fw fa-clipboard" aria-hidden="true"></i></button>
</p> </p>
</div> </div>
@ -185,12 +200,12 @@
@endif @endif
<footer class="footer has-background-grey-dark has-text-light has-text-centered"> <footer class="footer has-background-grey-dark has-text-light has-text-centered">
<p>{{ antl.formatMessage('messages.footer') }}</p> <p>{{ antl.formatMessage('messages.footer') }}</p>
@if(antl._locale == 'ar') @if(antl._locale == 'ar')
<bdi><p>{{ antl.formatMessage('messages.footer2p1') }} <a href="https://github.com/rg3/youtube-dl/">youtube-dl</a> - {{ antl.formatMessage('messages.footer2p2') }} <a href="https://discordapp.com/oauth2/authorize?client_id=377563711927484418&scope=bot&permissions=0">Haha yes</a> & <a href="https://twitter.com/ExplosmR">ExplosmRCG twitter bot</a> - {{ antl.formatMessage('messages.footer2p3') }}: {{ viewCounter }} - {{ antl.formatMessage('messages.footer2p4') }} <a href="https://discord.gg/cNRh5JQ">Supositware#1616</a> {{ antl.formatMessage('messages.footer2p5') }} </bdi></p> <bdi><p>{{ antl.formatMessage('messages.footer2p1') }} <a href="https://github.com/rg3/youtube-dl/">youtube-dl</a> - {{ antl.formatMessage('messages.footer2p2') }} <a href="https://discordapp.com/oauth2/authorize?client_id=377563711927484418&scope=bot&permissions=0">Haha yes</a> & <a href="https://twitter.com/ExplosmR">ExplosmRCG twitter bot</a> - {{ antl.formatMessage('messages.footer2p3') }}: {{ viewCounter }} - {{ antl.formatMessage('messages.footer2p4') }} <a href="https://discord.gg/cNRh5JQ">Supositware#1616</a> {{ antl.formatMessage('messages.footer2p5') }} </bdi></p>
<bdi><p>{{ antl.formatMessage('messages.footer3p1') }} <a href="https://www.paypal.me/supositware">Paypal</a> {{ antl.formatMessage('messages.footer3p2') }} <a href="https://basicattentiontoken.org/">BAT</a> {{ antl.formatMessage('messages.footer3p3') }} <a href="https://brave.com/nam120">Brave Browser </a> </bdi> <bdi><p>{{ antl.formatMessage('messages.footer3p1') }} <a href="https://www.paypal.me/supositware">Paypal</a> {{ antl.formatMessage('messages.footer3p2') }} <a href="https://basicattentiontoken.org/">BAT</a> {{ antl.formatMessage('messages.footer3p3') }} <a href="https://brave.com/nam120">Brave Browser </a> </bdi>
@else @else
<p>{{ antl.formatMessage('messages.footer2p1') }} <a href="https://github.com/rg3/youtube-dl/">youtube-dl</a> - {{ antl.formatMessage('messages.footer2p2') }} <a href="https://discordapp.com/oauth2/authorize?client_id=377563711927484418&scope=bot&permissions=0">Haha yes</a> & <a href="https://twitter.com/ExplosmR">ExplosmRCG twitter bot</a> - {{ antl.formatMessage('messages.footer2p3') }}: {{ viewCounter }} - {{ antl.formatMessage('messages.footer2p4') }} <a href="https://discord.gg/cNRh5JQ">Supositware#1616</a> {{ antl.formatMessage('messages.footer2p5') }}</p> <p>{{ antl.formatMessage('messages.footer2p1') }} <a href="https://github.com/rg3/youtube-dl/">youtube-dl</a> - {{ antl.formatMessage('messages.footer2p2') }} <a href="https://discordapp.com/oauth2/authorize?client_id=377563711927484418&scope=bot&permissions=0">Haha yes</a> & <a href="https://twitter.com/ExplosmR">ExplosmRCG twitter bot</a> - {{ antl.formatMessage('messages.footer2p3') }}: {{ viewCounter }} - {{ antl.formatMessage('messages.footer2p4') }} <a href="https://discord.gg/cNRh5JQ">Supositware#1616</a> {{ antl.formatMessage('messages.footer2p5') }}</p>
<p>{{ antl.formatMessage('messages.footer3p1') }} <a href="https://www.paypal.me/supositware">Paypal</a> {{ antl.formatMessage('messages.footer3p2') }} <a href="https://basicattentiontoken.org/">BAT</a> {{ antl.formatMessage('messages.footer3p3') }} <a href="https://brave.com/nam120">Brave Browser </a> <p>{{ antl.formatMessage('messages.footer3p1') }} <a href="https://www.paypal.me/supositware">Paypal</a> {{ antl.formatMessage('messages.footer3p2') }} <a href="https://basicattentiontoken.org/">BAT</a> {{ antl.formatMessage('messages.footer3p3') }} <a href="https://brave.com/nam120">Brave Browser </a>
@endif @endif
<p><a href="legacy">{{ antl.formatMessage('messages.footer4') }}</a></p> <p><a href="legacy">{{ antl.formatMessage('messages.footer4') }}</a></p>
</footer> </footer>
@ -224,7 +239,7 @@
console.error(err); console.error(err);
document.getElementById('msg').innerHTML = '<div class="notification is-error fadein" id="notif">{{ antl.formatMessage('messages.errorCopy') }}</div>'; document.getElementById('msg').innerHTML = '<div class="notification is-error fadein" id="notif">{{ antl.formatMessage('messages.errorCopy') }}</div>';
setTimeout(() => { setTimeout(() => {
fadeout('notif') fadeout('notif')
}, 2000); }, 2000);
}); });
document.getElementById('msg').innerHTML = '<div class="notification is-success fadein" id="notif">{{ antl.formatMessage('messages.successCopy') }}</div>'; document.getElementById('msg').innerHTML = '<div class="notification is-success fadein" id="notif">{{ antl.formatMessage('messages.successCopy') }}</div>';
@ -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) {
@ -260,4 +275,4 @@
} }
}); });
</script> </script>
</html> </html>