WIP: refactor and release v1 #30
27
app/ytdlp.go
27
app/ytdlp.go
@@ -1,12 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
"fmt"
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/lrstanley/go-ytdlp"
|
||||
)
|
||||
func downloadVideo(out_dir, url string) {
|
||||
|
||||
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").
|
||||
@@ -20,7 +27,19 @@ func downloadVideo(out_dir, url string) {
|
||||
prog.Filename,
|
||||
)
|
||||
}).
|
||||
Output("%(extractor)s - %(title)s.%(ext)s")
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user