From 2b2fe45be84abb242a5c08f97390b5a378cd2c0f Mon Sep 17 00:00:00 2001 From: Flummi Date: Tue, 20 Feb 2024 17:46:41 +0100 Subject: [PATCH 1/3] imgur schmimgur --- src/inc/trigger/parser.mjs | 93 ++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/src/inc/trigger/parser.mjs b/src/inc/trigger/parser.mjs index b940eff..b44427d 100644 --- a/src/inc/trigger/parser.mjs +++ b/src/inc/trigger/parser.mjs @@ -11,7 +11,7 @@ import path from "path"; const regex = { 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, - imgur: /^https?:\/\/(\w+\.)?imgur.com\/(\w*\d\w*)+(\.[a-zA-Z]{3,4})?/gi, + imgur: /(?:https?:)?\/\/(\w+\.)?imgur\.com\/(\S*)(\.[a-zA-Z]{3,4})/gi, instagram: /(?:https?:\/\/www\.)?instagram\.com\S*?\/(?:p|reel)\/(\w{11})\/?/im }; const mediagroupids = new Set(); @@ -51,8 +51,8 @@ export default async bot => { console.log(`parsing ${links.length} link${links.length > 1 ? "s" : ""}...`); links.forEach(async link => { - if(regex.imgur.test(link)) - return await e.reply(`fuck imgur... seriously`); + //if(regex.imgur.test(link)) + // return await e.reply(`fuck imgur... seriously`); if(regex.instagram.test(link)) return await e.reply(`fuck instagram... seriously`); @@ -69,16 +69,22 @@ export default async bot => { // read metadata let ext; - if(regex.instagram.test(link)) - // is instagram - 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 -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]; + if(link.match(regex.instagram)) { + // is instagram + 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 -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 if(link.match(regex.imgur)) { + // imghure + ext = link.split('.').pop(); + await e.reply(`extension: ${ext}`); } else { // is not instagram @@ -100,42 +106,43 @@ export default async bot => { disable_notification: true }); - // download data + // const start = new Date(); let source; - try { - if(regex.instagram.test(link)) - try { - // add --cookies on local instance if you want to avoid getting rate limited - 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, "instagram dl error"); - return await e.reply("instagram dl error", err); - } - else { - 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, err); - return await e.reply(err); - } + if(link.match(regex.instagram)) { + try { + // add --cookies on local instance if you want to avoid getting rate limited + 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, "instagram dl error"); + return await e.reply("instagram dl error", err); } - } catch(err) { - console.log(err); } + else if(link.match(regex.imgur)) { + // imghure via torsocks + try { + await queue.exec(`torsocks wget ${link} -O ./tmp/${uuid}.${ext}`); + source = `./tmp/${uuid}.${ext}`; + } catch(err) { + console.error('err:', err); + if(e.type == 'tg') + return await e.editMessageText(msg.result.chat.id, msg.result.message_id, err); + return await e.reply(err); + } + } + else { + 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, err); + return await e.reply(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(e.type == 'tg') return await e.editMessageText(msg.result.chat.id, msg.result.message_id, "something went wrong lol"); -- 2.45.2 From c2e9922ae9f92afadd8f213ea0a4ba21293ddb6e Mon Sep 17 00:00:00 2001 From: Abu Ottermann Date: Tue, 20 Feb 2024 20:51:29 +0100 Subject: [PATCH 2/3] debugmeldung entfernen --- src/inc/trigger/parser.mjs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/inc/trigger/parser.mjs b/src/inc/trigger/parser.mjs index b44427d..1f1a88d 100644 --- a/src/inc/trigger/parser.mjs +++ b/src/inc/trigger/parser.mjs @@ -84,7 +84,6 @@ export default async bot => { else if(link.match(regex.imgur)) { // imghure ext = link.split('.').pop(); - await e.reply(`extension: ${ext}`); } else { // is not instagram -- 2.45.2 From 7844bc8b63b81ec0225e5e890751643ca8c49707 Mon Sep 17 00:00:00 2001 From: Abu Ottermann Date: Tue, 20 Feb 2024 21:06:47 +0100 Subject: [PATCH 3/3] blah --- src/inc/trigger/parser.mjs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/inc/trigger/parser.mjs b/src/inc/trigger/parser.mjs index 1f1a88d..02051ba 100644 --- a/src/inc/trigger/parser.mjs +++ b/src/inc/trigger/parser.mjs @@ -11,7 +11,7 @@ import path from "path"; const regex = { 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, - imgur: /(?:https?:)?\/\/(\w+\.)?imgur\.com\/(\S*)(\.[a-zA-Z]{3,4})/gi, + imgur: /(?:https?:)?\/\/(\w+\.)?imgur\.com\/(\S*)(\.[a-zA-Z].{3,4})/i, instagram: /(?:https?:\/\/www\.)?instagram\.com\S*?\/(?:p|reel)\/(\w{11})\/?/im }; const mediagroupids = new Set(); @@ -128,16 +128,17 @@ export default async bot => { console.error('err:', err); if(e.type == 'tg') return await e.editMessageText(msg.result.chat.id, msg.result.message_id, err); - return await e.reply(err); + return await e.reply('something went wrong lol'); } } else { 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) { + console.error('err:', err); if(e.type == 'tg') return await e.editMessageText(msg.result.chat.id, msg.result.message_id, err); - return await e.reply(err); + return await e.reply('something went wrong lol'); } } // -- 2.45.2