code refactoring, removed unused rx package

This commit is contained in:
2024-08-26 10:18:14 +02:00
parent bb4db5d342
commit b0c7c13e5e
2 changed files with 8 additions and 47 deletions

View File

@@ -14,13 +14,11 @@ import (
"sync"
"syscall"
"log"
"os"
"os/exec"
"strings"
"time"
"github.com/marcopeocchi/yt-dlp-web-ui/server/cli"
"github.com/marcopeocchi/yt-dlp-web-ui/server/config"
)
@@ -109,13 +107,13 @@ func (p *Process) Start() {
stdout, err := cmd.StdoutPipe()
if err != nil {
slog.Error("failed to connect to stdout", slog.Any("err", err))
slog.Error("failed to get a stdout pipe", slog.Any("err", err))
panic(err)
}
stderr, err := cmd.StderrPipe()
if err != nil {
slog.Error("failed to connect to stdout", slog.Any("err", err))
slog.Error("failed to get a stderr pipe", slog.Any("err", err))
panic(err)
}
@@ -253,6 +251,12 @@ func (p *Process) GetFormats() (DownloadFormats, error) {
return DownloadFormats{}, err
}
slog.Info(
"retrieving metadata",
slog.String("caller", "getFormats"),
slog.String("url", p.Url),
)
info := DownloadFormats{URL: p.Url}
best := Format{}
@@ -263,18 +267,6 @@ func (p *Process) GetFormats() (DownloadFormats, error) {
wg.Add(2)
log.Println(
cli.BgRed, "Metadata", cli.Reset,
cli.BgBlue, "Formats", cli.Reset,
p.Url,
)
slog.Info(
"retrieving metadata",
slog.String("caller", "getFormats"),
slog.String("url", p.Url),
)
go func() {
decodingError = json.Unmarshal(stdout, &info)
wg.Done()

View File

@@ -1,31 +0,0 @@
package rx
import "time"
// ReactiveX inspired sample function.
//
// Debounce emits the most recently emitted value from the source
// withing the timespan set by the span time.Duration
//
// Soon it will be deprecated since it doesn't add anything useful.
// (It lowers the CPU usage by a negligible margin)
func Sample(span time.Duration, source chan []byte, done chan struct{}, fn func(e []byte)) {
var (
item []byte
ticker = time.NewTicker(span)
)
for {
select {
case <-ticker.C:
if item != nil {
fn(item)
}
case <-source:
item = <-source
case <-done:
ticker.Stop()
return
}
}
}