youtube-dl
This commit is contained in:
parent
2a10fd2e93
commit
de0a0e2303
|
@ -48,25 +48,23 @@ export default async bot => {
|
||||||
let meta;
|
let meta;
|
||||||
// read metadata
|
// read metadata
|
||||||
try {
|
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-dl -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/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) {
|
catch(e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const filename = `${uuid}.${meta.ext}`;
|
let filename = `${uuid}.${meta.ext}`;
|
||||||
|
|
||||||
e.reply(`downloading ${filename}...`);
|
e.reply(`downloading ${uuid}...`);
|
||||||
|
|
||||||
// download data
|
// download data
|
||||||
const start = new Date();
|
const start = new Date();
|
||||||
//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;
|
let source;
|
||||||
if(meta.ext === "mp4")
|
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();
|
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();
|
||||||
else
|
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();
|
source = (await exec(`youtube-dl "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" -o ./tmp/${filename}`)).stdout.trim();
|
||||||
|
|
||||||
if(source.match(/larger than/))
|
if(source.match(/larger than/))
|
||||||
return e.reply("too large lol");
|
return e.reply("too large lol");
|
||||||
|
@ -80,6 +78,29 @@ export default async bot => {
|
||||||
const mime = (await exec(`file --mime-type -b ./tmp/${filename}`)).stdout.trim();
|
const mime = (await exec(`file --mime-type -b ./tmp/${filename}`)).stdout.trim();
|
||||||
if(!cfg.allowed.includes(mime))
|
if(!cfg.allowed.includes(mime))
|
||||||
return e.reply(`lol, go f0ck yourself (${mime})`);
|
return e.reply(`lol, go f0ck yourself (${mime})`);
|
||||||
|
|
||||||
|
if(!cfg.ext.includes(meta.ext)) {
|
||||||
|
let tmpext = "";
|
||||||
|
if(mime === "image/png")
|
||||||
|
tmpext = "png";
|
||||||
|
else if(mime === "video/webm")
|
||||||
|
tmpext = "webm";
|
||||||
|
else if(mime === "image/gif")
|
||||||
|
tmpext = "gif";
|
||||||
|
else if(mime === "image/jpeg")
|
||||||
|
tmpext = "jpg";
|
||||||
|
else if(mime === "video/mp4" || mime === "video/quicktime")
|
||||||
|
tmpext = "mp4";
|
||||||
|
else if(mime === "audio/mpeg")
|
||||||
|
tmpext = "mp3";
|
||||||
|
else if(mime === "audio/ogg")
|
||||||
|
tmpext = "ogg";
|
||||||
|
else if(mime === "audio/flac" || mime === "audio/x-flac")
|
||||||
|
tmpext = "flac";
|
||||||
|
|
||||||
|
fs.renameSync(`./tmp/${filename}`, `./tmp/${uuid}.${tmpext}`);
|
||||||
|
filename = `${uuid}.${tmpext}`;
|
||||||
|
}
|
||||||
|
|
||||||
// check repost (checksum)
|
// check repost (checksum)
|
||||||
const q_repostc = await sql.query("select id from items where checksum = ?", [ checksum ]);
|
const q_repostc = await sql.query("select id from items where checksum = ?", [ checksum ]);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user