fix: instagram && tiktok downloader
This commit is contained in:
+22
-16
@@ -7,7 +7,6 @@ import (
|
|||||||
"neo/api"
|
"neo/api"
|
||||||
hc "neo/context"
|
hc "neo/context"
|
||||||
"neo/core"
|
"neo/core"
|
||||||
"neo/helper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type instagramVideo struct {
|
type instagramVideo struct {
|
||||||
@@ -47,23 +46,30 @@ var Instagram = &core.Command{
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
mediaURL := ""
|
for _, video := range res.Videos {
|
||||||
if len(res.Videos) > 0 {
|
data, _, err := api.Download(video.Src)
|
||||||
mediaURL = res.Videos[0].Src
|
if err != nil {
|
||||||
} else if len(res.Images) > 0 {
|
ctx.Reply(fmt.Sprintf("Download failed: %v", err))
|
||||||
mediaURL = res.Images[0]
|
return
|
||||||
}
|
}
|
||||||
if mediaURL == "" {
|
// if i == 0 {
|
||||||
ctx.Reply("No media found")
|
// ctx.SendVideo(data, fmt.Sprintf("Instagram Video\n%s", url))
|
||||||
return
|
// } else {
|
||||||
|
ctx.SendVideo(data, "")
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
data, mime, err := api.Download(mediaURL)
|
for _, imgURL := range res.Images {
|
||||||
if err != nil {
|
data, _, err := api.Download(imgURL)
|
||||||
ctx.Reply(fmt.Sprintf("Download failed: %v", err))
|
if err != nil {
|
||||||
return
|
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"
|
"neo/api"
|
||||||
hc "neo/context"
|
hc "neo/context"
|
||||||
"neo/core"
|
"neo/core"
|
||||||
"neo/helper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type tiktokResult struct {
|
type tiktokResult struct {
|
||||||
@@ -31,7 +30,7 @@ var TikTok = &core.Command{
|
|||||||
return
|
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) {
|
if !ttRegex.MatchString(url) {
|
||||||
ctx.Reply("Invalid TikTok URL")
|
ctx.Reply("Invalid TikTok URL")
|
||||||
return
|
return
|
||||||
@@ -44,24 +43,28 @@ var TikTok = &core.Command{
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
mediaURL := ""
|
caption := fmt.Sprintf("@%s\n%s", res.Username, res.Description)
|
||||||
if len(res.VideoURL) > 0 {
|
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 {
|
} else if len(res.ImageURL) > 0 {
|
||||||
mediaURL = res.ImageURL[0]
|
go func() {
|
||||||
}
|
for _, imgURL := range res.ImageURL {
|
||||||
if mediaURL == "" {
|
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")
|
ctx.Reply("No media found")
|
||||||
return
|
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