From 38773e31fce1be7ff001b980fa7c62f57e40e6b7 Mon Sep 17 00:00:00 2001 From: Fdvkey Date: Fri, 17 Jul 2026 22:50:36 +0700 Subject: [PATCH] fix: instagram && tiktok downloader --- cmds/download/instagram.go | 38 ++++++++++++++++++++++---------------- cmds/download/tiktok.go | 35 +++++++++++++++++++---------------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/cmds/download/instagram.go b/cmds/download/instagram.go index ac48bab..9e22587 100644 --- a/cmds/download/instagram.go +++ b/cmds/download/instagram.go @@ -7,7 +7,6 @@ import ( "neo/api" hc "neo/context" "neo/core" - "neo/helper" ) type instagramVideo struct { @@ -47,23 +46,30 @@ var Instagram = &core.Command{ return } - mediaURL := "" - if len(res.Videos) > 0 { - mediaURL = res.Videos[0].Src - } else if len(res.Images) > 0 { - mediaURL = res.Images[0] - } - if mediaURL == "" { - ctx.Reply("No media found") - return + for _, video := range res.Videos { + data, _, err := api.Download(video.Src) + if err != nil { + ctx.Reply(fmt.Sprintf("Download failed: %v", err)) + return + } + // if i == 0 { + // ctx.SendVideo(data, fmt.Sprintf("Instagram Video\n%s", url)) + // } else { + ctx.SendVideo(data, "") + // } } - data, mime, err := api.Download(mediaURL) - if err != nil { - ctx.Reply(fmt.Sprintf("Download failed: %v", err)) - return + for _, imgURL := range res.Images { + data, _, err := api.Download(imgURL) + if err != nil { + ctx.Reply(fmt.Sprintf("Download failed: %v", err)) + return + } + // if i == 0 { + // ctx.SendImage(data, fmt.Sprintf("Instagram Image\n%s", url)) + // } else { + ctx.SendImage(data, "") + // } } - - helper.SendMedia(ctx, data, mime, "") }, } diff --git a/cmds/download/tiktok.go b/cmds/download/tiktok.go index 77a21fb..9980e7e 100644 --- a/cmds/download/tiktok.go +++ b/cmds/download/tiktok.go @@ -7,7 +7,6 @@ import ( "neo/api" hc "neo/context" "neo/core" - "neo/helper" ) type tiktokResult struct { @@ -31,7 +30,7 @@ var TikTok = &core.Command{ return } - ttRegex := regexp.MustCompile(`(?i)(?:tiktok\.com)\/(?:@[\w.-]+\/video\/|v\/|t\/)([0-9]+)`) + ttRegex := regexp.MustCompile(`(?i)^https?://(?:[\w-]+\.)?tiktok\.com(?:/.*)?$`) if !ttRegex.MatchString(url) { ctx.Reply("Invalid TikTok URL") return @@ -44,24 +43,28 @@ var TikTok = &core.Command{ return } - mediaURL := "" + caption := fmt.Sprintf("@%s\n%s", res.Username, res.Description) if len(res.VideoURL) > 0 { - mediaURL = res.VideoURL[0] + data, _, err := api.Download(res.VideoURL[0]) + if err != nil { + ctx.Reply(fmt.Sprintf("Download failed: %v", err)) + return + } + ctx.SendVideo(data, caption) } else if len(res.ImageURL) > 0 { - mediaURL = res.ImageURL[0] - } - if mediaURL == "" { + go func() { + for _, imgURL := range res.ImageURL { + data, _, err := api.Download(imgURL) + if err != nil { + ctx.Reply(fmt.Sprintf("Download failed: %v", err)) + return + } + ctx.SendImage(data, caption) + } + }() + } else { ctx.Reply("No media found") return } - - data, mime, err := api.Download(mediaURL) - if err != nil { - ctx.Reply(fmt.Sprintf("Download failed: %v", err)) - return - } - - caption := fmt.Sprintf("@%s\n%s", res.Username, res.Description) - helper.SendMedia(ctx, data, mime, caption) }, }