diff --git a/youtubeapi/youtube.go b/youtubeapi/youtube.go index 256db65..e075260 100644 --- a/youtubeapi/youtube.go +++ b/youtubeapi/youtube.go @@ -81,6 +81,7 @@ type Youtube struct { executor cmd.CommandExecutor streamUrlTimeout time.Duration streamUrlExpireRegex *regexp.Regexp + ytdlpArgs []string } func NewYoutubeAPI() *Youtube { @@ -88,6 +89,7 @@ func NewYoutubeAPI() *Youtube { executor: &cmd.DefaultCommandExecutor{}, streamUrlTimeout: time.Second * 30, streamUrlExpireRegex: regexp.MustCompile("(expire)(\\/|=)(\\d+)(\\/|=|&|$)"), + ytdlpArgs: make([]string, 0), } return yt @@ -97,6 +99,10 @@ func (yt *Youtube) SetCmdExecutor(exec cmd.CommandExecutor) { yt.executor = exec } +func (yt *Youtube) SetYtDlpArgs(extraArgs []string) { + yt.ytdlpArgs = extraArgs +} + func (yt *Youtube) SearchYoutubeMedia(numSearchResults int, videoIdOrSearchTerm string) ([]*YoutubeMedia, error) { replacer := strings.NewReplacer( "\"", "", @@ -119,6 +125,10 @@ func (yt *Youtube) SearchYoutubeMedia(numSearchResults int, videoIdOrSearchTerm "--print-json", } + if len(yt.ytdlpArgs) > 0 { + args = append(args, yt.ytdlpArgs...) + } + stdout, err := yt.YtDlpExec(yt.streamUrlTimeout, args) if err != nil { @@ -205,6 +215,10 @@ func (yt *Youtube) GetYoutubeMedia(videoIdOrSearchTerm string) (*YoutubeMedia, e "--print-json", } + if len(yt.ytdlpArgs) > 0 { + args = append(args, yt.ytdlpArgs...) + } + stdout, err := yt.YtDlpExec(yt.streamUrlTimeout, args) if err != nil { @@ -255,6 +269,10 @@ func (yt *Youtube) GetYoutubePlaylist(playlistIdOrUrl string) (*YoutubePlaylist, "--flat-playlist", } + if len(yt.ytdlpArgs) > 0 { + args = append(args, yt.ytdlpArgs...) + } + stdout, err := yt.YtDlpExec(yt.streamUrlTimeout, args) if err != nil { @@ -304,6 +322,10 @@ func (yt *Youtube) ListFormats(videoIdOrUrl string) ([]*YtDlpVideoFormat, error) "--print-json", } + if len(yt.ytdlpArgs) > 0 { + args = append(args, yt.ytdlpArgs...) + } + stdout, err := yt.YtDlpExec(yt.streamUrlTimeout, args) if err != nil {