code refactoring, removed unused rx package
This commit is contained in:
@@ -14,13 +14,11 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/marcopeocchi/yt-dlp-web-ui/server/cli"
|
|
||||||
"github.com/marcopeocchi/yt-dlp-web-ui/server/config"
|
"github.com/marcopeocchi/yt-dlp-web-ui/server/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -109,13 +107,13 @@ func (p *Process) Start() {
|
|||||||
|
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
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)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
stderr, err := cmd.StderrPipe()
|
stderr, err := cmd.StderrPipe()
|
||||||
if err != nil {
|
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)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,6 +251,12 @@ func (p *Process) GetFormats() (DownloadFormats, error) {
|
|||||||
return DownloadFormats{}, err
|
return DownloadFormats{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slog.Info(
|
||||||
|
"retrieving metadata",
|
||||||
|
slog.String("caller", "getFormats"),
|
||||||
|
slog.String("url", p.Url),
|
||||||
|
)
|
||||||
|
|
||||||
info := DownloadFormats{URL: p.Url}
|
info := DownloadFormats{URL: p.Url}
|
||||||
best := Format{}
|
best := Format{}
|
||||||
|
|
||||||
@@ -263,18 +267,6 @@ func (p *Process) GetFormats() (DownloadFormats, error) {
|
|||||||
|
|
||||||
wg.Add(2)
|
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() {
|
go func() {
|
||||||
decodingError = json.Unmarshal(stdout, &info)
|
decodingError = json.Unmarshal(stdout, &info)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user