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,19 +30,21 @@ 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 = [];
|
||||
for (let f of fs.readdirSync('./public/uploads')) {
|
||||
|
@ -50,21 +54,21 @@ class DownloadController {
|
|||
file = file.sort((a, b) => {
|
||||
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 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;
|
||||
}
|
||||
return 0;
|
||||
}).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')) {
|
||||
if (!file.includes(f) && (f != 'hidden' && f != '.keep')) {
|
||||
fs.unlinkSync(`./public/uploads/${f}`);
|
||||
}
|
||||
}
|
||||
|
||||
for (let f of file) {
|
||||
for (let f of file) {
|
||||
if (f.endsWith('.mp4') || f.endsWith('.webm')) {
|
||||
// Send file name, file size in MB relative path for the file
|
||||
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` });
|
||||
}
|
||||
}
|
||||
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
|
||||
|
@ -125,36 +129,40 @@ class DownloadController {
|
|||
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) {
|
||||
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;
|
||||
|
@ -167,8 +175,8 @@ class DownloadController {
|
|||
|
||||
// If no title use the ID
|
||||
if (title == '_') title = `_${info.id}`;
|
||||
// If user want to hide from the feed
|
||||
if (data.feed == 'on')
|
||||
// If user want to hide from the feed
|
||||
if (data.feed == 'on')
|
||||
DLFile = `hidden/${title}.${ext}`;
|
||||
|
||||
video.pipe(fs.createWriteStream(`./public/uploads/${DLFile}`));
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
@endif
|
||||
<p class="subtitle">{{ announcement }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</section>
|
||||
|
@ -45,26 +45,26 @@
|
|||
<h1 class="title has-text-light">{{ antl.formatMessage('messages.title') }} v{{ version }}</h1>
|
||||
<form name="download-form" method="POST" action="/">
|
||||
{{ csrfField() }}
|
||||
|
||||
|
||||
<div class="field is-horizontal">
|
||||
<div class="field-body">
|
||||
<div class="field is-horizontal">
|
||||
<div class="control">
|
||||
<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') }}
|
||||
</label>
|
||||
|
||||
|
||||
<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') }}
|
||||
</label>
|
||||
|
||||
|
||||
<label class="checkbox" for="alt">
|
||||
<input class="checkbox" type="checkbox" name="alt" id="alt" title="Use this if download dosen't work">
|
||||
{{ antl.formatMessage('messages.altDL') }}
|
||||
</label>
|
||||
|
||||
|
||||
<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">
|
||||
{{ antl.formatMessage('messages.feed') }}
|
||||
|
@ -72,8 +72,8 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="field-body">
|
||||
<div class="field is-expanded">
|
||||
<div class="field has-addons">
|
||||
|
@ -86,41 +86,56 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="field has-addon">
|
||||
<div class="control">
|
||||
</div>
|
||||
<div class="control">
|
||||
</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?
|
||||
</label>
|
||||
|
||||
|
||||
<label class="radio" for="mp3">
|
||||
<input class="radio" type="radio" name="format" value="mp3" id="mp3">
|
||||
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>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="contaianer">
|
||||
<div id="msg"></div>
|
||||
|
||||
<div class="container">
|
||||
<div id="msg"></div>
|
||||
@if(error)
|
||||
<div class="notification is-danger fadein" id="error">
|
||||
<button class="delete" onclick="fadeout('error')"></button>
|
||||
|
@ -133,7 +148,7 @@
|
|||
</section>
|
||||
|
||||
@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">
|
||||
<div class="columns is-vcentered is-multiline fadein">
|
||||
@each(file in file)
|
||||
|
@ -152,7 +167,7 @@
|
|||
<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>
|
||||
</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>
|
||||
</p>
|
||||
</div>
|
||||
|
@ -185,12 +200,12 @@
|
|||
@endif
|
||||
<footer class="footer has-background-grey-dark has-text-light has-text-centered">
|
||||
<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.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
|
||||
<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
|
||||
<p><a href="legacy">{{ antl.formatMessage('messages.footer4') }}</a></p>
|
||||
</footer>
|
||||
|
@ -224,7 +239,7 @@
|
|||
console.error(err);
|
||||
document.getElementById('msg').innerHTML = '<div class="notification is-error fadein" id="notif">{{ antl.formatMessage('messages.errorCopy') }}</div>';
|
||||
setTimeout(() => {
|
||||
fadeout('notif')
|
||||
fadeout('notif')
|
||||
}, 2000);
|
||||
});
|
||||
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");
|
||||
input.addEventListener("keyup", function(event) {
|
||||
if (event.keyCode === 13) {
|
||||
|
@ -260,4 +275,4 @@
|
|||
}
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue