Download REST API endpoints (#72)
* backend and frontend hotfixes, see message Improved rendering on the frontend by cutting unecessary useStates. Backend side, downloads now auto resume even on application kill. * download rest api endpoints, general code refactor * download request json mappings
This commit is contained in:
@@ -66,8 +66,8 @@ type AbortRequest struct {
|
||||
// struct representing the intent to start a download
|
||||
type DownloadRequest struct {
|
||||
Id string
|
||||
URL string
|
||||
Path string
|
||||
Rename string
|
||||
Params []string
|
||||
URL string `json:"url"`
|
||||
Path string `json:"path"`
|
||||
Rename string `json:"rename"`
|
||||
Params []string `json:"params"`
|
||||
}
|
||||
|
||||
@@ -125,12 +125,18 @@ func (m *MemoryDB) Restore() {
|
||||
}
|
||||
|
||||
for _, proc := range session.Processes {
|
||||
m.table.Store(proc.Id, &Process{
|
||||
restored := &Process{
|
||||
Id: proc.Id,
|
||||
Url: proc.Info.URL,
|
||||
Info: proc.Info,
|
||||
Progress: proc.Progress,
|
||||
})
|
||||
}
|
||||
|
||||
m.table.Store(proc.Id, restored)
|
||||
|
||||
if restored.Progress.Percentage != "-1" {
|
||||
go restored.Start()
|
||||
}
|
||||
}
|
||||
|
||||
log.Println(cli.BgGreen, "Successfully restored session", cli.Reset)
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/marcopeocchi/fazzoletti/slices"
|
||||
"github.com/marcopeocchi/yt-dlp-web-ui/server/cli"
|
||||
"github.com/marcopeocchi/yt-dlp-web-ui/server/config"
|
||||
)
|
||||
|
||||
@@ -136,8 +137,11 @@ func (p *Process) Start() {
|
||||
Speed: stdout.Speed,
|
||||
ETA: stdout.Eta,
|
||||
}
|
||||
shortId := strings.Split(p.Id, "-")[0]
|
||||
log.Printf("[%s] %s %s\n", shortId, p.Url, p.Progress.Percentage)
|
||||
log.Println(
|
||||
cli.BgGreen, "DL", cli.Reset,
|
||||
cli.BgBlue, p.getShortId(), cli.Reset,
|
||||
p.Url, stdout.Percentage,
|
||||
)
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -156,6 +160,14 @@ func (p *Process) Complete() {
|
||||
Speed: 0,
|
||||
ETA: 0,
|
||||
}
|
||||
|
||||
shortId := p.getShortId()
|
||||
|
||||
log.Println(
|
||||
cli.BgMagenta, "FINISH", cli.Reset,
|
||||
cli.BgBlue, shortId, cli.Reset,
|
||||
p.Url,
|
||||
)
|
||||
}
|
||||
|
||||
// Kill a process and remove it from the memory
|
||||
@@ -202,6 +214,12 @@ func (p *Process) GetFormatsSync() (DownloadFormats, error) {
|
||||
return DownloadFormats{}, err
|
||||
}
|
||||
|
||||
log.Println(
|
||||
cli.BgRed, "Metadata", cli.Reset,
|
||||
cli.BgBlue, p.getShortId(), cli.Reset,
|
||||
p.Url,
|
||||
)
|
||||
|
||||
go func() {
|
||||
decodingError = json.NewDecoder(stdout).Decode(&info)
|
||||
wg.Done()
|
||||
@@ -248,6 +266,12 @@ func (p *Process) SetMetadata() error {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Println(
|
||||
cli.BgRed, "Metadata", cli.Reset,
|
||||
cli.BgBlue, p.getShortId(), cli.Reset,
|
||||
p.Url,
|
||||
)
|
||||
|
||||
err = json.NewDecoder(stdout).Decode(&info)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -260,3 +284,7 @@ func (p *Process) SetMetadata() error {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *Process) getShortId() string {
|
||||
return strings.Split(p.Id, "-")[0]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user