Skip to content

Commit

Permalink
way faster playlist entries detection
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopiovanello committed Jun 12, 2024
1 parent d402d71 commit 9c09c88
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions server/internal/playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type metadata struct {
func PlaylistDetect(req DownloadRequest, mq *MessageQueue, db *MemoryDB, logger *slog.Logger) error {
var (
downloader = config.Instance().DownloaderPath
cmd = exec.Command(downloader, req.URL, "-J")
cmd = exec.Command(downloader, req.URL, "--flat-playlist", "-J")
)

stdout, err := cmd.StdoutPipe()
Expand Down Expand Up @@ -59,7 +59,7 @@ func PlaylistDetect(req DownloadRequest, mq *MessageQueue, db *MemoryDB, logger

logger.Info("playlist detected", slog.String("url", req.URL), slog.Int("count", len(entries)))

for _, meta := range entries {
for i, meta := range entries {
// detect playlist title from metadata since each playlist entry will be
// treated as an individual download
req.Rename = strings.Replace(
Expand All @@ -69,16 +69,19 @@ func PlaylistDetect(req DownloadRequest, mq *MessageQueue, db *MemoryDB, logger
1,
)

//TODO: it's idiotic but it works: virtually delay the creation time
meta.CreatedAt = time.Now().Add(time.Millisecond * time.Duration(i*10))

proc := &Process{
Url: meta.OriginalURL,
Url: meta.URL,
Progress: DownloadProgress{},
Output: DownloadOutput{Filename: req.Rename},
Info: meta,
Params: req.Params,
Logger: logger,
}

proc.Info.URL = meta.OriginalURL
proc.Info.URL = meta.URL

time.Sleep(time.Millisecond)

Expand Down

0 comments on commit 9c09c88

Please sign in to comment.