add api /v1/get_file_ffprobe_info

This commit is contained in:
2022-11-03 00:43:04 +08:00
parent 8a9569ea61
commit 08a5650b30
2 changed files with 41 additions and 0 deletions

View File

@@ -57,6 +57,7 @@ func NewAPI(config commonconfig.Config) (*API, error) {
apiMux.HandleFunc("/get_file_stream", api.HandleGetFileStream)
apiMux.HandleFunc("/get_ffmpeg_config_list", api.HandleGetFfmpegConfigs)
apiMux.HandleFunc("/get_file_info", api.HandleGetFileInfo)
apiMux.HandleFunc("/get_file_ffprobe_info", api.HandleGetFileFfprobeInfo)
apiMux.HandleFunc("/get_file_stream_direct", api.HandleGetFileStreamDirect)
apiMux.HandleFunc("/prepare_file_stream_direct", api.HandlePrepareFileStreamDirect)
apiMux.HandleFunc("/delete_file", api.HandleDeleteFile)

View File

@@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"os"
"os/exec"
"strconv"
)
@@ -46,6 +47,45 @@ func (api *API) HandleGetFileInfo(w http.ResponseWriter, r *http.Request) {
}
}
func (api *API) HandleGetFileFfprobeInfo(w http.ResponseWriter, r *http.Request) {
getFileRequest := &GetFileRequest {
ID: -1,
}
err := json.NewDecoder(r.Body).Decode(getFileRequest)
if err != nil {
api.HandleError(w, r, err)
return
}
// check empty
if getFileRequest.ID < 0 {
api.HandleErrorString(w, r, `"id" can't be none or negative`)
return
}
log.Println("[api] Get file Ffprobe info", getFileRequest.ID)
file, err := api.Db.GetFile(getFileRequest.ID)
if err != nil {
api.HandleError(w, r, err)
return
}
path, err := file.Path()
if err != nil {
api.HandleError(w, r, err)
return
}
cmd := exec.Command("ffprobe", "-i", path, "-hide_banner")
cmd.Stderr = w
err = cmd.Run()
if err != nil {
api.HandleError(w, r, err)
return
}
}
// /get_file
// get raw file with io.Copy method
func (api *API) HandleGetFile(w http.ResponseWriter, r *http.Request) {