add dl command to download videos with yt-dlp

This commit is contained in:
lyx0 2023-09-27 16:44:42 +02:00
parent f2d95ac9c6
commit 67e7a2e655
5 changed files with 50 additions and 2 deletions

View file

@ -83,6 +83,9 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
reply, _ = commands.Currency(cmdParams[1], cmdParams[2], cmdParams[4])
}
case "dl":
reply, _ = app.Download(target, cmdParams[1])
case "mail":
app.SendEmail("Test command used!", "This is an email test")

38
cmd/nourybot/download.go Normal file
View file

@ -0,0 +1,38 @@
package main
import (
"context"
"io"
"os"
"os/exec"
"github.com/wader/goutubedl"
)
func (app *application) Download(channel, link string) (string, error) {
goutubedl.Path = "yt-dlp"
app.Send(channel, "dankCircle")
result, err := goutubedl.New(context.Background(), link, goutubedl.Options{})
if err != nil {
app.Log.Fatal(err)
}
downloadResult, err := result.Download(context.Background(), "best")
if err != nil {
app.Log.Fatal(err)
}
defer downloadResult.Close()
f, err := os.Create("output.mp4")
if err != nil {
app.Log.Fatal(err)
}
defer f.Close()
io.Copy(f, downloadResult)
out, err := exec.Command("curl", "-L", "-F", "file=@output.mp4", "i.yaf.ee/upload").Output()
if err != nil {
app.Log.Fatal(err)
}
return string(out), nil
}

View file

@ -47,12 +47,14 @@ func (app *application) checkMessage(text string) (bool, string) {
"message": text,
})
if err != nil {
log.Fatal(err)
app.Log.Error(err)
return true, "could not check banphrase api"
}
resp, err := http.Post(banPhraseUrl, "application/json", bytes.NewBuffer(reqBody))
if err != nil {
log.Panic(err)
app.Log.Error(err)
return true, "could not check banphrase api"
}
defer resp.Body.Close()

1
go.mod
View file

@ -14,6 +14,7 @@ require (
)
require (
github.com/wader/goutubedl v0.0.0-20230924165737-427b7fa536e6 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect

4
go.sum
View file

@ -7,6 +7,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/gempir/go-twitch-irc/v4 v4.0.0 h1:sHVIvbWOv9nHXGEErilclxASv0AaQEr/r/f9C0B9aO8=
github.com/gempir/go-twitch-irc/v4 v4.0.0/go.mod h1:QsOMMAk470uxQ7EYD9GJBGAVqM/jDrXBNbuePfTauzg=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
@ -36,6 +37,9 @@ github.com/shkh/lastfm-go v0.0.0-20191215035245-89a801c244e0/go.mod h1:n3nudMl17
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/wader/goutubedl v0.0.0-20230924165737-427b7fa536e6 h1:KHJV3fnnKsdWdGu5IKrDAA0Oa5RzGwrJpfx+bvVAjLA=
github.com/wader/goutubedl v0.0.0-20230924165737-427b7fa536e6/go.mod h1:5KXd5tImdbmz4JoVhePtbIokCwAfEhUVVx3WLHmjYuw=
github.com/wader/osleaktest v0.0.0-20191111175233-f643b0fed071/go.mod h1:XD6emOFPHVzb0+qQpiNOdPL2XZ0SRUM0N5JHuq6OmXo=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=