From 128a5d6fb2d09718f95d9238fc438a1cbee6e328 Mon Sep 17 00:00:00 2001 From: MasedMSD <68379695+MasedMSD@users.noreply.github.com> Date: Sat, 2 Nov 2024 23:48:40 +0500 Subject: [PATCH] yt-dlp for tiktok --- bun.lockb | Bin 30901 -> 31255 bytes package.json | 3 +- src/handlers/index.ts | 1 + src/handlers/ytdl.composer.ts | 61 ++++++++++++++++++++++++++++++++++ src/structures/client.ts | 2 ++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/handlers/ytdl.composer.ts diff --git a/bun.lockb b/bun.lockb index 529b809bd66dc173b5cc826848fc4cee0e90d63e..038d50b2c51226006ea6dc000b98f64512a10b58 100644 GIT binary patch delta 4859 zcmeHLdvH|M8NcTyo9sCL0rZ&-P+yNj_b`p9QXx7k|u-h12upSfwDYJ zmLvtVqjy8!#;)E?1fJ#ZfU@1zwoP3FU6NEB_7jUC*mR~C$wX0`?jv`jnWugvHlZmkk@_-l;?k` zr!8`t&zBO4AQIt!M%LH9?c1EKNQB#9&#Rds!L%WOc*qo+s!Y~?hGSIm3I!p`kSQ+KE!L4IRuzY77{4D=FjkcdqbN@AR(8TyDctI4G}bAeq+z`( zOVM-=s%o@FB~($A6ytv&~&|1`3X4Qn@-Ebo8+0S%9#clnd}xvC^%VF zUP8;SfdRsZb1HMuPaG7?^-j@G!%3<*M!_UZN~E}Cx7bIXWL5byI)c{-r7C+eor7u@ zDJiP>D|u2>B^`YljtI5sq+p7wdmOT5bRoqhJ|T}$l@}({h|w+Xrl3*PJ%_G_(&&=) zDO8^7)-6I$7SmpXOYEg!s;Z2G=RlAZgk?eVFVS|L6zf!)z;We5x(C4Jg*FG>_?Nm- zgHuUGXLHX8Vy+e(M>~aTQ=H<*6iidaWl~J4JZTD*o80o!DKuhoi#-%Hsp45u%&Huf zM&;&(KE%SewKgVF9Bh1pO5E#MSsP55$6cZgrfi3UK%*v2DoITF{;-63raW(Yn5Kv2 zpzE|t7Vv~jfE~^Pcrax?iy4fG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(WZac)GVph$w>eEq~o=IrG88U;!Mv>L zX?K;bK27r~`4($l*}uW`G@=uA94u+e`Q*xrdN=!#5V*N2(lfbb<%31{ymK;B@qK6O zm5b0kgnkkZCX}K8b`R?VRir823wq5I)OqQQ?Ir+vQ=*qSxM@>4bfb#kbOMfK~R7F8w%y{0pIeSZ1g-~Oue zlh;fXO}MhOLAkltRJ-L?jEY{uZ(sCkP#f;P!?w~cQ;!_(b>l$(E5_RY&ghly6HoRs%V+_4Fi { + // if (ctx.chatId !== -1001705068191) return; + + const url = ctx.match[0]; + const metadata = await ytDlpWrap.getVideoInfo(url); + + console.log(metadata); + + const formattedMetadata = metadata + ? [ + `Название: ${metadata.title}\n`, + `Количество просмотров: ${metadata.view_count}`, + `Количество лайков: ${metadata.like_count}`, + `Количество комментариев: ${metadata.comment_count}`, + `Количество репостов: ${metadata.repost_count}`, + ].join("\n") + : "Метаданные видео недоступны"; + + const stream = ytDlpWrap.execStream([url]); + const tempFilePath = join(tmpdir(), `download-${Date.now()}.mp4`); + const fileStream = createWriteStream(tempFilePath); + + stream.pipe(fileStream); + + fileStream.on("finish", async () => { + await ctx.replyWithVideo(new InputFile(tempFilePath), { + caption: formattedMetadata, + parse_mode: "HTML", + reply_markup: { + inline_keyboard: [ + [ + { + text: "Автор", + url: metadata.uploader_url, + }, + { + text: "Ссылка на видео", + url, + }, + ], + ], + }, + }); + + unlink(tempFilePath, err => { + if (err) console.error(`Не удалось удалить файл ${tempFilePath}`, err); + }); + }); + } +); diff --git a/src/structures/client.ts b/src/structures/client.ts index 569745a..b58703d 100644 --- a/src/structures/client.ts +++ b/src/structures/client.ts @@ -10,6 +10,7 @@ import { randomEmojiComposer, startCommand, telegraphComposer, + YTDLComposer, } from "../handlers"; import { Database } from "./database"; @@ -62,6 +63,7 @@ export class Client { this.bot.use(msdIncorporatedComposer); this.bot.use(randomEmojiComposer); this.bot.use(telegraphComposer); + this.bot.use(YTDLComposer); this.bot.command("eval", evalCommand); this.bot.command("exec", execCommand);