add meme command.

meme command takes in a video url, then downloads the video with yt-dlp and moves it to the folder that docker maps to public/uploads and replies with a url to it
This commit is contained in:
lyx0 2023-12-19 22:53:42 +01:00
parent 5c70be6d94
commit 4422e49ea0
4 changed files with 65 additions and 3 deletions

View file

@ -222,6 +222,11 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
app.ConvertToMP4(cmdParams[1], message)
}
case "meme":
if userLevel >= 100 {
app.ConvertAndSave(cmdParams[1], cmdParams[2], message)
}
case "set":
switch cmdParams[1] {
case "lastfm":

View file

@ -35,6 +35,59 @@ func (app *application) NewDownload(destination, target, link string, msg twitch
app.GofileDownload(target, link, identifier, msg)
}
}
func (app *application) ConvertAndSave(fName, link string, msg twitch.PrivateMessage) {
goutubedl.Path = "yt-dlp"
uuid_og := uuid.NewString()
app.Send(msg.Channel, "Downloading... dankCircle", msg)
result, err := goutubedl.New(context.Background(), link, goutubedl.Options{})
if err != nil {
app.Log.Errorln(err)
app.Send(msg.Channel, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err), msg)
return
}
rExt := result.Info.Ext
downloadResult, err := result.Download(context.Background(), "best")
if err != nil {
app.Log.Errorln(err)
app.Send(msg.Channel, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err), msg)
return
}
//app.Send(target, "Downloaded.", msg)
fileName := fmt.Sprintf("%s.%s", uuid_og, rExt)
f, err := os.Create(fileName)
//app.Send(target, fmt.Sprintf("Filename: %s", fileName), msg)
if err != nil {
app.Log.Errorln(err)
app.Send(msg.Channel, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err), msg)
return
}
defer f.Close()
if _, err = io.Copy(f, downloadResult); err != nil {
app.Log.Errorln(err)
app.Send(msg.Channel, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err), msg)
return
}
downloadResult.Close()
f.Close()
out := fmt.Sprintf("/public/uploads/%s.mp4", fName)
fn, err := os.Create(out)
if err != nil {
app.Log.Errorln(err)
app.Send(msg.Channel, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err), msg)
return
}
defer fn.Close()
err = ffmpeg.Input(fileName).
Output(out).
OverWriteOutput().ErrorToStdOut().Run()
app.Send(msg.Channel, fmt.Sprintf("https://bot.noury.is/uploads/%s.mp4", fName), msg)
}
func (app *application) ConvertToMP4(link string, msg twitch.PrivateMessage) {
goutubedl.Path = "yt-dlp"
uuid_og := uuid.NewString()
@ -72,7 +125,9 @@ func (app *application) ConvertToMP4(link string, msg twitch.PrivateMessage) {
downloadResult.Close()
f.Close()
fn, err := os.Create("output.mp4")
out := "/public/uploads/output.mp4"
fn, err := os.Create(out)
if err != nil {
app.Log.Errorln(err)
app.Send(msg.Channel, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err), msg)
@ -81,10 +136,10 @@ func (app *application) ConvertToMP4(link string, msg twitch.PrivateMessage) {
defer fn.Close()
err = ffmpeg.Input(fileName).
Output("output.mp4").
Output(out).
OverWriteOutput().ErrorToStdOut().Run()
go app.NewUpload("yaf", "output.mp4", msg.Channel, uuid_new, msg)
go app.NewUpload("yaf", out, msg.Channel, uuid_new, msg)
}
func (app *application) YafDownload(target, link, identifier string, msg twitch.PrivateMessage) {

View file

@ -14,6 +14,8 @@ services:
context: .
dockerfile: Dockerfile
env_file: .env
volumes:
- "./public/uploads:/public/uploads"
ports:
- "127.0.0.1:42069:8080"
depends_on:

0
public/uploads/.gitkeep Normal file
View file