Files
yt-dlp-bot/app/ytdlp.go
2026-01-22 23:11:59 -05:00

49 lines
868 B
Go

package main
import (
"context"
"fmt"
"time"
"github.com/lrstanley/go-ytdlp"
)
type DownloadOptions struct {
EmbedThumbnail bool
IncludeSubtitles bool
}
func downloadVideo(out_dir, url string, opts DownloadOptions) {
dl := ytdlp.New().
SetWorkDir(out_dir).
FormatSort("res,ext:mp4:m4a").
RecodeVideo("mp4").
ProgressFunc(100*time.Millisecond, func(prog ytdlp.ProgressUpdate) {
fmt.Printf(
"%s @ %s [eta: %s] :: %s\n",
prog.Status,
prog.PercentString(),
prog.ETA(),
prog.Filename,
)
}).
Output("%(title)s.%(ext)s")
if opts.EmbedThumbnail {
dl = dl.EmbedThumbnail()
}
if opts.IncludeSubtitles {
dl = dl.CompatOptions("no-keep-subs")
dl = dl.EmbedSubs()
dl = dl.SubLangs("en,en*")
dl = dl.WriteAutoSubs()
dl = dl.WriteSubs()
}
_, err := dl.Run(context.TODO(), url)
if err != nil {
panic(err)
}
}