@@ -10,6 +10,11 @@ type ProgressTemplate struct {
|
|||||||
Eta float32 `json:"eta"`
|
Eta float32 `json:"eta"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type PostprocessTemplate struct {
|
||||||
|
FilePath string `json:"filepath"`
|
||||||
|
}
|
||||||
|
|
||||||
// Defines where and how the download needs to be saved
|
// Defines where and how the download needs to be saved
|
||||||
type DownloadOutput struct {
|
type DownloadOutput struct {
|
||||||
Path string
|
Path string
|
||||||
|
|||||||
@@ -22,13 +22,20 @@ import (
|
|||||||
"github.com/marcopeocchi/yt-dlp-web-ui/server/config"
|
"github.com/marcopeocchi/yt-dlp-web-ui/server/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
const template = `download:
|
const downloadTemplate = `download:
|
||||||
{
|
{
|
||||||
"eta":%(progress.eta)s,
|
"eta":%(progress.eta)s,
|
||||||
"percentage":"%(progress._percent_str)s",
|
"percentage":"%(progress._percent_str)s",
|
||||||
"speed":%(progress.speed)s
|
"speed":%(progress.speed)s
|
||||||
}`
|
}`
|
||||||
|
|
||||||
|
// filename not returning the correct extension after postprocess
|
||||||
|
const postprocessTemplate = `postprocess:
|
||||||
|
{
|
||||||
|
"filepath":"%(info.filepath)s"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
const (
|
const (
|
||||||
StatusPending = iota
|
StatusPending = iota
|
||||||
StatusDownloading
|
StatusDownloading
|
||||||
@@ -80,16 +87,16 @@ func (p *Process) Start() {
|
|||||||
|
|
||||||
buildFilename(&p.Output)
|
buildFilename(&p.Output)
|
||||||
|
|
||||||
//TODO: it spawn another one yt-dlp process, too slow.
|
templateReplacer := strings.NewReplacer("\n", "", "\t", "", " ", "")
|
||||||
go p.GetFileName(&out)
|
|
||||||
|
|
||||||
baseParams := []string{
|
baseParams := []string{
|
||||||
strings.Split(p.Url, "?list")[0], //no playlist
|
strings.Split(p.Url, "?list")[0], //no playlist
|
||||||
"--newline",
|
"--newline",
|
||||||
"--no-colors",
|
"--no-colors",
|
||||||
"--no-playlist",
|
"--no-playlist",
|
||||||
"--progress-template",
|
"--progress-template",
|
||||||
strings.NewReplacer("\n", "", "\t", "", " ", "").Replace(template),
|
templateReplacer.Replace(downloadTemplate),
|
||||||
|
"--progress-template",
|
||||||
|
templateReplacer.Replace(postprocessTemplate),
|
||||||
}
|
}
|
||||||
|
|
||||||
// if user asked to manually override the output path...
|
// if user asked to manually override the output path...
|
||||||
@@ -167,11 +174,9 @@ func (p *Process) consumeLogs(ctx context.Context, logs <-chan []byte) {
|
|||||||
|
|
||||||
func (p *Process) parseLogEntry(entry []byte) {
|
func (p *Process) parseLogEntry(entry []byte) {
|
||||||
var progress ProgressTemplate
|
var progress ProgressTemplate
|
||||||
|
var postprocess PostprocessTemplate
|
||||||
|
|
||||||
if err := json.Unmarshal(entry, &progress); err != nil {
|
if err := json.Unmarshal(entry, &progress); err == nil {
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
p.Progress = DownloadProgress{
|
p.Progress = DownloadProgress{
|
||||||
Status: StatusDownloading,
|
Status: StatusDownloading,
|
||||||
Percentage: progress.Percentage,
|
Percentage: progress.Percentage,
|
||||||
@@ -186,6 +191,18 @@ func (p *Process) parseLogEntry(entry []byte) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(entry, &postprocess); err == nil {
|
||||||
|
p.Output.SavedFilePath = postprocess.FilePath
|
||||||
|
|
||||||
|
slog.Info("postprocess",
|
||||||
|
slog.String("id", p.getShortId()),
|
||||||
|
slog.String("url", p.Url),
|
||||||
|
slog.String("filepath", postprocess.FilePath),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Process) detectYtDlpErrors(r io.Reader) {
|
func (p *Process) detectYtDlpErrors(r io.Reader) {
|
||||||
scanner := bufio.NewScanner(r)
|
scanner := bufio.NewScanner(r)
|
||||||
|
|
||||||
@@ -209,6 +226,11 @@ func (p *Process) Complete() {
|
|||||||
ETA: 0,
|
ETA: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for safety, if the filename is not set, set it with original function
|
||||||
|
if p.Output.SavedFilePath == "" {
|
||||||
|
p.GetFileName(&p.Output)
|
||||||
|
}
|
||||||
|
|
||||||
slog.Info("finished",
|
slog.Info("finished",
|
||||||
slog.String("id", p.getShortId()),
|
slog.String("id", p.getShortId()),
|
||||||
slog.String("url", p.Url),
|
slog.String("url", p.Url),
|
||||||
|
|||||||
Reference in New Issue
Block a user