Skip to content

Commit

Permalink
Add support for yt-dlp as a media downloader option
Browse files Browse the repository at this point in the history
  • Loading branch information
folliehiyuki committed Feb 29, 2024
1 parent 30dc536 commit 43ac6f6
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions reduxer/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ var (

_, existFFmpeg = exists("ffmpeg")
youget, existYouGet = exists("you-get")
ytdl, existYoutubeDL = exists("youtube-dl")
ytdl, existYoutubeDL = func() (string, bool) {
if ytdlPath, ok := exists("youtube-dl"); ok {
return ytdlPath, ok
}
return exists("yt-dlp")

Check warning on line 38 in reduxer/media.go

View check run for this annotation

Codecov / codecov/patch

reduxer/media.go#L38

Added line #L38 was not covered by tests
}()
)

func init() {
Expand Down Expand Up @@ -153,29 +158,36 @@ func run(cmd *exec.Cmd, debug bool) error {
return nil
}

// Download media via youtube-dl
// Download media via youtube-dl or yt-dlp
func (m media) viaYoutubeDL(ctx context.Context, cfg *config.Options) string {
if !existYoutubeDL {
return ""
}
logger.Debug("download media via youtube-dl")
ytdlCmd := filepath.Base(ytdl)
logger.Debug("download media via %s", ytdlCmd)

Check warning on line 167 in reduxer/media.go

View check run for this annotation

Codecov / codecov/patch

reduxer/media.go#L166-L167

Added lines #L166 - L167 were not covered by tests

args := []string{
"--http-chunk-size=10M", "--prefer-free-formats", "--restrict-filenames",
"--no-color", "--rm-cache-dir", "--no-warnings", "--no-check-certificate",
"--rm-cache-dir", "--no-warnings",

Check warning on line 171 in reduxer/media.go

View check run for this annotation

Codecov / codecov/patch

reduxer/media.go#L171

Added line #L171 was not covered by tests
"--no-progress", "--no-part", "--no-mtime", "--embed-subs", "--quiet",
"--ignore-errors", "--format=best[ext=mp4]/best", "--merge-output-format=mp4",
"--output=" + m.path + ".%(ext)s", m.url,
}
if cfg.HasDebugMode() {
args = append(args, "--verbose", "--print-traffic")
}
// These arguments are different between youtube-dl and yt-dlp
if ytdlCmd == "youtube-dl" {
args = append(args, "--no-color", "--no-check-certificate")
} else {
args = append(args, "--color=no_color", "--no-check-certificates")
}

Check warning on line 184 in reduxer/media.go

View check run for this annotation

Codecov / codecov/patch

reduxer/media.go#L180-L184

Added lines #L180 - L184 were not covered by tests

cmd := exec.CommandContext(ctx, ytdl, args...) // nosemgrep: gitlab.gosec.G204-1
logger.Debug("youtube-dl args: %s", cmd.String())
logger.Debug("%s args: %s", ytdlCmd, cmd.String())

Check warning on line 187 in reduxer/media.go

View check run for this annotation

Codecov / codecov/patch

reduxer/media.go#L187

Added line #L187 was not covered by tests

if err := run(cmd, cfg.HasDebugMode()); err != nil {
logger.Warn("start youtube-dl failed: %v", err)
logger.Warn("start %s failed: %v", ytdlCmd, err)

Check warning on line 190 in reduxer/media.go

View check run for this annotation

Codecov / codecov/patch

reduxer/media.go#L190

Added line #L190 was not covered by tests
}

return match(m.path + "*")
Expand Down Expand Up @@ -207,6 +219,8 @@ func exists(tool string) (string, bool) {
locations = []string{"ffmpeg", "ffmpeg.exe"}
case "youtube-dl":
locations = []string{"youtube-dl"}
case "yt-dlp":
locations = []string{"yt-dlp"}

Check warning on line 223 in reduxer/media.go

View check run for this annotation

Codecov / codecov/patch

reduxer/media.go#L222-L223

Added lines #L222 - L223 were not covered by tests
case "you-get":
locations = []string{"you-get"}
}
Expand Down

0 comments on commit 43ac6f6

Please sign in to comment.