sped-up download by spawning 1 less yt-dlp process

This commit is contained in:
2024-06-07 10:55:03 +02:00
parent 2f0afe27cc
commit 00ca9156fb
2 changed files with 12 additions and 7 deletions

View File

@@ -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"`
}

View File

@@ -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
}