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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -17,24 +16,6 @@ type CliFlags struct {
|
||||||
verbose bool
|
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
|
type PostId uint64
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -67,17 +48,6 @@ func doPixivRequest(client *http.Client, url, referer, userAgent string) io.Read
|
||||||
return response.Body
|
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) {
|
func getUgoira(postId PostId, flags CliFlags) {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
artworkUrl := fmt.Sprintf(ArtworkUrlTemplate, postId)
|
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