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 {
31 g, _ := caches.Get(groupCache).Get(int(gid)).(*Group)
35 // Returns a Group from the cache if possible.
37 // If the Group is stale, then retrieves the Group
38 // through the UDP API.
39 func (adb *AniDB) GroupByID(gid GID) <-chan *Group {
40 ch := make(chan *Group, 1)
41 if g := gid.Group(); !g.IsStale() {
47 gc := caches.Get(groupCache)
49 ic := make(chan Cacheable, 1)
50 go func() { ch <- (<-ic).(*Group); close(ch) }()
52 if gc.Intent(int(gid), ic) {
57 reply := <-adb.udp.SendRecv("GROUP",
61 if reply.Error() == nil {
62 parts := strings.Split(reply.Lines()[1], "|")
63 ints := make([]int64, len(parts))
64 for i := range parts {
65 ints[i], _ = strconv.ParseInt(parts[i], 10, 32)
70 irc = "irc://" + parts[8] + "/" + parts[7][1:]
75 pic = httpapi.AniDBImageBaseURL + parts[10]
78 rellist := strings.Split(parts[16], "'")
79 relations := make(map[GID]GroupRelationType, len(rellist))
80 for _, rel := range rellist {
81 r := strings.Split(rel, ",")
82 gid, _ := strconv.ParseInt(r[0], 10, 32)
83 typ, _ := strconv.ParseInt(r[1], 10, 32)
85 relations[GID(gid)] = GroupRelationType(typ)
88 ft := time.Unix(ints[11], 0)
92 dt := time.Unix(ints[12], 0)
96 lr := time.Unix(ints[14], 0)
100 la := time.Unix(ints[15], 0)
122 Rating: float32(ints[1]) / 100,
123 VoteCount: int(ints[2]),
125 AnimeCount: int(ints[3]),
126 FileCount: int(ints[4]),
128 RelatedGroups: relations,