Add --ignore-errors for info download also
--ignore-errors still return error message and exit code != 0 so workaround is to assume things went ok if we get some json on stdout Filter out failed entries for playlists
This commit is contained in:
25
goutubedl.go
25
goutubedl.go
@ -217,6 +217,7 @@ func infoFromURL(ctx context.Context, rawURL string, options Options) (info Info
|
|||||||
Path,
|
Path,
|
||||||
"--no-call-home",
|
"--no-call-home",
|
||||||
"--no-cache-dir",
|
"--no-cache-dir",
|
||||||
|
"--ignore-errors",
|
||||||
"--skip-download",
|
"--skip-download",
|
||||||
"--restrict-filenames",
|
"--restrict-filenames",
|
||||||
// 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
|
||||||
@ -275,10 +276,14 @@ func infoFromURL(ctx context.Context, rawURL string, options Options) (info Info
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if errMessage != "" {
|
// HACK: --ignore-errors still return error message and exit code != 0
|
||||||
return Info{}, nil, Error(errMessage)
|
// so workaround is to assume things went ok if we get some json on stdout
|
||||||
} else if cmdErr != nil {
|
if len(stdoutBuf.Bytes()) == 0 {
|
||||||
return Info{}, nil, cmdErr
|
if errMessage != "" {
|
||||||
|
return Info{}, nil, Error(errMessage)
|
||||||
|
} else if cmdErr != nil {
|
||||||
|
return Info{}, nil, cmdErr
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if infoErr := json.Unmarshal(stdoutBuf.Bytes(), &info); infoErr != nil {
|
if infoErr := json.Unmarshal(stdoutBuf.Bytes(), &info); infoErr != nil {
|
||||||
@ -318,6 +323,18 @@ func infoFromURL(ctx context.Context, rawURL string, options Options) (info Info
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// as we ignore errors some entries might show up as null
|
||||||
|
if options.YesPlaylist {
|
||||||
|
var filteredEntrise []Info
|
||||||
|
for _, e := range info.Entries {
|
||||||
|
if e.ID == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
filteredEntrise = append(filteredEntrise, e)
|
||||||
|
}
|
||||||
|
info.Entries = filteredEntrise
|
||||||
|
}
|
||||||
|
|
||||||
return info, stdoutBuf.Bytes(), nil
|
return info, stdoutBuf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,6 +181,26 @@ func TestPlaylist(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPlaylistWithPrivateVideo(t *testing.T) {
|
||||||
|
defer leaktest.Check(t)()
|
||||||
|
|
||||||
|
playlistRawURL := "https://www.youtube.com/playlist?list=PLX0g748fkegS54oiDN4AXKl7BR7mLIydP"
|
||||||
|
ydlResult, ydlResultErr := New(context.Background(), playlistRawURL, Options{
|
||||||
|
YesPlaylist: true,
|
||||||
|
DownloadThumbnail: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
if ydlResultErr != nil {
|
||||||
|
t.Errorf("failed to download: %s", ydlResultErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedLen := 2
|
||||||
|
actualLen := len(ydlResult.Info.Entries)
|
||||||
|
if expectedLen != actualLen {
|
||||||
|
t.Errorf("expected len %d got %d", expectedLen, actualLen)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPlaylistBadURL(t *testing.T) {
|
func TestPlaylistBadURL(t *testing.T) {
|
||||||
defer leakChecks(t)()
|
defer leakChecks(t)()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user