experimental instagram video download support #65

Merged
schrumpel merged 2 commits from dev into master 2024-02-19 19:59:14 +00:00
Showing only changes of commit 604e54f238 - Show all commits

View File

@ -12,7 +12,7 @@ const regex = {
all: /https?:\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?/gi, all: /https?:\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?/gi,
yt: /(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|watch\/?\?(?:\S*?&?v\=))|youtu\.be\/)([a-zA-Z0-9_-]{6,11})/gi, yt: /(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|watch\/?\?(?:\S*?&?v\=))|youtu\.be\/)([a-zA-Z0-9_-]{6,11})/gi,
imgur: /^https?:\/\/(\w+\.)?imgur.com\/(\w*\d\w*)+(\.[a-zA-Z]{3,4})?/gi, imgur: /^https?:\/\/(\w+\.)?imgur.com\/(\w*\d\w*)+(\.[a-zA-Z]{3,4})?/gi,
instagram: /^https?:\/\/(\w+\.)?instagram.com\/p\/(.*)\//gi instagram: /(?:https?:\/\/www\.)?instagram\.com\S*?\/(?:p|reel)\/(\w{11})\/?/im
}; };
const mediagroupids = new Set(); const mediagroupids = new Set();
@ -52,7 +52,10 @@ export default async bot => {
links.forEach(async link => { links.forEach(async link => {
if(regex.imgur.test(link)) if(regex.imgur.test(link))
await e.reply(`imgur detected?`); return await e.reply(`fuck imgur... seriously`);
if(regex.instagram.test(link))
await e.reply(`insta link`);
// check repost (link) // check repost (link)
repost = await queue.checkrepostlink(link); repost = await queue.checkrepostlink(link);
@ -66,9 +69,19 @@ export default async bot => {
// read metadata // read metadata
let ext; let ext;
if(regex.imgur.test(link)) if(regex.instagram.test(link))
ext = link.split('.').pop(); // is instagram
// blah? try {
// @flummi -> is there a variable for the actual work directory so it doesn't have to be hardcoded?
const meta = JSON.parse((await queue.exec(`yt-dlp --cookies /opt/f0ck/qutecookies.txt -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' --skip-download --dump-json "${link}"`)).stdout);
ext = meta.ext;
} catch(err) {
const tmphead = (await fetch(link, { method: "HEAD" })).headers["content-type"];
// this can be undefined for unsupported mime types, but will be caught in the general mime check below
ext = cfg.mimes[tmphead];
}
else {
// is not instagram
try { try {
const meta = JSON.parse((await queue.exec(`yt-dlp -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' --skip-download --dump-json "${link}"`)).stdout); const meta = JSON.parse((await queue.exec(`yt-dlp -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' --skip-download --dump-json "${link}"`)).stdout);
ext = meta.ext; ext = meta.ext;
@ -77,6 +90,7 @@ export default async bot => {
// this can be undefined for unsupported mime types, but will be caught in the general mime check below // this can be undefined for unsupported mime types, but will be caught in the general mime check below
ext = cfg.mimes[tmphead]; ext = cfg.mimes[tmphead];
} }
}
if(!Object.values(cfg.mimes).includes(ext?.toLowerCase())) { if(!Object.values(cfg.mimes).includes(ext?.toLowerCase())) {
return console.log('mime schmime ' + ext); return console.log('mime schmime ' + ext);
@ -89,30 +103,45 @@ export default async bot => {
// download data // download data
const start = new Date(); const start = new Date();
let source; let source;
if(regex.imgur.test(link))
try { try {
source = (await queue.exec(`wget "${link}" -o "/home/f0ck/f0ckv2/tmp/${uuid}.${ext}"`)).stdout.trim(); if(regex.instagram.test(link))
try {
console.log("insta link");
source = (await queue.exec(`yt-dlp --cookies /opt/f0ck/qutecookies.txt -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' "${link}" --max-filesize ${maxfilesize / 1024}k --postprocessor-args "ffmpeg:-bitexact" -o "./tmp/${uuid}.%(ext)s" --print after_move:filepath --merge-output-format "mp4"`)).stdout.trim();
} catch(err) { } catch(err) {
return await e.reply("fuck js"); if(e.type == 'tg')
return await e.editMessageText(msg.result.chat.id, msg.result.message_id, "instagram dl error");
return await e.reply("instagram dl error", err);
} }
else { else {
try { try {
source = (await queue.exec(`yt-dlp -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' "${link}" --max-filesize ${maxfilesize / 1024}k --postprocessor-args "ffmpeg:-bitexact" -o "./tmp/${uuid}.%(ext)s" --print after_move:filepath --merge-output-format "mp4"`)).stdout.trim(); source = (await queue.exec(`yt-dlp -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' "${link}" --max-filesize ${maxfilesize / 1024}k --postprocessor-args "ffmpeg:-bitexact" -o "./tmp/${uuid}.%(ext)s" --print after_move:filepath --merge-output-format "mp4"`)).stdout.trim();
} catch(err) { } catch(err) {
if(e.type == 'tg') if(e.type == 'tg')
return await e.editMessageText(msg.result.chat.id, msg.result.message_id, "something went wrong lol"); return await e.editMessageText(msg.result.chat.id, msg.result.message_id, err);
return await e.reply("something went wrong lol 1"); return await e.reply(err);
} }
} }
} catch(err) {
console.log(err);
}
// this is how it was before I fucked it up :>
// try {
// source = (await queue.exec(`yt-dlp -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' "${link}" --max-filesize ${maxfilesize / 1024}k --postprocessor-args "ffmpeg:-bitexact" -o "./tmp/${uuid}.%(ext)s" --print after_move:filepath --merge-output-format "mp4"`)).stdout.trim();
// } catch(err) {
// if(e.type == 'tg')
// return await e.editMessageText(msg.result.chat.id, msg.result.message_id, "something went wrong lol");
// return await e.reply("something went wrong lol");
// }
if(!source) { if(!source) {
if(e.type == 'tg') if(e.type == 'tg')
return await e.editMessageText(msg.result.chat.id, msg.result.message_id, "something went wrong lol"); return await e.editMessageText(msg.result.chat.id, msg.result.message_id, "something went wrong lol");
return await e.reply("something went wrong lol 2"); return await e.reply("something went wrong lol");
} }
console.log(typeof source)
if(source.match(/larger than/)) { if(source.match(/larger than/)) {
if(e.type == 'tg') if(e.type == 'tg')
return await e.editMessageText(msg.result.chat.id, msg.result.message_id, "too large lol"); return await e.editMessageText(msg.result.chat.id, msg.result.message_id, "too large lol");