mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-30 19:54:16 -04:00
Add basic extraction methods
This commit is contained in:
parent
43ba1bb449
commit
30cb171612
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@ -208,6 +209,46 @@ func GetInfo(c echo.Context) error {
|
|||||||
return c.JSON(http.StatusOK, ret)
|
return c.JSON(http.StatusOK, ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get attachments
|
||||||
|
//
|
||||||
|
// Get a specific attachment
|
||||||
|
//
|
||||||
|
// Path: /:sha/attachment/:name
|
||||||
|
func GetAttachment(c echo.Context) error {
|
||||||
|
sha := c.Param("sha")
|
||||||
|
name := c.Param("name")
|
||||||
|
|
||||||
|
if err := SanitizePath(sha); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := SanitizePath(name); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
path := fmt.Sprintf("%s/%s/att/%s", src.GetMetadataPath(), sha, name)
|
||||||
|
return c.File(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get subtitle
|
||||||
|
//
|
||||||
|
// Get a specific subtitle
|
||||||
|
//
|
||||||
|
// Path: /:sha/sub/:name
|
||||||
|
func GetSubtitle(c echo.Context) error {
|
||||||
|
sha := c.Param("sha")
|
||||||
|
name := c.Param("name")
|
||||||
|
|
||||||
|
if err := SanitizePath(sha); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := SanitizePath(name); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
path := fmt.Sprintf("%s/%s/sub/%s", src.GetMetadataPath(), sha, name)
|
||||||
|
return c.File(path)
|
||||||
|
}
|
||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
transcoder *src.Transcoder
|
transcoder *src.Transcoder
|
||||||
}
|
}
|
||||||
@ -231,6 +272,8 @@ func main() {
|
|||||||
e.GET("/:resource/:slug/:quality/:chunk", h.GetVideoSegment)
|
e.GET("/:resource/:slug/:quality/:chunk", h.GetVideoSegment)
|
||||||
e.GET("/:resource/:slug/audio/:audio/:chunk", h.GetAudioSegment)
|
e.GET("/:resource/:slug/audio/:audio/:chunk", h.GetAudioSegment)
|
||||||
e.GET("/:resource/:slug/info", GetInfo)
|
e.GET("/:resource/:slug/info", GetInfo)
|
||||||
|
e.GET("/:sha/attachment/:name", GetAttachment)
|
||||||
|
e.GET("/:sha/sub/:name", GetSubtitle)
|
||||||
|
|
||||||
e.Logger.Fatal(e.Start(":7666"))
|
e.Logger.Fatal(e.Start(":7666"))
|
||||||
}
|
}
|
||||||
|
42
transcoder/src/extract.go
Normal file
42
transcoder/src/extract.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package src
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetMetadataPath() string {
|
||||||
|
out := os.Getenv("GOCODER_METADATA_ROOT")
|
||||||
|
if out == "" {
|
||||||
|
return "/metadata"
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func extract(path string, sha string, subs *[]Subtitle) {
|
||||||
|
fmt.Printf("Extract subs and fonts for %s", path)
|
||||||
|
cmd := exec.Command(
|
||||||
|
"ffmpeg",
|
||||||
|
"-dump_attachment:t", "",
|
||||||
|
"-i", path,
|
||||||
|
)
|
||||||
|
cmd.Dir = fmt.Sprintf("/%s/%s/att/", GetMetadataPath(), sha)
|
||||||
|
|
||||||
|
for _, sub := range *subs {
|
||||||
|
if ext := sub.Extension; ext != nil {
|
||||||
|
cmd.Args = append(
|
||||||
|
cmd.Args,
|
||||||
|
"-map", fmt.Sprintf("0:s:%d", sub.Index),
|
||||||
|
"-c:s", "copy",
|
||||||
|
fmt.Sprintf("/%s/%s/sub/%d.%s", GetMetadataPath(), sha, sub.Index, *ext),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Printf("Starting extraction with the command: %s", cmd)
|
||||||
|
cmd.Stdout = nil
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error starting ffmpeg extract:", err)
|
||||||
|
}
|
||||||
|
}
|
@ -56,6 +56,13 @@ func GetPath(resource string, slug string) (string, error) {
|
|||||||
return ret.Path, nil
|
return ret.Path, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SanitizePath(path string) error {
|
||||||
|
if strings.Contains(path, "/") || strings.Contains(path, "..") {
|
||||||
|
return echo.NewHTTPError(http.StatusBadRequest, "Invalid parameter. Can't contains path delimiters or ..")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func GetClientId(c echo.Context) (string, error) {
|
func GetClientId(c echo.Context) (string, error) {
|
||||||
key := c.Request().Header.Get("X-CLIENT-ID")
|
key := c.Request().Header.Get("X-CLIENT-ID")
|
||||||
if key == "" {
|
if key == "" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user