From f478754b6f94cb717fa3d59a3f92c4dc209292fa Mon Sep 17 00:00:00 2001 From: Marco <35533749+marcopeocchi@users.noreply.github.com> Date: Wed, 22 Nov 2023 11:14:58 +0100 Subject: [PATCH] fixed double ext and playlist title detection (#106) --- frontend/src/components/DownloadDialog.tsx | 5 +++++ server/internal/playlist.go | 17 ++++++++++++++--- server/internal/process.go | 17 ++++++++++++++++- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/DownloadDialog.tsx b/frontend/src/components/DownloadDialog.tsx index 11664b6..2dedf87 100644 --- a/frontend/src/components/DownloadDialog.tsx +++ b/frontend/src/components/DownloadDialog.tsx @@ -25,6 +25,7 @@ import { FC, Suspense, forwardRef, + useEffect, useMemo, useRef, useState, @@ -92,6 +93,10 @@ const DownloadDialog: FC = ({ open, onClose, onDownloadStart }) => { const [isPending, startTransition] = useTransition() + useEffect(() => { + setCustomArgs('') + }, [open]) + /** * Retrive url from input, cli-arguments from checkboxes and emits via WebSocket */ diff --git a/server/internal/playlist.go b/server/internal/playlist.go index ff7789b..0a4d843 100644 --- a/server/internal/playlist.go +++ b/server/internal/playlist.go @@ -5,6 +5,7 @@ import ( "errors" "log" "os/exec" + "strings" "time" "github.com/marcopeocchi/yt-dlp-web-ui/server/cli" @@ -12,9 +13,10 @@ import ( ) type metadata struct { - Entries []DownloadInfo `json:"entries"` - Count int `json:"playlist_count"` - Type string `json:"_type"` + Entries []DownloadInfo `json:"entries"` + Count int `json:"playlist_count"` + PlaylistTitle string `json:"title"` + Type string `json:"_type"` } func PlaylistDetect(req DownloadRequest, mq *MessageQueue, db *MemoryDB) error { @@ -57,6 +59,15 @@ func PlaylistDetect(req DownloadRequest, mq *MessageQueue, db *MemoryDB) error { for i, meta := range m.Entries { delta := time.Second.Microseconds() * int64(i+1) + // detect playlist title from metadata since each playlist entry will be + // treated as an individual download + req.Rename = strings.Replace( + req.Rename, + "%(playlist_title)s", + m.PlaylistTitle, + 1, + ) + proc := &Process{ Url: meta.OriginalURL, Progress: DownloadProgress{}, diff --git a/server/internal/process.go b/server/internal/process.go index 93182bd..dd5b20d 100644 --- a/server/internal/process.go +++ b/server/internal/process.go @@ -84,9 +84,11 @@ func (p *Process) Start() { } if p.Output.Filename != "" { - out.Filename = p.Output.Filename + ".%(ext)s" + out.Filename = p.Output.Filename } + buildFilename(&p.Output) + params := append([]string{ strings.Split(p.Url, "?list")[0], //no playlist "--newline", @@ -298,3 +300,16 @@ func (p *Process) SetMetadata() error { func (p *Process) getShortId() string { return strings.Split(p.Id, "-")[0] } + +func buildFilename(o *DownloadOutput) { + if o.Filename != "" && strings.Contains(o.Filename, ".%(ext)s") { + o.Filename += ".%(ext)s" + } + + o.Filename = strings.Replace( + o.Filename, + ".%(ext)s.%(ext)s", + ".%(ext)s", + 1, + ) +}