fix crummy ffprobe json output handling
All checks were successful
/ build-linux-amd64 (push) Successful in 1m35s
All checks were successful
/ build-linux-amd64 (push) Successful in 1m35s
This commit is contained in:
parent
f4381f7cdc
commit
51a1de845f
2 changed files with 42 additions and 16 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -28,13 +29,13 @@ type (
|
|||
Category *Category `toml:"category" comment:"(Optional) Category details, for additional credits."`
|
||||
}
|
||||
|
||||
ffprobeFormat struct {
|
||||
FFprobeFormat struct {
|
||||
Duration float64 `json:"duration"`
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
ffprobeOutput struct {
|
||||
Format ffprobeFormat `json:"format"`
|
||||
FFprobeOutput struct {
|
||||
Format FFprobeFormat `json:"format"`
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -58,15 +59,36 @@ func ScanSegments(directory string, extension string) ([]string, error) {
|
|||
return files, nil
|
||||
}
|
||||
|
||||
func ProbeSegment(filename string) (*ffprobeOutput, error) {
|
||||
func ProbeSegment(filename string) (*FFprobeOutput, error) {
|
||||
out, err := ffmpeg_go.Probe(filename)
|
||||
if err != nil { return nil, err }
|
||||
|
||||
probe := ffprobeOutput{}
|
||||
type (
|
||||
RawFFprobeFormat struct {
|
||||
// these being strings upsets me immensely
|
||||
Duration string `json:"duration"`
|
||||
Size string `json:"size"`
|
||||
}
|
||||
RawFFprobeOutput struct {
|
||||
Format RawFFprobeFormat `json:"format"`
|
||||
}
|
||||
)
|
||||
|
||||
probe := RawFFprobeOutput{}
|
||||
err = json.Unmarshal([]byte(out), &probe)
|
||||
if err != nil { return nil, err }
|
||||
|
||||
return &probe, nil
|
||||
duration, err := strconv.ParseFloat(probe.Format.Duration, 64)
|
||||
if err != nil { return nil, err }
|
||||
size, err := strconv.ParseInt(probe.Format.Size, 10, 0)
|
||||
if err != nil { return nil, err }
|
||||
|
||||
return &FFprobeOutput{
|
||||
Format: FFprobeFormat{
|
||||
Duration: duration,
|
||||
Size: size,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ReadMetadata(directory string) (*Metadata, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue