display yt-dlp version, multiple downloads enabled.

code refactoring
preparations for optimistic ui updates for new downloads
This commit is contained in:
2024-03-22 13:22:38 +01:00
parent 48c9258088
commit 43e5c94b58
10 changed files with 137 additions and 28 deletions

View File

@@ -6,8 +6,11 @@ import (
"errors"
"log/slog"
"os"
"os/exec"
"time"
"github.com/google/uuid"
"github.com/marcopeocchi/yt-dlp-web-ui/server/config"
"github.com/marcopeocchi/yt-dlp-web-ui/server/internal"
)
@@ -118,3 +121,23 @@ func (s *Service) DeleteTemplate(ctx context.Context, id string) error {
return err
}
func (s *Service) GetVersion(ctx context.Context) (string, error) {
ch := make(chan string, 1)
c, cancel := context.WithTimeout(ctx, time.Second*10)
defer cancel()
cmd := exec.CommandContext(c, config.Instance().DownloaderPath, "--version")
go func() {
stdout, _ := cmd.Output()
ch <- string(stdout)
}()
select {
case <-c.Done():
return "", errors.New("requesting yt-dlp version took too long")
case res := <-ch:
return res, nil
}
}