blob: 38162d65858e923c7af0a0bdc8c135c2225f26a5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
package main
import (
"encoding/json"
"io/ioutil"
"path/filepath"
"strconv"
"strings"
"fagott.pw/grilist/models"
)
func ifErrExit(err error) {
if err != nil {
panic(err)
}
}
func toInt(s string) int {
i, err := strconv.ParseInt(s, 10, 32)
ifErrExit(err)
return int(i)
}
type ACDv2Reader struct{}
type ACDv2Series struct {
Name struct {
English string `json:"english"`
Romaji string `json:"romaji"`
Japanese string `json:"japanese"`
Furigana string `json:"furigana"`
Aliases []string `json:"aliases"`
} `json:"name"`
Tags []string `json:"tags"`
Image string `json:"image"`
}
func (r *ACDv2Reader) Read(path string) WrappedSeries {
s := WrappedSeries{}
data, err := ioutil.ReadFile(path)
ifErrExit(err)
var jObj ACDv2Series
err = json.Unmarshal(data, &jObj)
ifErrExit(err)
s.Image = jObj.Image
s.Series.ID = toInt(strings.TrimSuffix(filepath.Base(path), ".json"))
s.Series.Name = jObj.Name.English
s.Series.KanjiName = jObj.Name.Japanese
s.Series.RomajiName = jObj.Name.Romaji
s.Series.FuriganaName = jObj.Name.Furigana
s.Series.OtherNames = jObj.Name.Aliases
s.Series.Tags = jObj.Tags
return s
}
func (r *ACDv2Reader) ID() int {
return int(models.DataSourceACD)
}
|