prototyping
This commit is contained in:
@@ -137,17 +137,17 @@ func (p *Process) Kill() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) GetFormatsSync() (DownloadInfo, error) {
|
func (p *Process) GetFormatsSync() (DownloadFormats, error) {
|
||||||
cmd := exec.Command(driver, p.url, "-J")
|
cmd := exec.Command(driver, p.url, "-J")
|
||||||
stdout, err := cmd.Output()
|
stdout, err := cmd.Output()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return DownloadInfo{}, err
|
return DownloadFormats{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Wait()
|
cmd.Wait()
|
||||||
|
|
||||||
info := DownloadInfo{URL: p.url}
|
info := DownloadFormats{URL: p.url}
|
||||||
json.Unmarshal(stdout, &info)
|
json.Unmarshal(stdout, &info)
|
||||||
|
|
||||||
return info, nil
|
return info, nil
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ package server
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/rpc"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
||||||
@@ -22,6 +24,9 @@ func RunBlocking(ctx context.Context) {
|
|||||||
fe := ctx.Value("frontend").(fs.SubFS)
|
fe := ctx.Value("frontend").(fs.SubFS)
|
||||||
port := ctx.Value("port")
|
port := ctx.Value("port")
|
||||||
|
|
||||||
|
service := new(Service)
|
||||||
|
rpc.Register(service)
|
||||||
|
|
||||||
app := fiber.New()
|
app := fiber.New()
|
||||||
|
|
||||||
app.Use("/", filesystem.New(filesystem.Config{
|
app.Use("/", filesystem.New(filesystem.Config{
|
||||||
@@ -30,32 +35,16 @@ func RunBlocking(ctx context.Context) {
|
|||||||
|
|
||||||
app.Get("/ws", websocket.New(func(c *websocket.Conn) {
|
app.Get("/ws", websocket.New(func(c *websocket.Conn) {
|
||||||
for {
|
for {
|
||||||
mtype, msg, err := c.ReadMessage()
|
mtype, reader, err := c.NextReader()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
writer, err := c.NextWriter(mtype)
|
||||||
switch string(msg) {
|
|
||||||
case "send-url-format-selection":
|
|
||||||
getFormats(c)
|
|
||||||
case "send-url":
|
|
||||||
download(c)
|
|
||||||
case "abort":
|
|
||||||
abort(c)
|
|
||||||
case "abort-all":
|
|
||||||
abortAll(c)
|
|
||||||
case "status":
|
|
||||||
status(c)
|
|
||||||
case "update-bin":
|
|
||||||
hotUpdate(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("Read: %s", msg)
|
|
||||||
|
|
||||||
err = c.WriteMessage(mtype, msg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
res := NewRPCRequest(reader).Call()
|
||||||
|
io.Copy(writer, res)
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,14 @@ func (t *Service) Progess(args Args, progress *DownloadProgress) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Progess retrieves the Progress of a specific Process given its Id
|
||||||
|
func (t *Service) Formats(args Args, progress *DownloadFormats) error {
|
||||||
|
var err error
|
||||||
|
p := Process{url: args.URL}
|
||||||
|
*progress, err = p.GetFormatsSync()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Pending retrieves a slice of all Pending/Running processes ids
|
// Pending retrieves a slice of all Pending/Running processes ids
|
||||||
func (t *Service) Pending(args NoArgs, pending *Pending) error {
|
func (t *Service) Pending(args NoArgs, pending *Pending) error {
|
||||||
*pending = Pending(db.Keys())
|
*pending = Pending(db.Keys())
|
||||||
|
|||||||
@@ -17,6 +17,23 @@ type DownloadInfo struct {
|
|||||||
Extension string `json:"ext"`
|
Extension string `json:"ext"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DownloadFormats struct {
|
||||||
|
Formats []Format `json:"formats"`
|
||||||
|
Best Format `json:"best"`
|
||||||
|
Thumbnail string `json:"thumbnail"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Format struct {
|
||||||
|
Format_id string `json:"format_id"`
|
||||||
|
Format_note string `json:"format_note"`
|
||||||
|
FPS float32 `json:"fps"`
|
||||||
|
Resolution string `json:"resolution"`
|
||||||
|
VCodec string `json:"vcodec"`
|
||||||
|
ACodec string `json:"acodec"`
|
||||||
|
}
|
||||||
|
|
||||||
// struct representing the response sent to the client
|
// struct representing the response sent to the client
|
||||||
// as JSON-RPC result field
|
// as JSON-RPC result field
|
||||||
type ProcessResponse struct {
|
type ProcessResponse struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user