5 "github.com/Kovensky/go-anidb/http"
12 gob.RegisterName("*github.com/Kovensky/go-anidb.Group", &Group{})
15 func (g *Group) Touch() {
19 func (g *Group) IsStale() bool {
23 return time.Now().Sub(g.Cached) > GroupCacheDuration
26 // Unique Group IDentifier
29 // Retrieves the Group from the cache.
30 func (gid GID) Group() *Group {
32 if cache.Get(&g, "gid", gid) == nil {
38 // Returns a Group from the cache if possible.
40 // If the Group is stale, then retrieves the Group
41 // through the UDP API.
42 func (adb *AniDB) GroupByID(gid GID) <-chan *Group {
43 keys := []cacheKey{"gid", gid}
44 ch := make(chan *Group, 1)
46 ic := make(chan Cacheable, 1)
47 go func() { ch <- (<-ic).(*Group); close(ch) }()
48 if intentMap.Intent(ic, keys...) {
52 if g := gid.Group(); !g.IsStale() {
53 intentMap.Notify(g, keys...)
58 reply := <-adb.udp.SendRecv("GROUP",
62 if reply.Error() == nil {
63 parts := strings.Split(reply.Lines()[1], "|")
64 ints := make([]int64, len(parts))
65 for i := range parts {
66 ints[i], _ = strconv.ParseInt(parts[i], 10, 32)
71 irc = "irc://" + parts[8] + "/" + parts[7][1:]
76 pic = httpapi.AniDBImageBaseURL + parts[10]
79 rellist := strings.Split(parts[16], "'")
80 relations := make(map[GID]GroupRelationType, len(rellist))
81 for _, rel := range rellist {
82 r := strings.Split(rel, ",")
83 gid, _ := strconv.ParseInt(r[0], 10, 32)
84 typ, _ := strconv.ParseInt(r[1], 10, 32)
86 relations[GID(gid)] = GroupRelationType(typ)
89 ft := time.Unix(ints[11], 0)
93 dt := time.Unix(ints[12], 0)
97 lr := time.Unix(ints[14], 0)
101 la := time.Unix(ints[15], 0)
123 Rating: float32(ints[1]) / 100,
124 VoteCount: int(ints[2]),
126 AnimeCount: int(ints[3]),
127 FileCount: int(ints[4]),
129 RelatedGroups: relations,
134 cache.Set(g, keys...)
135 intentMap.Notify(g, keys...)