fixed double ext and playlist title detection (#106)

This commit is contained in:
Marco
2023-11-22 11:14:58 +01:00
committed by GitHub
parent fe6519773e
commit f478754b6f
3 changed files with 35 additions and 4 deletions

View File

@@ -25,6 +25,7 @@ import {
FC,
Suspense,
forwardRef,
useEffect,
useMemo,
useRef,
useState,
@@ -92,6 +93,10 @@ const DownloadDialog: FC<Props> = ({ open, onClose, onDownloadStart }) => {
const [isPending, startTransition] = useTransition()
useEffect(() => {
setCustomArgs('')
}, [open])
/**
* Retrive url from input, cli-arguments from checkboxes and emits via WebSocket
*/

View File

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

View File

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