Unexport the Options.noInfoDownload field
There is a package Download() function now which handle downloading without using the Info struct so this field no longer needs to be exported.
This commit is contained in:
14
goutubedl.go
14
goutubedl.go
@ -215,8 +215,8 @@ type Options struct {
|
|||||||
SortingFormat string // --format-sort
|
SortingFormat string // --format-sort
|
||||||
|
|
||||||
// Set to true if you don't want to use the result.Info structure after the goutubedl.New() call,
|
// Set to true if you don't want to use the result.Info structure after the goutubedl.New() call,
|
||||||
// so the given URL will be downloaded in a single pass in the Download() call.
|
// so the given URL will be downloaded in a single pass in the DownloadResult.Download() call.
|
||||||
NoInfoDownload bool
|
noInfoDownload bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version of youtube-dl.
|
// Version of youtube-dl.
|
||||||
@ -234,7 +234,7 @@ func Version(ctx context.Context) (string, error) {
|
|||||||
// Downloads given URL using the given options and filter (usually a format id or quality designator).
|
// Downloads given URL using the given options and filter (usually a format id or quality designator).
|
||||||
// If filter is empty, then youtube-dl will use its default format selector.
|
// If filter is empty, then youtube-dl will use its default format selector.
|
||||||
func Download(ctx context.Context, rawURL string, options Options, filter string) (*DownloadResult, error) {
|
func Download(ctx context.Context, rawURL string, options Options, filter string) (*DownloadResult, error) {
|
||||||
options.NoInfoDownload = true
|
options.noInfoDownload = true
|
||||||
d, err := New(ctx, rawURL, options)
|
d, err := New(ctx, rawURL, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -248,7 +248,7 @@ func New(ctx context.Context, rawURL string, options Options) (result Result, er
|
|||||||
options.DebugLog = nopPrinter{}
|
options.DebugLog = nopPrinter{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.NoInfoDownload {
|
if options.noInfoDownload {
|
||||||
return Result{
|
return Result{
|
||||||
RawURL: rawURL,
|
RawURL: rawURL,
|
||||||
Options: options,
|
Options: options,
|
||||||
@ -476,7 +476,7 @@ type DownloadOptions struct {
|
|||||||
func (result Result) DownloadWithOptions(ctx context.Context, options DownloadOptions) (*DownloadResult, error) {
|
func (result Result) DownloadWithOptions(ctx context.Context, options DownloadOptions) (*DownloadResult, error) {
|
||||||
debugLog := result.Options.DebugLog
|
debugLog := result.Options.DebugLog
|
||||||
|
|
||||||
if !result.Options.NoInfoDownload {
|
if !result.Options.noInfoDownload {
|
||||||
if (result.Info.Type == "playlist" || result.Info.Type == "multi_video") && options.PlaylistIndex == 0 {
|
if (result.Info.Type == "playlist" || result.Info.Type == "multi_video") && options.PlaylistIndex == 0 {
|
||||||
return nil, fmt.Errorf("can't download a playlist when the playlist index options is not set")
|
return nil, fmt.Errorf("can't download a playlist when the playlist index options is not set")
|
||||||
}
|
}
|
||||||
@ -488,7 +488,7 @@ func (result Result) DownloadWithOptions(ctx context.Context, options DownloadOp
|
|||||||
}
|
}
|
||||||
|
|
||||||
var jsonTempPath string
|
var jsonTempPath string
|
||||||
if !result.Options.NoInfoDownload {
|
if !result.Options.noInfoDownload {
|
||||||
jsonTempPath = path.Join(tempPath, "info.json")
|
jsonTempPath = path.Join(tempPath, "info.json")
|
||||||
if err := ioutil.WriteFile(jsonTempPath, result.RawJSON, 0600); err != nil {
|
if err := ioutil.WriteFile(jsonTempPath, result.RawJSON, 0600); err != nil {
|
||||||
os.RemoveAll(tempPath)
|
os.RemoveAll(tempPath)
|
||||||
@ -511,7 +511,7 @@ func (result Result) DownloadWithOptions(ctx context.Context, options DownloadOp
|
|||||||
"-o", "-",
|
"-o", "-",
|
||||||
)
|
)
|
||||||
|
|
||||||
if result.Options.NoInfoDownload {
|
if result.Options.noInfoDownload {
|
||||||
// provide URL via stdin for security, youtube-dl has some run command args
|
// provide URL via stdin for security, youtube-dl has some run command args
|
||||||
cmd.Args = append(cmd.Args, "--batch-file", "-")
|
cmd.Args = append(cmd.Args, "--batch-file", "-")
|
||||||
cmd.Stdin = bytes.NewBufferString(result.RawURL + "\n")
|
cmd.Stdin = bytes.NewBufferString(result.RawURL + "\n")
|
||||||
|
Reference in New Issue
Block a user