By default probe for youtube-dl or yt-dlp binary
Still possible to override with Path
This commit is contained in:
17
README.md
17
README.md
@ -1,18 +1,19 @@
|
|||||||
## goutubedl
|
## goutubedl
|
||||||
|
|
||||||
Go wrapper for [youtube-dl](https://github.com/ytdl-org/youtube-dl) and [yt-dlp](https://github.com/yt-dlp/yt-dlp), currently tested and
|
Go wrapper for
|
||||||
developed using yt-dlp.
|
[youtube-dl](https://github.com/ytdl-org/youtube-dl) and
|
||||||
|
[yt-dlp](https://github.com/yt-dlp/yt-dlp).
|
||||||
|
Currently only tested and developed using yt-dlp.
|
||||||
API documentation can be found at [godoc.org](https://pkg.go.dev/github.com/wader/goutubedl?tab=doc).
|
API documentation can be found at [godoc.org](https://pkg.go.dev/github.com/wader/goutubedl?tab=doc).
|
||||||
|
|
||||||
See [yt-dlp documentation](https://github.com/yt-dlp/yt-dlp) for how to
|
See [yt-dlp documentation](https://github.com/yt-dlp/yt-dlp) for how to
|
||||||
install and what is recommended to install in addition to youtube-dl.
|
install and what is recommended to install in addition to yt-dl.
|
||||||
|
|
||||||
goutubedl default uses `PATH` to find youtube-dl but it can be configured with the `goutubedl.Path`
|
goutubedl default uses `PATH` to find `youtube-dl` or `yt-dlp` (in that order) but can be configured with the
|
||||||
variable. Default is currently `youtube-dl` for backwards compability. If your using yt-dlp you
|
`goutubedl.Path` variable.
|
||||||
probably want to set it to `yt-dlp`.
|
|
||||||
|
|
||||||
Due to the nature and frequent updates of youtube-dl only the latest version
|
Due to the nature of and frequent updates of yt-dl only the latest version is tested.
|
||||||
is tested. But it seems to work well with older versions also.
|
But it seems to work well with older versions also.
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
|
26
goutubedl.go
26
goutubedl.go
@ -18,8 +18,22 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Path to youtube-dl binary. Default look for "youtube-dl" in PATH.
|
// Path to youtube-dl binary. If not set look for "youtube-dl" then "yt-dlp" in PATH.
|
||||||
var Path = "youtube-dl"
|
var Path = ""
|
||||||
|
|
||||||
|
func ProbePath() string {
|
||||||
|
if Path != "" {
|
||||||
|
return Path
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, n := range []string{"youtube-dl", "yt-dlp"} {
|
||||||
|
if p, err := exec.LookPath(n); err == nil {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "youtube-dl"
|
||||||
|
}
|
||||||
|
|
||||||
// Printer is something that can print
|
// Printer is something that can print
|
||||||
type Printer interface {
|
type Printer interface {
|
||||||
@ -223,7 +237,7 @@ type Options struct {
|
|||||||
// Version of youtube-dl.
|
// Version of youtube-dl.
|
||||||
// Might be a good idea to call at start to assert that youtube-dl can be found.
|
// Might be a good idea to call at start to assert that youtube-dl can be found.
|
||||||
func Version(ctx context.Context) (string, error) {
|
func Version(ctx context.Context) (string, error) {
|
||||||
cmd := exec.CommandContext(ctx, Path, "--version")
|
cmd := exec.CommandContext(ctx, ProbePath(), "--version")
|
||||||
versionBytes, cmdErr := cmd.Output()
|
versionBytes, cmdErr := cmd.Output()
|
||||||
if cmdErr != nil {
|
if cmdErr != nil {
|
||||||
return "", cmdErr
|
return "", cmdErr
|
||||||
@ -275,7 +289,7 @@ func New(ctx context.Context, rawURL string, options Options) (result Result, er
|
|||||||
func infoFromURL(ctx context.Context, rawURL string, options Options) (info Info, rawJSON []byte, err error) {
|
func infoFromURL(ctx context.Context, rawURL string, options Options) (info Info, rawJSON []byte, err error) {
|
||||||
cmd := exec.CommandContext(
|
cmd := exec.CommandContext(
|
||||||
ctx,
|
ctx,
|
||||||
Path,
|
ProbePath(),
|
||||||
// see comment below about ignoring errors for playlists
|
// see comment below about ignoring errors for playlists
|
||||||
"--ignore-errors",
|
"--ignore-errors",
|
||||||
"--no-call-home",
|
"--no-call-home",
|
||||||
@ -503,7 +517,7 @@ func (result Result) DownloadWithOptions(ctx context.Context, options DownloadOp
|
|||||||
|
|
||||||
cmd := exec.CommandContext(
|
cmd := exec.CommandContext(
|
||||||
ctx,
|
ctx,
|
||||||
Path,
|
ProbePath(),
|
||||||
"--no-call-home",
|
"--no-call-home",
|
||||||
"--no-cache-dir",
|
"--no-cache-dir",
|
||||||
"--ignore-errors",
|
"--ignore-errors",
|
||||||
@ -556,7 +570,7 @@ func (result Result) DownloadWithOptions(ctx context.Context, options DownloadOp
|
|||||||
if result.Options.Downloader != "" {
|
if result.Options.Downloader != "" {
|
||||||
cmd.Args = append(cmd.Args, "--downloader", result.Options.Downloader)
|
cmd.Args = append(cmd.Args, "--downloader", result.Options.Downloader)
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.Options.DownloadSections != "" {
|
if result.Options.DownloadSections != "" {
|
||||||
cmd.Args = append(cmd.Args, "--download-sections", result.Options.DownloadSections)
|
cmd.Args = append(cmd.Args, "--download-sections", result.Options.DownloadSections)
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,6 @@ import (
|
|||||||
"github.com/wader/osleaktest"
|
"github.com/wader/osleaktest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
// we're using yt-dlp at the moment
|
|
||||||
goutubedl.Path = "yt-dlp"
|
|
||||||
}
|
|
||||||
|
|
||||||
const testVideoRawURL = "https://www.youtube.com/watch?v=C0DPdy98e4c"
|
const testVideoRawURL = "https://www.youtube.com/watch?v=C0DPdy98e4c"
|
||||||
const playlistRawURL = "https://soundcloud.com/mattheis/sets/kindred-phenomena"
|
const playlistRawURL = "https://soundcloud.com/mattheis/sets/kindred-phenomena"
|
||||||
const subtitlesTestVideoRawURL = "https://www.youtube.com/watch?v=QRS8MkLhQmM"
|
const subtitlesTestVideoRawURL = "https://www.youtube.com/watch?v=QRS8MkLhQmM"
|
||||||
@ -307,7 +302,6 @@ func TestDownloadSections(t *testing.T) {
|
|||||||
DownloadSections: fmt.Sprintf("*0:0-0:%d", duration),
|
DownloadSections: fmt.Sprintf("*0:0-0:%d", duration),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
if ydlResult.Options.DownloadSections != "*0:0-0:5" {
|
if ydlResult.Options.DownloadSections != "*0:0-0:5" {
|
||||||
t.Errorf("failed to setup --download-sections")
|
t.Errorf("failed to setup --download-sections")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user