Compare commits
4 commits
186d3b3069
...
c5015145b2
Author | SHA1 | Date | |
---|---|---|---|
c5015145b2 | |||
f5afb11f90 | |||
ef82200046 | |||
b18f850114 |
2 changed files with 39 additions and 2 deletions
|
@ -33,7 +33,7 @@ func getLargestFormat(input goutubedl.Result, sizeLimit float64) (format goutube
|
||||||
} else {
|
} else {
|
||||||
size = input.Formats()[i].Filesize
|
size = input.Formats()[i].Filesize
|
||||||
}
|
}
|
||||||
if size <= sizeLimit {
|
if size <= sizeLimit && input.Formats()[i].VCodec != "h265" { // Discord can't embed HEVC
|
||||||
return input.Formats()[i], nil
|
return input.Formats()[i], nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,7 @@ func messageCreate(session *discordgo.Session, message *discordgo.MessageCreate)
|
||||||
choice, err := getLargestFormat(result, 8*1024*1024)
|
choice, err := getLargestFormat(result, 8*1024*1024)
|
||||||
log.Printf("Choice: %s | Size: %fM\n", choice.FormatID, choice.FilesizeApprox/1024/1024)
|
log.Printf("Choice: %s | Size: %fM\n", choice.FormatID, choice.FilesizeApprox/1024/1024)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
session.ChannelTyping(message.ChannelID)
|
||||||
downloadResult, err := result.Download(context.Background(), choice.FormatID)
|
downloadResult, err := result.Download(context.Background(), choice.FormatID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
@ -116,6 +117,7 @@ func messageCreate(session *discordgo.Session, message *discordgo.MessageCreate)
|
||||||
choice, err := getLargestYTFormat(result, 8*1024*1024)
|
choice, err := getLargestYTFormat(result, 8*1024*1024)
|
||||||
log.Printf("Choice: %s | Size: %fM\n", choice.FormatID, choice.FilesizeApprox/1024/1024)
|
log.Printf("Choice: %s | Size: %fM\n", choice.FormatID, choice.FilesizeApprox/1024/1024)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
session.ChannelTyping(message.ChannelID)
|
||||||
downloadResult, err := result.Download(context.Background(), choice.FormatID)
|
downloadResult, err := result.Download(context.Background(), choice.FormatID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -148,7 +150,8 @@ func messageCreate(session *discordgo.Session, message *discordgo.MessageCreate)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
downloadResult, err := result.Download(context.Background(), result.Formats()[0].FormatID) // Insta only has one possible format to download :(
|
session.ChannelTyping(message.ChannelID)
|
||||||
|
downloadResult, err := result.Download(context.Background(), "best") // Insta only has one possible format to download :(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
continue
|
continue
|
||||||
|
@ -181,6 +184,40 @@ func messageCreate(session *discordgo.Session, message *discordgo.MessageCreate)
|
||||||
downloadResult.Close()
|
downloadResult.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
respond = true
|
||||||
|
} else if output, _ := regexp.MatchString("(http.*tiktok\\.com/\\@.*)", url); output {
|
||||||
|
log.Println("TikTok detected.")
|
||||||
|
|
||||||
|
response.Content = response.Content + fmt.Sprintf("\n<%s>", regexp.MustCompile("http.*tiktok\\.com").ReplaceAllString(url, "https://proxitok.pussthecat.org"))
|
||||||
|
|
||||||
|
result, err := goutubedl.New(context.Background(), url, goutubedl.Options{})
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
choice, err := getLargestFormat(result, 8*1024*1024)
|
||||||
|
log.Printf("Choice: %s | Size: %fM\n", choice.FormatID, choice.Filesize/1024/1024)
|
||||||
|
if err == nil {
|
||||||
|
session.ChannelTyping(message.ChannelID)
|
||||||
|
downloadResult, err := result.Download(context.Background(), choice.FormatID)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
//session.ChannelMessageSend(message.ChannelID, err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Files = append(response.Files, &discordgo.File {
|
||||||
|
Name: fmt.Sprintf("%s.%s", result.Info.ID, choice.Ext),
|
||||||
|
ContentType: "text/plain", // This is of course not true, but Discord doesn't give a shit
|
||||||
|
Reader: downloadResult,
|
||||||
|
})
|
||||||
|
|
||||||
|
defer downloadResult.Close()
|
||||||
|
} else {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
respond = true
|
respond = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue