forked from f0ck/f0ckv2
querybuilder intensifies
This commit is contained in:
@@ -8,7 +8,8 @@ import { exec as _exec } from "child_process";
|
||||
import { promisify } from "util";
|
||||
const exec = promisify(_exec);
|
||||
|
||||
const regex = /https?:\/\/[\w\S(\.|:|/)]+/gi;
|
||||
//const regex = /https?:\/\/[\w\S(\.|:|/)]+/gi;
|
||||
const regex = /https?:\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?/gi;
|
||||
|
||||
export default async bot => {
|
||||
|
||||
@@ -35,12 +36,12 @@ export default async bot => {
|
||||
|
||||
links.forEach(async link => {
|
||||
// check repost (link)
|
||||
const q_repost = await sql.query("select id from items where src = ?", [ link ]);
|
||||
const q_repost = await sql("items").select("id").where("src", link);
|
||||
if(q_repost.length > 0)
|
||||
return e.reply(`repost motherf0cker (link): ${cfg.main.url}/${q_repost[0].id}`);
|
||||
|
||||
// generate uuid
|
||||
const uuid = (await sql.query("select left(uuid(), 8) as uuid"))[0].uuid;
|
||||
const uuid = (await sql.select(sql.raw("left(uuid(), 8) as uuid")))[0].uuid;
|
||||
|
||||
const maxfilesize = (getLevel(e.user).level > 50 ? cfg.main.maxfilesize * 2.5 : cfg.main.maxfilesize) / 1024;
|
||||
|
||||
@@ -48,7 +49,6 @@ export default async bot => {
|
||||
// read metadata
|
||||
try {
|
||||
meta = JSON.parse((await exec(`youtube-dl -f "bestvideo[ext=mp4,filesize<${maxfilesize}k][width<2000][height<=1200]+bestaudio[ext=m4a,filesize<${maxfilesize}k]/bestvideo[width<2000][height<=1200]+bestaudio/best[width<2000][height<=1200]/best" --skip-download --dump-json "${link}"`)).stdout);
|
||||
//meta = JSON.parse((await exec(`youtube-dl -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" --skip-download --dump-json "${link}"`)).stdout);
|
||||
}
|
||||
catch(err) {
|
||||
//e.reply("(╯° °)╯︵ ┻━┻)");
|
||||
@@ -56,6 +56,9 @@ export default async bot => {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!cfg.ext.includes(meta.ext.toLowerCase()))
|
||||
return;
|
||||
|
||||
let filename = `${uuid}.${meta.ext}`;
|
||||
|
||||
//e.reply(`downloading ${uuid}...`);
|
||||
@@ -65,18 +68,14 @@ export default async bot => {
|
||||
const start = new Date();
|
||||
let source;
|
||||
if(meta.ext === "mp4") {
|
||||
//source = (await exec(`youtube-dl "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" --merge-output-format mp4 -o ./tmp/${filename}`)).stdout.trim();
|
||||
source = (await exec(`youtube-dl "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[ext=mp4,filesize<${maxfilesize}k][width<2000][height<=1200]+bestaudio[ext=m4a,filesize<${maxfilesize}k]/bestvideo[width<2000][height<=1200]+bestaudio/best[width<2000][height<=1200]/best" --merge-output-format mp4 -o ./tmp/${filename}`)).stdout.trim();
|
||||
console.log("mp4 lol");
|
||||
//console.log("mp4 lol");
|
||||
}
|
||||
else {
|
||||
//source = (await exec(`youtube-dl "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[filesize<${maxfilesize}k][width<2000][height<=1200]+bestaudio[ext=${meta.ext},filesize<${maxfilesize}k]/bestvideo[width<2000][height<=1200]+bestaudio/best[ext=${meta.ext},width<2000][height<=1200]/best" --merge-output-format ${meta.ext} -o ./tmp/${filename}`)).stdout.trim();
|
||||
source = (await exec(`youtube-dl "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[filesize<${maxfilesize}k][width<2000][height<=1200][ext=${meta.ext}]+bestaudio[filesize<${maxfilesize}k][ext=${meta.ext}]/best" -o ./tmp/${filename}`)).stdout.trim();
|
||||
//source = (await exec(`youtube-dl "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[ext=mp4,filesize<${maxfilesize}k][width<2000][height<=1200]+bestaudio[ext=m4a,filesize<${maxfilesize}k]/bestvideo[width<2000][height<=1200]+bestaudio/best[width<2000][height<=1200]/best" -o ./tmp/${filename}`)).stdout.trim();
|
||||
//source = (await exec(`youtube-dl "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" -o ./tmp/${filename}`)).stdout.trim();
|
||||
console.log("alles andere lol");
|
||||
//console.log("alles andere lol");
|
||||
}
|
||||
console.log(source);
|
||||
//console.log(source);
|
||||
|
||||
if(source.match(/larger than/))
|
||||
return e.reply("too large lol");
|
||||
@@ -115,17 +114,25 @@ export default async bot => {
|
||||
}
|
||||
|
||||
// check repost (checksum)
|
||||
const q_repostc = await sql.query("select id from items where checksum = ?", [ checksum ]);
|
||||
const q_repostc = await sql("items").select("id").where("checksum", checksum);
|
||||
if(q_repostc.length > 0)
|
||||
return e.reply(`repost motherf0cker (checksum): ${cfg.main.url}/${q_repostc[0].id}`);
|
||||
|
||||
await fs.promises.copyFile(`./tmp/${filename}`, `./public/b/${filename}`);
|
||||
await fs.promises.unlink(`./tmp/${filename}`).catch(_=>{});
|
||||
|
||||
const insertq = await sql.query(
|
||||
"insert into items (src, dest, mime, size, checksum, username, userchannel, usernetwork, stamp, active) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
[ e.photo ? "" : link, filename, mime, size, checksum, e.user.nick || e.user.username, e.channel, e.network, ~~(new Date() / 1000), 1 ]
|
||||
);
|
||||
const insertq = (await sql("items").insert({
|
||||
src: e.photo ? "" : link,
|
||||
dest: filename,
|
||||
mime: mime,
|
||||
size: size,
|
||||
checksum: checksum,
|
||||
username: e.user.nick || e.user.username,
|
||||
userchannel: e.channel,
|
||||
usernetwork: e.network,
|
||||
stamp: ~~(new Date() / 1000),
|
||||
active: 1
|
||||
}))[0];
|
||||
|
||||
// generate thumbnail
|
||||
try {
|
||||
@@ -134,17 +141,17 @@ export default async bot => {
|
||||
if(mime.startsWith("image") && mime !== "image/gif")
|
||||
thumb_orig = `./public/b/${filename}`;
|
||||
else if(!mime.startsWith("audio")) {
|
||||
await exec(`ffmpegthumbnailer -i./public/b/${filename} -s1024 -o./tmp/${insertq.insertId}`);
|
||||
thumb_orig = `./tmp/${insertq.insertId}`;
|
||||
await exec(`ffmpegthumbnailer -i./public/b/${filename} -s1024 -o./tmp/${insertq}`);
|
||||
thumb_orig = `./tmp/${insertq}`;
|
||||
}
|
||||
else if(mime.startsWith("audio")) {
|
||||
await exec(`ffmpeg -i ./public/b/${filename} -update 1 -map 0:v -map 0:1 -c copy ./tmp/${insertq.insertId}.png`)
|
||||
await exec(`cp ./tmp/${insertq.insertId}.png ./public/ca/${insertq.insertId}.png`)
|
||||
thumb_orig = `./tmp/${insertq.insertId}.png`;
|
||||
await exec(`ffmpeg -i ./public/b/${filename} -update 1 -map 0:v -map 0:1 -c copy ./tmp/${insertq}.png`)
|
||||
await exec(`cp ./tmp/${insertq}.png ./public/ca/${insertq}.png`)
|
||||
thumb_orig = `./tmp/${insertq}.png`;
|
||||
}
|
||||
}
|
||||
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(_=>{});
|
||||
await exec(`convert "${thumb_orig}" -resize "200x200^" -gravity center -crop 128x128+0+0 +repage ./public/t/${insertq}.png`);
|
||||
await fs.promises.unlink(`./tmp/${insertq}`).catch(_=>{});
|
||||
} catch(err) {
|
||||
e.reply("\x033>no thumb lol");
|
||||
console.error(err);
|
||||
@@ -155,8 +162,8 @@ export default async bot => {
|
||||
|
||||
e.reply([
|
||||
//`title: ${meta.fulltitle}`,
|
||||
`link: ${cfg.main.url}/${insertq.insertId} | size: ${lib.formatSize(size)} | speed: ${speed}`
|
||||
//`link: ${cfg.main.url}/${insertq.insertId}`
|
||||
`link: ${cfg.main.url}/${insertq} | size: ${lib.formatSize(size)} | speed: ${speed}`
|
||||
//`link: ${cfg.main.url}/${insertq}`
|
||||
]);
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user