Add support for the --proxy argument to yt-dlp
This commit is contained in:
parent
795b8c849c
commit
deb6d3b058
2 changed files with 27 additions and 5 deletions
|
|
@ -27,6 +27,10 @@ With Docker: `ronnieroller/media-roller:latest`.
|
||||||
See https://hub.docker.com/repository/docker/ronnieroller/media-roller
|
See https://hub.docker.com/repository/docker/ronnieroller/media-roller
|
||||||
The files are saved to the /download directory which you can mount as needed.
|
The files are saved to the /download directory which you can mount as needed.
|
||||||
|
|
||||||
|
## Docker Environemnt Variables
|
||||||
|
* `MR_DOWNLOAD_DIR` where videos are saved. Defaults to `/download`
|
||||||
|
* `MR_PROXY` will pass the value to yt-dlp witht he `--proxy` argument. Defaults to empty
|
||||||
|
|
||||||
# API
|
# API
|
||||||
To download a video directly, use the API endpoint:
|
To download a video directly, use the API endpoint:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ func FetchMedia(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := fetchIndexTmpl.Execute(w, data); err != nil {
|
if err = fetchIndexTmpl.Execute(w, data); err != nil {
|
||||||
log.Error().Msgf("Error rendering template: %v", err)
|
log.Error().Msgf("Error rendering template: %v", err)
|
||||||
http.Error(w, "Internal error", http.StatusInternalServerError)
|
http.Error(w, "Internal error", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +132,7 @@ func downloadMedia(url string) (string, string, error) {
|
||||||
|
|
||||||
log.Info().Msgf("Downloading %s to %s", url, name)
|
log.Info().Msgf("Downloading %s to %s", url, name)
|
||||||
|
|
||||||
cmd := exec.Command("yt-dlp",
|
args := []string{
|
||||||
"--format", "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best",
|
"--format", "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best",
|
||||||
"--merge-output-format", "mp4",
|
"--merge-output-format", "mp4",
|
||||||
"--trim-filenames", "100",
|
"--trim-filenames", "100",
|
||||||
|
|
@ -140,7 +140,15 @@ func downloadMedia(url string) (string, string, error) {
|
||||||
"--write-info-json",
|
"--write-info-json",
|
||||||
"--verbose",
|
"--verbose",
|
||||||
"--output", name,
|
"--output", name,
|
||||||
url)
|
}
|
||||||
|
|
||||||
|
if vars := getEnvVars(); len(vars) > 0 {
|
||||||
|
args = append(args, vars...)
|
||||||
|
}
|
||||||
|
|
||||||
|
args = append(args, url)
|
||||||
|
|
||||||
|
cmd := exec.Command("yt-dlp", args...)
|
||||||
|
|
||||||
var stdoutBuf, stderrBuf bytes.Buffer
|
var stdoutBuf, stderrBuf bytes.Buffer
|
||||||
stdoutIn, _ := cmd.StdoutPipe()
|
stdoutIn, _ := cmd.StdoutPipe()
|
||||||
|
|
@ -206,9 +214,9 @@ func getAllFilesForId(id string) ([]Media, error) {
|
||||||
// We expect two files to be produced for each video, a json manifest and an mp4.
|
// We expect two files to be produced for each video, a json manifest and an mp4.
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
if !strings.HasSuffix(f, ".json") {
|
if !strings.HasSuffix(f, ".json") {
|
||||||
fi, err := os.Stat(root + f)
|
fi, err2 := os.Stat(root + f)
|
||||||
var size int64 = 0
|
var size int64 = 0
|
||||||
if err == nil {
|
if err2 == nil {
|
||||||
size = fi.Size()
|
size = fi.Size()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -268,3 +276,13 @@ func getDownloadDir() string {
|
||||||
}
|
}
|
||||||
return "downloads/"
|
return "downloads/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getEnvVars() []string {
|
||||||
|
vars := make([]string, 0)
|
||||||
|
|
||||||
|
if ev := strings.TrimSpace(os.Getenv("MR_PROXY")); ev != "" {
|
||||||
|
vars = append(vars, "--proxy", ev)
|
||||||
|
}
|
||||||
|
|
||||||
|
return vars
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue