From 70e617594a052c0ad5a34d8c952be2dfcceb65dc Mon Sep 17 00:00:00 2001 From: tocariimaa Date: Sun, 29 Dec 2024 23:05:39 -0300 Subject: [PATCH] move manifest related code to its own file --- main.go | 30 ------------------------------ manifest.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 manifest.go diff --git a/main.go b/main.go index 2416d48..7e4e25a 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "encoding/json" "flag" "fmt" "io" @@ -17,24 +16,6 @@ type CliFlags struct { verbose bool } -type UgoiraManifestFrame struct { - File string `json:"file"` - Delay int `json:"delay"` -} - -type UgoiraManifestBodyDesc struct { - Src string `json:"src"` - OriginalSrc string `json:"originalSrc"` - MimeType string `json:"mime_type"` - Frames []UgoiraManifestFrame `json:"frames"` -} - -type UgoiraManifest struct { - Error bool `json:"error"` - Message string `json:"message"` - Body UgoiraManifestBodyDesc `json:"body"` -} - type PostId uint64 const ( @@ -67,17 +48,6 @@ func doPixivRequest(client *http.Client, url, referer, userAgent string) io.Read return response.Body } -func decodeUgoiraManifest(jsonData []byte) UgoiraManifest { - var manifest UgoiraManifest - if err := json.Unmarshal(jsonData, &manifest); err != nil { - die("Could not parse manifest JSON: %s", err) - } - if manifest.Error { - die("Manifest returned error: %s", manifest.Message) - } - return manifest -} - func getUgoira(postId PostId, flags CliFlags) { client := &http.Client{} artworkUrl := fmt.Sprintf(ArtworkUrlTemplate, postId) diff --git a/manifest.go b/manifest.go new file mode 100644 index 0000000..a4d1244 --- /dev/null +++ b/manifest.go @@ -0,0 +1,34 @@ +package main; + +import ( + "encoding/json" +) + +type UgoiraManifestFrame struct { + File string `json:"file"` + Delay int `json:"delay"` +} + +type UgoiraManifestBodyDesc struct { + Src string `json:"src"` + OriginalSrc string `json:"originalSrc"` + MimeType string `json:"mime_type"` + Frames []UgoiraManifestFrame `json:"frames"` +} + +type UgoiraManifest struct { + Error bool `json:"error"` + Message string `json:"message"` + Body UgoiraManifestBodyDesc `json:"body"` +} + +func decodeUgoiraManifest(jsonData []byte) UgoiraManifest { + var manifest UgoiraManifest + if err := json.Unmarshal(jsonData, &manifest); err != nil { + die("Could not parse manifest JSON: %s", err) + } + if manifest.Error { + die("Manifest returned error: %s", manifest.Message) + } + return manifest +}