move manifest error field check out
This commit is contained in:
parent
05370ac335
commit
39164960de
2 changed files with 16 additions and 8 deletions
14
main.go
14
main.go
|
@ -63,7 +63,13 @@ func getUgoira(postId PostId, flags CliFlags) {
|
|||
die("error while fetching manifest: %s", err)
|
||||
}
|
||||
// Now decode the JSON...
|
||||
manifest := decodeUgoiraManifest(manifestJsonData)
|
||||
manifest, err := decodeUgoiraManifest(manifestJsonData)
|
||||
if err != nil {
|
||||
die("%s", err)
|
||||
}
|
||||
if manifest.Error {
|
||||
die("Manifest returned error: %s", manifest.Message)
|
||||
}
|
||||
if len(manifest.Body.OriginalSrc) == 0 {
|
||||
die("Ugoira url is empty")
|
||||
}
|
||||
|
@ -150,7 +156,11 @@ func ugoira2videoCmd(args []string, flags CliFlags) {
|
|||
die("Could not read manifest: %s", err)
|
||||
}
|
||||
|
||||
err = ugoira2video(decodeUgoiraManifest(manifestData), ugoiraFileName, flags.outputFileName, flags.ffmpegArgs)
|
||||
manifest, err := decodeUgoiraManifest(manifestData)
|
||||
if err != nil {
|
||||
die("%s", err)
|
||||
}
|
||||
err = ugoira2video(manifest, ugoiraFileName, flags.outputFileName, flags.ffmpegArgs)
|
||||
if err != nil {
|
||||
die("Conversion failed: %s", err)
|
||||
}
|
||||
|
|
10
manifest.go
10
manifest.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type UgoiraManifestFrame struct {
|
||||
|
@ -22,13 +23,10 @@ type UgoiraManifest struct {
|
|||
Body UgoiraManifestBodyDesc `json:"body"`
|
||||
}
|
||||
|
||||
func decodeUgoiraManifest(jsonData []byte) UgoiraManifest {
|
||||
func decodeUgoiraManifest(jsonData []byte) (UgoiraManifest, error) {
|
||||
var manifest UgoiraManifest
|
||||
if err := json.Unmarshal(jsonData, &manifest); err != nil {
|
||||
die("Could not parse manifest JSON: %s", err)
|
||||
return manifest, fmt.Errorf("Could not decode manifest JSON: %w", err)
|
||||
}
|
||||
if manifest.Error {
|
||||
die("Manifest returned error: %s", manifest.Message)
|
||||
}
|
||||
return manifest
|
||||
return manifest, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue