move manifest related code to its own file
This commit is contained in:
parent
ebc13c3be3
commit
70e617594a
2 changed files with 34 additions and 30 deletions
30
main.go
30
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)
|
||||
|
|
34
manifest.go
Normal file
34
manifest.go
Normal file
|
@ -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
|
||||
}
|
Loading…
Add table
Reference in a new issue