mirror of
https://github.com/marcopiovanello/yt-dlp-web-ui.git
synced 2026-07-25 06:54:30 +00:00
143cc28a97
* refactoring-1 introduced pipelines and abstracted download process.go in Downloader interface * migrated to boltdb from sqlite + session files * refactoring: config struct & pipelines * added js runtime for yt-dlp * updated dockerfile * added external js runtime, metadata scraping refactor * updated Dockerfile * fixed env propagation in docker * updated package name to v4 * updated readme and cd
57 lines
895 B
Go
57 lines
895 B
Go
package formats
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log/slog"
|
|
"os/exec"
|
|
"sync"
|
|
|
|
"github.com/marcopiovanello/yt-dlp-web-ui/v4/server/config"
|
|
)
|
|
|
|
func ParseURL(url string) (*Metadata, error) {
|
|
cmd := exec.Command(config.Instance().Paths.DownloaderPath, url, "-J")
|
|
|
|
stdout, err := cmd.Output()
|
|
if err != nil {
|
|
slog.Error("failed to retrieve metadata", slog.String("err", err.Error()))
|
|
return nil, err
|
|
}
|
|
|
|
slog.Info(
|
|
"retrieving metadata",
|
|
slog.String("caller", "getFormats"),
|
|
slog.String("url", url),
|
|
)
|
|
|
|
info := &Metadata{URL: url}
|
|
best := &Format{}
|
|
|
|
var (
|
|
wg sync.WaitGroup
|
|
decodingError error
|
|
)
|
|
|
|
wg.Add(2)
|
|
|
|
go func() {
|
|
decodingError = json.Unmarshal(stdout, &info)
|
|
wg.Done()
|
|
}()
|
|
|
|
go func() {
|
|
decodingError = json.Unmarshal(stdout, &best)
|
|
wg.Done()
|
|
}()
|
|
|
|
wg.Wait()
|
|
|
|
if decodingError != nil {
|
|
return nil, err
|
|
}
|
|
|
|
info.Best = *best
|
|
|
|
return info, nil
|
|
}
|