package main import ( "encoding/json" "io/ioutil" "path/filepath" "strconv" "strings" "fagott.pw/grilist/modules/grils" ) 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(grils.DataSourceACD) }