add options for downloads
This commit is contained in:
35
app/ytdlp.go
35
app/ytdlp.go
@@ -1,12 +1,19 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
"fmt"
|
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/lrstanley/go-ytdlp"
|
"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().
|
dl := ytdlp.New().
|
||||||
SetWorkDir(out_dir).
|
SetWorkDir(out_dir).
|
||||||
FormatSort("res,ext:mp4:m4a").
|
FormatSort("res,ext:mp4:m4a").
|
||||||
@@ -20,10 +27,22 @@ func downloadVideo(out_dir, url string) {
|
|||||||
prog.Filename,
|
prog.Filename,
|
||||||
)
|
)
|
||||||
}).
|
}).
|
||||||
Output("%(extractor)s - %(title)s.%(ext)s")
|
Output("%(title)s.%(ext)s")
|
||||||
|
|
||||||
_, err := dl.Run(context.TODO(), url)
|
if opts.EmbedThumbnail {
|
||||||
if err != nil {
|
dl = dl.EmbedThumbnail()
|
||||||
panic(err)
|
}
|
||||||
}
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user