fix: instagram && tiktok downloader
This commit is contained in:
+22
-16
@@ -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, "")
|
||||
},
|
||||
}
|
||||
|
||||
+19
-16
@@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user