diff --git a/server/internal/common_types.go b/server/internal/common_types.go index e019efe..7920832 100644 --- a/server/internal/common_types.go +++ b/server/internal/common_types.go @@ -36,6 +36,7 @@ type DownloadInfo struct { ACodec string `json:"acodec"` Extension string `json:"ext"` OriginalURL string `json:"original_url"` + FileName string `json:"filename"` CreatedAt time.Time `json:"created_at"` } diff --git a/server/internal/process.go b/server/internal/process.go index 50b9ca6..e69ce43 100644 --- a/server/internal/process.go +++ b/server/internal/process.go @@ -82,9 +82,6 @@ func (p *Process) Start() { buildFilename(&p.Output) - //TODO: it spawn another one yt-dlp process, too slow. - go p.GetFileName(&out) - baseParams := []string{ strings.Split(p.Url, "?list")[0], //no playlist "--newline", @@ -275,6 +272,7 @@ func (p *Process) GetFormatsSync() (DownloadFormats, error) { return info, nil } +// TODO: remove, potentially unused func (p *Process) GetFileName(o *DownloadOutput) error { cmd := exec.Command( config.Instance().DownloaderPath, @@ -304,7 +302,12 @@ func (p *Process) SetPending() { } func (p *Process) SetMetadata() error { - cmd := exec.Command(config.Instance().DownloaderPath, p.Url, "-J") + cmd := exec.Command( + config.Instance().DownloaderPath, + p.Url, + "-J", + "-o", fmt.Sprintf("%s/%s", p.Output.Path, p.Output.Filename), + ) cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} stdout, err := cmd.StdoutPipe() @@ -351,13 +354,14 @@ func (p *Process) SetMetadata() error { return err } - p.Info = info - p.Progress.Status = StatusPending - if err := cmd.Wait(); err != nil { return errors.New(bufferedStderr.String()) } + p.Info = info + p.Progress.Status = StatusPending + p.Output.SavedFilePath = info.FileName + return nil }