Made it so that EngiBot doesn't try to upload non-video files or container formats that don't embed

This commit is contained in:
Logan G 2022-09-16 18:24:24 -06:00
parent 18a07ec828
commit a1330b3a33
Signed by: logan
GPG key ID: E328528C921E7A7A
3 changed files with 10 additions and 3 deletions

3
go.mod
View file

@ -5,11 +5,12 @@ go 1.18
require (
github.com/bwmarrin/discordgo v0.25.0
github.com/wader/goutubedl v0.0.0-20220629162042-a29fe0a651a9
golang.org/x/exp v0.0.0-20220916125017-b168a2c6b86b
mvdan.cc/xurls/v2 v2.4.0
)
require (
github.com/gorilla/websocket v1.4.2 // indirect
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
)

5
go.sum
View file

@ -15,10 +15,13 @@ github.com/wader/osleaktest v0.0.0-20191111175233-f643b0fed071 h1:QkrG4Zr5OVFuC9
github.com/wader/osleaktest v0.0.0-20191111175233-f643b0fed071/go.mod h1:XD6emOFPHVzb0+qQpiNOdPL2XZ0SRUM0N5JHuq6OmXo=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/exp v0.0.0-20220916125017-b168a2c6b86b h1:SCE/18RnFsLrjydh/R/s5EVvHoZprqEQUuoxK8q2Pc4=
golang.org/x/exp v0.0.0-20220916125017-b168a2c6b86b/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

View file

@ -7,8 +7,11 @@ import (
"errors"
"github.com/wader/goutubedl"
"golang.org/x/exp/slices"
)
var FileExtensions = []string {".webm",".mp4",".mkv"}
func getRedirectURL(input string) (string, error) {
request, err := http.NewRequest("GET", input, nil)
if err != nil {
@ -33,7 +36,7 @@ func getLargestFormat(input goutubedl.Result, sizeLimit float64) (format goutube
} else {
size = input.Formats()[i].Filesize
}
if size <= sizeLimit && input.Formats()[i].VCodec != "h265" { // Discord can't embed HEVC
if size <= sizeLimit && input.Formats()[i].VCodec != "h265" && slices.Contains(FileExtensions, input.Formats()[i].Ext) { // Discord can't embed HEVC
return input.Formats()[i], nil
}
}