ja
This commit is contained in:
parent
6a4d3cb5bc
commit
2a10fd2e93
44
package-lock.json
generated
44
package-lock.json
generated
@ -10,22 +10,22 @@
|
||||
"integrity": "sha512-wE2v81i4C4Ol09RtsWFAqg3BUitWbHSpSlIo+bNdsCJijO9sjme+zm+73ZMCa/qMC8UEERxzGbvmr1cffo2SiQ=="
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "13.13.25",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.25.tgz",
|
||||
"integrity": "sha512-6ZMK4xRcF2XrPdKmPYQxZkdHKV18xKgUFVvhIgw2iwaaO6weleLPHLBGPZmLhjo+m1N+MZXRAoBEBCCVqgO2zQ=="
|
||||
"version": "14.14.22",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.22.tgz",
|
||||
"integrity": "sha512-g+f/qj/cNcqKkc3tFqlXOYjrmZA+jNBiDzbP3kH+B+otKFqAdPgVTGP1IeKRdMml/aE69as5S4FqtxAbl+LaMw=="
|
||||
},
|
||||
"cuffeo": {
|
||||
"version": "1.0.6-1",
|
||||
"resolved": "https://registry.npmjs.org/cuffeo/-/cuffeo-1.0.6-1.tgz",
|
||||
"integrity": "sha512-r7MCG7rIuG86leo4aB73YEkl7UWAGprd2A/9xy4iZmrbMepIFaCgHOn7SC6wemPbS4LRXQAgqvV9a6PCyHaCfg==",
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/cuffeo/-/cuffeo-1.0.7.tgz",
|
||||
"integrity": "sha512-9XpEUnN9jIfaiIMJwcfPW61PxTxBJUoa9VN/TjiWk7Z/jNStdrlPTdn6Y2cdclsWsHtAyabHdCNUAHscQ89WCQ==",
|
||||
"requires": {
|
||||
"flumm-fetch-cookies": "^1.3.5"
|
||||
}
|
||||
},
|
||||
"denque": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz",
|
||||
"integrity": "sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ=="
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.0.tgz",
|
||||
"integrity": "sha512-CYiCSgIF1p6EUByQPlGkKnP1M9g0ZV3qMIrqMqZqdwazygIA/YP2vrbcyl1h/WppKJTdl1F85cXIle+394iDAQ=="
|
||||
},
|
||||
"flumm-fetch": {
|
||||
"version": "1.0.1",
|
||||
@ -41,11 +41,11 @@
|
||||
}
|
||||
},
|
||||
"iconv-lite": {
|
||||
"version": "0.5.2",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.5.2.tgz",
|
||||
"integrity": "sha512-kERHXvpSaB4aU3eANwidg79K8FlrN77m8G9V+0vOR3HYaRifrlwMEpT7ZBJqLSEIHnEgJTHcWK82wwLwwKwtag==",
|
||||
"version": "0.6.2",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.2.tgz",
|
||||
"integrity": "sha512-2y91h5OpQlolefMPmUlivelittSWy0rP+oYVpn6A7GwVHNE8AWzoYOBNmlwks3LobaJxgHCYZAnyNo2GgpNRNQ==",
|
||||
"requires": {
|
||||
"safer-buffer": ">= 2.1.2 < 3"
|
||||
"safer-buffer": ">= 2.1.2 < 3.0.0"
|
||||
}
|
||||
},
|
||||
"long": {
|
||||
@ -54,16 +54,16 @@
|
||||
"integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA=="
|
||||
},
|
||||
"mariadb": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/mariadb/-/mariadb-2.4.2.tgz",
|
||||
"integrity": "sha512-ybK520CO/8Z74MNJ77dEwXjRMhxMbQdpPia+/uJakJWiZoLEmuwSHqs51qWr4FE5WcgHQfL5KCmOiHErR/LpTg==",
|
||||
"version": "2.5.2",
|
||||
"resolved": "https://registry.npmjs.org/mariadb/-/mariadb-2.5.2.tgz",
|
||||
"integrity": "sha512-SfaBl5/LiX2qJNNr7wCQvizVjtWxVm1CUWYKe+y4OMeyYMM6g0GhwX7/BbGtv/O3WthnGrM+Kj1imFnlescO0w==",
|
||||
"requires": {
|
||||
"@types/geojson": "^7946.0.7",
|
||||
"@types/node": "^13.9.8",
|
||||
"@types/node": "^14.14.7",
|
||||
"denque": "^1.4.1",
|
||||
"iconv-lite": "^0.5.1",
|
||||
"iconv-lite": "^0.6.2",
|
||||
"long": "^4.0.0",
|
||||
"moment-timezone": "^0.5.31",
|
||||
"moment-timezone": "^0.5.32",
|
||||
"please-upgrade-node": "^3.2.0"
|
||||
}
|
||||
},
|
||||
@ -73,9 +73,9 @@
|
||||
"integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ=="
|
||||
},
|
||||
"moment-timezone": {
|
||||
"version": "0.5.31",
|
||||
"resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.31.tgz",
|
||||
"integrity": "sha512-+GgHNg8xRhMXfEbv81iDtrVeTcWt0kWmTEY1XQK14dICTXnWJnT0dxdlPspwqF3keKMVPXwayEsk1DI0AA/jdA==",
|
||||
"version": "0.5.32",
|
||||
"resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.32.tgz",
|
||||
"integrity": "sha512-Z8QNyuQHQAmWucp8Knmgei8YNo28aLjJq6Ma+jy1ZSpSk5nyfRT8xgUbSQvD2+2UajISfenndwvFuH3NGS+nvA==",
|
||||
"requires": {
|
||||
"moment": ">= 2.9.0"
|
||||
}
|
||||
|
@ -10,8 +10,8 @@
|
||||
"author": "Flummi",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cuffeo": "^1.0.6-1",
|
||||
"cuffeo": "^1.0.7",
|
||||
"flumm-fetch-cookies": "^1.4.0",
|
||||
"mariadb": "^2.4.2"
|
||||
"mariadb": "^2.5.2"
|
||||
}
|
||||
}
|
||||
|
@ -18,12 +18,20 @@ export default async bot => {
|
||||
f: e => {
|
||||
logger.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`);
|
||||
|
||||
const trigger = [...bot._trigger.entries()].filter(t =>
|
||||
t[1].call.exec(e.message) &&
|
||||
t[1].clients.includes(e.type) &&
|
||||
t[1].active &&
|
||||
t[1].level <= getLevel(e.user).level
|
||||
);
|
||||
let trigger;
|
||||
|
||||
if(e.photo) {
|
||||
trigger = [...bot._trigger.entries()].filter(t => t[1].name === "parser");
|
||||
if(!e.message)
|
||||
e.message = "";
|
||||
} else {
|
||||
trigger = [...bot._trigger.entries()].filter(t =>
|
||||
t[1].call.exec(e.message) &&
|
||||
t[1].clients.includes(e.type) &&
|
||||
t[1].active &&
|
||||
t[1].level <= getLevel(e.user).level
|
||||
);
|
||||
}
|
||||
|
||||
trigger.forEach(async t => {
|
||||
try {
|
||||
@ -31,6 +39,7 @@ export default async bot => {
|
||||
console.log(`triggered > ${t[0]}`);
|
||||
}
|
||||
catch(err) {
|
||||
console.error(err);
|
||||
e.reply(`${t[0]}: An error occured.`);
|
||||
logger.error(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${err.toString ? err : JSON.stringify(err)}`);
|
||||
}
|
||||
|
@ -3,6 +3,6 @@ export default new class {
|
||||
return (size / Math.pow(1024, i)).toFixed(2) * 1 + " " + ["B", "kB", "MB", "GB", "TB"][i];
|
||||
}
|
||||
calcSpeed(b, s) {
|
||||
return `${(Math.round((b * 8 / s / 1e6) * 1e4) / 1e4).toFixed(2)} Mbit/s`;
|
||||
return (Math.round((b * 8 / s / 1e6) * 1e4) / 1e4);
|
||||
}
|
||||
};
|
||||
|
@ -21,7 +21,7 @@ router.get("/", async (req, res) => {
|
||||
router.get(/^\/([0-9]+)$/, async (req, res) => {
|
||||
const query = (await sql.query(queries.item, Array(3).fill(req.url.split[0])))?.shift();
|
||||
|
||||
if(query.length === 0)
|
||||
if(!query?.id)
|
||||
return res.redirect("/404");
|
||||
|
||||
const data = {
|
||||
|
@ -17,11 +17,12 @@ export default async bot => {
|
||||
call: regex,
|
||||
active: true,
|
||||
f: e => {
|
||||
const links = e.message.match(regex)?.filter(link => {
|
||||
return (
|
||||
!link.includes("f0ck.me")
|
||||
);
|
||||
});
|
||||
const links = e.message.match(regex)?.filter(link => !link.includes("f0ck.me")) || [];
|
||||
|
||||
if(e.photo) {
|
||||
links.push(e.photo);
|
||||
}
|
||||
|
||||
if(links.length === 0)
|
||||
return false;
|
||||
|
||||
@ -42,17 +43,31 @@ export default async bot => {
|
||||
// generate uuid
|
||||
const uuid = (await sql.query("select left(uuid(), 8) as uuid"))[0].uuid;
|
||||
|
||||
// read metadata
|
||||
const meta = JSON.parse((await exec(`youtube-dlc --skip-download --dump-json "${link}"`)).stdout);
|
||||
const maxfilesize = ( getLevel(e.user).level > 50 ? cfg.main.maxfilesize * 2.5 : cfg.main.maxfilesize ) / 1024;
|
||||
|
||||
const filename = `${uuid}.mp4`;
|
||||
let meta;
|
||||
// read metadata
|
||||
try {
|
||||
//meta = JSON.parse((await exec(`youtube-dlc -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" --skip-download --dump-json "${link}"`)).stdout);
|
||||
meta = JSON.parse((await exec(`youtube-dlc -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" --skip-download --dump-json "${link}"`)).stdout);
|
||||
}
|
||||
catch(e) {
|
||||
return;
|
||||
}
|
||||
|
||||
const filename = `${uuid}.${meta.ext}`;
|
||||
|
||||
e.reply(`downloading ${filename}...`);
|
||||
|
||||
// download data
|
||||
const start = new Date();
|
||||
const maxfilesize = getLevel(e.user).level > 50 ? cfg.main.maxfilesize * 2.5 : cfg.main.maxfilesize;
|
||||
const source = (await exec(`youtube-dlc "${link}" -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" --max-filesize ${maxfilesize} -o ./tmp/${filename}`)).stdout.trim();
|
||||
//const source = (await exec(`youtube-dlc "${link}" -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" --max-filesize ${maxfilesize} -o ./tmp/${filename}`)).stdout.trim();
|
||||
let source;
|
||||
if(meta.ext === "mp4")
|
||||
source = (await exec(`youtube-dlc "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" --merge-output-format mp4 -o ./tmp/${filename}`)).stdout.trim();
|
||||
else
|
||||
source = (await exec(`youtube-dlc "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" -o ./tmp/${filename}`)).stdout.trim();
|
||||
|
||||
if(source.match(/larger than/))
|
||||
return e.reply("too large lol");
|
||||
const end = ~~((new Date() - start) / 1e3);
|
||||
@ -76,15 +91,15 @@ export default async bot => {
|
||||
|
||||
const insertq = await sql.query(
|
||||
"insert into items (src, dest, mime, size, checksum, username, userchannel, usernetwork, stamp, active) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
[ link, filename, mime, size, checksum, e.user.nick || e.user.username, e.channel, e.network, ~~(new Date() / 1000), 1 ]
|
||||
[ e.photo ? "" : link, filename, mime, size, checksum, e.user.nick || e.user.username, e.channel, e.network, ~~(new Date() / 1000), 1 ]
|
||||
);
|
||||
|
||||
// generate thumbnail
|
||||
let thumb_orig = (await exec(`youtube-dlc --get-thumbnail "${link}"`)).stdout.trim();
|
||||
let thumb_orig = (await exec(`youtube-dlc -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" --get-thumbnail "${link}"`)).stdout.trim();
|
||||
if(!thumb_orig.startsWith("http")) {
|
||||
if(mime.startsWith("image") && mime !== "image/gif")
|
||||
thumb_orig = `./public/b/${filename}`;
|
||||
else {
|
||||
else if(!mime.startsWith("audio")) {
|
||||
await exec(`ffmpegthumbnailer -i./public/b/${filename} -s1024 -o./tmp/${insertq.insertId}`);
|
||||
thumb_orig = `./tmp/${insertq.insertId}`;
|
||||
}
|
||||
@ -92,9 +107,12 @@ export default async bot => {
|
||||
await exec(`convert "${thumb_orig}" -resize "200x200^" -gravity center -crop 128x128+0+0 +repage ./public/t/${insertq.insertId}.png`);
|
||||
await fs.promises.unlink(`./tmp/${insertq.insertId}`).catch(_=>{});
|
||||
|
||||
let speed = lib.calcSpeed(size, end);
|
||||
speed = !Number.isFinite(speed) ? "yes" : `${speed.toFixed(2)} Mbit/s`;
|
||||
|
||||
e.reply([
|
||||
`title: ${meta.fulltitle}`,
|
||||
`size: ${lib.formatSize(size)} ${lib.calcSpeed(size, end)} (ytdl: ${end})`,
|
||||
`size: ${lib.formatSize(size)} speed: ${speed}`,
|
||||
`link: ${cfg.main.url}/${insertq.insertId}`
|
||||
]);
|
||||
|
||||
|
@ -11,6 +11,7 @@ import "./websrv.mjs";
|
||||
this.call = args.call;
|
||||
this.help = args.help || false;
|
||||
this.level = args.level || 0;
|
||||
this.name = args.name;
|
||||
this.active = args.hasOwnProperty("active") ? args.active : true;
|
||||
this.clients = args.clients || [ "irc", "tg", "slack" ];
|
||||
this.f = args.f;
|
||||
|
Loading…
Reference in New Issue
Block a user