remove gjson dependency

This commit is contained in:
Connor Baker
2021-10-28 15:12:18 -04:00
parent 2758af6b5d
commit 491575df52
4 changed files with 56 additions and 17 deletions

View File

@@ -1,14 +1,39 @@
package ffmpeg_go
import (
"encoding/json"
"fmt"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
"github.com/tidwall/gjson"
)
func TestProbe(t *testing.T) {
data, err := Probe(TestInputFile1, nil)
assert.Nil(t, err)
assert.Equal(t, gjson.Get(data, "format.duration").String(), "7.036000")
duration, err := probeOutputDuration(data)
assert.Nil(t, err)
assert.Equal(t, fmt.Sprintf("%f", duration), "7.036000")
}
type probeFormat struct {
Duration string `json:"duration"`
}
type probeData struct {
Format probeFormat `json:"format"`
}
func probeOutputDuration(a string) (float64, error) {
pd := probeData{}
err := json.Unmarshal([]byte(a), &pd)
if err != nil {
return 0, err
}
f, err := strconv.ParseFloat(pd.Format.Duration, 64)
if err != nil {
return 0, err
}
return f, nil
}