WIP: refactor and release v1 #30

Draft
williamp wants to merge 16 commits from v1-refactor into master
Showing only changes of commit b5642456c2 - Show all commits

View File

@@ -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,7 +27,19 @@ func downloadVideo(out_dir, url string) {
prog.Filename, 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) _, err := dl.Run(context.TODO(), url)
if err != nil { if err != nil {