Implemented "download file" in dashboard and bulk download

closes #115
This commit is contained in:
2024-04-16 11:27:47 +02:00
parent 294ad29bf2
commit 205f2e5cdf
8 changed files with 174 additions and 14 deletions

View File

@@ -55,8 +55,9 @@ type Process struct {
}
type DownloadOutput struct {
Path string
Filename string
Path string
Filename string
SavedFilePath string `json:"savedFilePath"`
}
// Starts spawns/forks a new yt-dlp process and parse its stdout.
@@ -91,6 +92,8 @@ func (p *Process) Start() {
buildFilename(&p.Output)
go p.GetFileName(&out)
params := []string{
strings.Split(p.Url, "?list")[0], //no playlist
"--newline",
@@ -269,6 +272,24 @@ func (p *Process) GetFormatsSync() (DownloadFormats, error) {
return info, nil
}
func (p *Process) GetFileName(o *DownloadOutput) error {
cmd := exec.Command(
config.Instance().DownloaderPath,
"--print", "filename",
"-o", fmt.Sprintf("%s/%s", o.Path, o.Filename),
p.Url,
)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
out, err := cmd.Output()
if err != nil {
return err
}
p.Output.SavedFilePath = strings.Trim(string(out), "\n")
return nil
}
func (p *Process) SetPending() {
// Since video's title isn't available yet, fill in with the URL.
p.Info = DownloadInfo{