)
// Main struct for the client, contains all non-shared state.
+//
+// All ObjectByKey methods (AnimeByID, GroupByName, etc) first try to read
+// from the cache. If the sought object isn't cached, or if the cache is
+// stale, then the appropriate API is queried.
type AniDB struct {
Timeout time.Duration // Timeout for the various calls (default: 45s)
err error
}
-// Retrieves an Anime from the cache if possible. If it isn't cached,
-// or if the cache is stale, queries both the UDP and HTTP APIs
-// for data.
-//
-// Note: This can take at least 4 seconds during heavy traffic.
+// Retrieves an Anime by its AID. Uses both HTTP and UDP APIs,
+// but can work without the UDP API.
func (adb *AniDB) AnimeByID(aid AID) <-chan *Anime {
keys := []cacheKey{"aid", aid}
ch := make(chan *Anime, 1)
cache.Set(ep, "eid", ep.EID)
}
-// Retrieves the Episode from the cache if possible.
-//
-// If the result is stale, then queries the UDP API to
-// know which AID owns this EID, then gets the episode
-// from the Anime.
+// Retrieves an Episode by its EID.
func (adb *AniDB) EpisodeByID(eid EID) <-chan *Episode {
keys := []cacheKey{"eid", eid}
ch := make(chan *Episode, 1)
return ch
}
-// Returns the File from the cache if possible.
-//
-// If the File is stale, then retrieves the File through the UDP API.
+// Retrieves a File by its FID.
func (adb *AniDB) FileByID(fid FID) <-chan *File {
keys := []cacheKey{"fid", fid}
return ch
}
-// Returns the File from the cache if possible.
-//
-// If the File is stale, then retrieves the File through the UDP API.
+// Retrieves a File by its Ed2kHash + Filesize combination.
func (adb *AniDB) FileByEd2kSize(ed2k string, size int64) <-chan *File {
keys := []cacheKey{"fid", "by-ed2k", ed2k, size}
return true
}
-// Returns a Group from the cache if possible.
-//
-// If the Group is stale, then retrieves the Group
-// through the UDP API.
+// Retrieves a Group by its GID.
func (adb *AniDB) GroupByID(gid GID) <-chan *Group {
keys := []cacheKey{"gid", gid}
ch := make(chan *Group, 1)
return ch
}
+// Retrieves a Group by its name. Either full or short names are matched.
func (adb *AniDB) GroupByName(gname string) <-chan *Group {
keys := []cacheKey{"gid", "by-name", gname}
altKeys := []cacheKey{"gid", "by-shortname", gname}