Documentation
¶
Overview ¶
Attempt at high level client library for AniDB's APIs
Index ¶
- Constants
- Variables
- func AnimeCount() int
- func Banned() bool
- func CacheGet(v interface{}, key ...fscache.CacheKey) (err error)
- func CacheSet(v interface{}, key ...fscache.CacheKey) (err error)
- func RefreshTitles() error
- func SearchAnimeAll(name string) titles.ResultSet
- func SearchAnimeFoldAll(name string) titles.ResultSet
- func TitlesUpToDate() (ok bool)
- type AID
- type AniDB
- func (adb *AniDB) AnimeByID(aid AID) <-chan *Anime
- func (adb *AniDB) AnimeByName(name string) <-chan *Anime
- func (adb *AniDB) AnimeByNameFold(name string) <-chan *Anime
- func (adb *AniDB) Auth(username, password, udpKey string) (err error)
- func (adb *AniDB) EpisodeByID(eid EID) <-chan *Episode
- func (adb *AniDB) FIDsByGID(ep *Episode, gid GID) <-chan FID
- func (adb *AniDB) FileByEd2kSize(ed2k string, size int64) <-chan *File
- func (adb *AniDB) FileByID(fid FID) <-chan *File
- func (adb *AniDB) FilesByGID(ep *Episode, gid GID) <-chan *File
- func (adb *AniDB) FilesByGroup(ep *Episode, g *Group) <-chan *File
- func (adb *AniDB) GetCurrentUser() <-chan *User
- func (adb *AniDB) GetUserByID(uid UID) <-chan *User
- func (adb *AniDB) GetUserByName(username string) <-chan *User
- func (adb *AniDB) GetUserName(uid UID) <-chan string
- func (adb *AniDB) GetUserUID(username string) <-chan UID
- func (adb *AniDB) GroupByID(gid GID) <-chan *Group
- func (adb *AniDB) GroupByName(gname string) <-chan *Group
- func (adb *AniDB) Logout() error
- func (adb *AniDB) MyListAdd(f *File, set *MyListSet) <-chan LID
- func (adb *AniDB) MyListAddByEd2kSize(ed2k string, size int64, set *MyListSet) <-chan LID
- func (adb *AniDB) MyListAnime(aid AID) <-chan *MyListAnime
- func (adb *AniDB) MyListByFID(fid FID) <-chan *MyListEntry
- func (adb *AniDB) MyListByFile(f *File) <-chan *MyListEntry
- func (adb *AniDB) MyListByLID(lid LID) <-chan *MyListEntry
- func (adb *AniDB) MyListDel(f *File) <-chan bool
- func (adb *AniDB) MyListEdit(f *File, set *MyListSet) <-chan bool
- func (adb *AniDB) MyListStats(user *User) <-chan *MyListStats
- func (adb *AniDB) SetCredentials(username, password, udpKey string)
- func (adb *AniDB) UpdateTitles() error
- func (adb *AniDB) User() *User
- func (adb *AniDB) UserMyListAnime(uid UID, aid AID) <-chan *MyListAnime
- type Anime
- func (a *Anime) Episode(ep *misc.Episode) *Episode
- func (a *Anime) EpisodeByEID(eid EID) *Episode
- func (a *Anime) EpisodeByNumber(number int) *Episode
- func (a *Anime) EpisodeByString(name string) *Episode
- func (a *Anime) EpisodeList(c misc.EpisodeContainer) (eps []*Episode)
- func (a *Anime) IsStale() bool
- func (a *Anime) MyList(adb *AniDB) <-chan *MyListAnime
- type AnimeType
- type AudioStream
- type EID
- type Episode
- type FID
- type File
- type FileSource
- type FileState
- type FileVersion
- type GID
- type Group
- type GroupEpisodes
- type GroupRelationType
- type GroupRelations
- type LID
- type LIDMap
- type Language
- type MyListAnime
- type MyListEntry
- type MyListSet
- type MyListState
- type MyListStateMap
- type MyListStats
- type Rating
- type RelatedEpisodes
- type Resource
- type Resources
- type TitleMap
- type UID
- type UniqueTitleMap
- type User
- type VideoInfo
Constants ¶
const ( AnimeTypeTVSeries = AnimeType("TV Series") // Anime was a regular TV broadcast series AnimeTypeTVSpecial = AnimeType("TV Special") // Anime was broadcast on TV as a special AnimeTypeMovie = AnimeType("Movie") // Anime was a feature film AnimeTypeOVA = AnimeType("OVA") // Anime was released direct-to-video AnimeTypeWeb = AnimeType("Web") // Anime was released through online streaming or downloads AnimeTypeMusicVideo = AnimeType("Music Video") )
const ( GroupParticipantIn = GroupRelationType(1 + iota) GroupParentOf GroupMergedFrom GroupNowKnownAs GroupOther GroupChildOf = GroupRelationType(102) )
const ( MyListStateUnknown = MyListState(iota) MyListStateHDD MyListStateCD MyListStateDeleted )
const ( FileStateOriginal = FileState(iota) FileStateCorrupted FileStateEdited FileStateOther = 100 )
const ( FileStateSelfRip = FileState(10 + iota) FileStateDVD FileStateVHS FileStateTV FileStateTheaters FileStateStreamed )
Variables ¶
var ( // Default durations for the various caches. // Used by the IsStale methods. DefaultCacheDuration = 7 * 24 * time.Hour AnimeCacheDuration = DefaultCacheDuration EpisodeCacheDuration = DefaultCacheDuration GroupCacheDuration = 4 * DefaultCacheDuration // They don't change that often. FileCacheDuration = 8 * DefaultCacheDuration // These change even less often. MyListCacheDuration = 12 * time.Hour // When the file isn't watched MyListWatchedCacheDuration = 2 * DefaultCacheDuration // When the file is watched LIDCacheDuration = 4 * DefaultCacheDuration UIDCacheDuration = 16 * DefaultCacheDuration // Can these even be changed? // Used for anime that have already finished airing. // It's unlikely that they get any important updates. FinishedAnimeCacheDuration = 4 * AnimeCacheDuration // Used when a request uses a non-existing key (AID, ed2k+size, etc) InvalidKeyCacheDuration = 1 * time.Hour // Used when the UDP API Anime query fails, but the HTTP API query succeeds. AnimeIncompleteCacheDuration = 24 * time.Hour // Used when there's some data missing on a file. // Usually happens because the AVDump data hasn't been merged with the database // yet, which is done on a daily cron job. FileIncompleteCacheDuration = 24 * time.Hour )
var Cache fscache.CacheDir
Functions ¶
func Banned ¶
func Banned() bool
Returns whether the last UDP API access returned a 555 BANNED message.
func RefreshTitles ¶
func RefreshTitles() error
Loads the database from anime-titles.dat.gz in the cache dir.
func SearchAnimeAll ¶
Searches for all anime that match the given anime name, case sensitive.
func SearchAnimeFoldAll ¶
Searches for all anime that match the given anime name, case folding.
func TitlesUpToDate ¶
func TitlesUpToDate() (ok bool)
Returns true if the titles database is up-to-date (newer than 24 hours).
Types ¶
type AID ¶
type AID int
Unique Anime IDentifier.
func SearchAnime ¶
Searches for the given anime name, case sensitive.
Returns the match with the smallest AID.
func SearchAnimeFold ¶
Searches for the given anime name, case folding.
Returns the match with the smallest AID.
type AniDB ¶
type AniDB struct { Timeout time.Duration // Timeout for the various calls (default: 45s) Logger *log.Logger // Logger where HTTP/UDP traffic is logged // contains filtered or unexported fields }
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.
Queries return their results using channels. Most queries only have one result, but some have 0 or more. All result channels are closed after sending their data.
Queries that depend on the UDP API can't be used without first authenticating to the API server. This uses the credentials stored by SetCredentials, or by a previous Auth() call.
func (*AniDB) AnimeByID ¶
Retrieves an Anime by its AID. Uses both the HTTP and UDP APIs, but can work without the UDP API.
func (*AniDB) AnimeByName ¶
Convenience method that runs AnimeByID on the result of SearchAnime.
func (*AniDB) AnimeByNameFold ¶
Convenience method that runs AnimeByID on the result of SearchAnimeFold.
func (*AniDB) Auth ¶
Authenticates to anidb's UDP API and, on success, stores the credentials using SetCredentials. If udpKey is not "", the communication with the server will be encrypted, but in the VERY weak ECB mode.
func (*AniDB) EpisodeByID ¶
Retrieves an Episode by its EID.
If we know which AID owns this EID, then it's equivalent to an Anime query. Otherwise, uses both the HTTP and UDP APIs to retrieve it.
func (*AniDB) FIDsByGID ¶
Gets the FIDs that the Group (given by its ID) has released for the given Episode. The returned channel may return multiple (or no) FIDs. Uses the UDP API.
On API error (offline, etc), the first *File returned is nil, followed by cached files (which may also be nil).
func (*AniDB) FileByEd2kSize ¶
Retrieves a File by its Ed2kHash + Filesize combination. Uses the UDP API.
func (*AniDB) FilesByGID ¶
Gets the Files that the Group (given by its ID) has released for the given Episode. The returned channel may return multiple (or no) Files. Uses the UDP API.
On API error (offline, etc), the first *File returned is nil, followed by cached files (which may also be nil).
func (*AniDB) FilesByGroup ¶
Gets the Files that the given Group has released for the given Episode. Convenience method that calls FilesByGID.
func (*AniDB) GetCurrentUser ¶
func (*AniDB) GetUserByID ¶
This is an (almost) entirely local representation.
func (*AniDB) GetUserByName ¶
func (*AniDB) GetUserName ¶
func (*AniDB) GetUserUID ¶
func (*AniDB) GroupByName ¶
Retrieves a Group by its name. Either full or short names are matched. Uses the UDP API.
func (*AniDB) MyListAddByEd2kSize ¶
func (*AniDB) MyListAnime ¶
func (adb *AniDB) MyListAnime(aid AID) <-chan *MyListAnime
func (*AniDB) MyListByFID ¶
func (adb *AniDB) MyListByFID(fid FID) <-chan *MyListEntry
func (*AniDB) MyListByFile ¶
func (adb *AniDB) MyListByFile(f *File) <-chan *MyListEntry
func (*AniDB) MyListByLID ¶
func (adb *AniDB) MyListByLID(lid LID) <-chan *MyListEntry
func (*AniDB) MyListStats ¶
func (adb *AniDB) MyListStats(user *User) <-chan *MyListStats
func (*AniDB) SetCredentials ¶
Saves the used credentials in the AniDB struct, to allow automatic re-authentication when needed; they are (properly) encrypted with a key that's uniquely generated every time the module is initialized.
func (*AniDB) UpdateTitles ¶
Downloads a new anime-titles database if the database is outdated.
Saves the database as anime-titles.dat.gz in the cache dir.
func (*AniDB) UserMyListAnime ¶
func (adb *AniDB) UserMyListAnime(uid UID, aid AID) <-chan *MyListAnime
type Anime ¶
type Anime struct { AID AID // The Anime ID. R18 bool // Whether this anime is considered porn. Type AnimeType // Production/distribution type. TotalEpisodes int // Total number of regular episodes. EpisodeCount misc.EpisodeCount // Known numbers of the various types of episodes. StartDate time.Time // Date of first episode release, if available. EndDate time.Time // Date of last episode release, if available. PrimaryTitle string // The primary title in the database; almost always a romanization of the Japanese title. OfficialTitles UniqueTitleMap // The official title for each language. ShortTitles TitleMap // Shortcut titles used for searches Synonyms TitleMap // Synonyms for each language, or unofficial titles OfficialURL string // URL for original official website. Picture string // URL for the page picture on AniDB. Description string Votes Rating // Votes from people who watched the whole thing. TemporaryVotes Rating // Votes from people who are still watching this. Reviews Rating // Votes from reviewers. Episodes []*Episode // List of episodes. Awards []string Resources Resources Incomplete bool // Set if the UDP API part of the query failed. Updated time.Time // When the data was last modified in the server. Cached time.Time // When the data was retrieved from the server. }
func (*Anime) Episode ¶
Searches for the given Episode in this Anime's Episodes list and returns the match.
Returns nil if there is no match.
func (*Anime) EpisodeByEID ¶
func (*Anime) EpisodeByNumber ¶
Convenience method that parses the int into an Episode before doing the Episode search.
Only works with regular (i.e. not special, etc) episodes.
func (*Anime) EpisodeByString ¶
Convenience method that parses the string into an Episode before doing the Episode search.
func (*Anime) EpisodeList ¶
func (a *Anime) EpisodeList(c misc.EpisodeContainer) (eps []*Episode)
Returns a list of all Episodes in this Anime's Episodes list that are contained by the given EpisodeContainer.
func (*Anime) MyList ¶
func (a *Anime) MyList(adb *AniDB) <-chan *MyListAnime
type AudioStream ¶
type Episode ¶
type Episode struct { EID EID // The Episode ID. AID AID // The Anime ID this Episode belongs to. // Type, Number misc.Episode Length time.Duration // rounded somehow to minutes AirDate *time.Time // The original release date, if available. Rating Rating // Episode-specific ratings. Titles UniqueTitleMap // Map with a title for each language Cached time.Time // When the data was retrieved from the server }
type File ¶
type File struct { FID FID AID AID EID EID GID GID LID LIDMap EpisodeString string EpisodeNumber misc.EpisodeList Incomplete bool Deprecated bool CRCMatch bool BadCRC bool Version FileVersion Uncensored bool // Meaning unclear, may not be simply !Censored Censored bool // Meaning unclear, may not be simply !Uncensored Filesize int64 Ed2kHash string SHA1Hash string CRC32 string Length time.Duration AirDate time.Time AudioStreams []AudioStream SubtitleLanguages []Language VideoInfo VideoInfo FileExtension string Source FileSource // Map of related EIDs to percentages (range 0.0-1.0). // The percentage indicates how much of the EID is covered by this file. RelatedEpisodes RelatedEpisodes Cached time.Time }
func (*File) Prefetch ¶
Prefetches the Anime, Episode and Group that this file is linked to using the given AniDB instance.
Returns a channel where this file will be sent to when the prefetching is done; if the file is nil, the channel will return nil.
func (*File) UserMyList ¶
func (f *File) UserMyList(user *User) *MyListEntry
type FileSource ¶
type FileSource string
type FileVersion ¶
type FileVersion int
func (FileVersion) String ¶
func (v FileVersion) String() string
type Group ¶
type Group struct { GID GID Name string // Full name ShortName string // Abbreviated name IRC string // irc: schema format URL string Picture string Founded time.Time Disbanded time.Time LastRelease time.Time LastActivity time.Time Rating Rating AnimeCount int // Number of anime this group has worked on FileCount int // Number of files this group has released RelatedGroups GroupRelations Cached time.Time }
type GroupEpisodes ¶
type GroupEpisodes map[GID]misc.EpisodeList
func (GroupEpisodes) MarshalJSON ¶
func (ge GroupEpisodes) MarshalJSON() ([]byte, error)
func (GroupEpisodes) UnmarshalJSON ¶
func (ge GroupEpisodes) UnmarshalJSON(b []byte) error
type GroupRelationType ¶
type GroupRelationType int
See the constants list for valid values.
func (GroupRelationType) String ¶
func (gr GroupRelationType) String() string
type GroupRelations ¶
type GroupRelations map[GID]GroupRelationType
func (GroupRelations) MarshalJSON ¶
func (gr GroupRelations) MarshalJSON() ([]byte, error)
func (GroupRelations) UnmarshalJSON ¶
func (gr GroupRelations) UnmarshalJSON(b []byte) error
type MyListAnime ¶
type MyListAnime struct { AID AID EpisodesWithState MyListStateMap WatchedEpisodes misc.EpisodeList EpisodesPerGroup GroupEpisodes Cached time.Time }
func (*MyListAnime) IsStale ¶
func (a *MyListAnime) IsStale() bool
type MyListEntry ¶
type MyListEntry struct { LID LID FID FID EID EID AID AID GID GID DateAdded time.Time DateWatched time.Time State FileState MyListState MyListState Storage string Source string Other string Cached time.Time }
func (*MyListEntry) Anime ¶
func (e *MyListEntry) Anime() *Anime
func (*MyListEntry) Episode ¶
func (e *MyListEntry) Episode() *Episode
func (*MyListEntry) File ¶
func (e *MyListEntry) File() *File
func (*MyListEntry) Group ¶
func (e *MyListEntry) Group() *Group
func (*MyListEntry) IsStale ¶
func (e *MyListEntry) IsStale() bool
type MyListSet ¶
type MyListSet struct { State *MyListState Watched *bool ViewDate *time.Time Source *string Storage *string Other *string }
These are all pointers because they're not sent at all if they're nil
type MyListState ¶
type MyListState int
type MyListStateMap ¶
type MyListStateMap map[MyListState]misc.EpisodeList
func (MyListStateMap) MarshalJSON ¶
func (sm MyListStateMap) MarshalJSON() ([]byte, error)
func (MyListStateMap) UnmarshalJSON ¶
func (sm MyListStateMap) UnmarshalJSON(b []byte) error
type MyListStats ¶
type MyListStats struct { Anime int Episodes int Files int Filesize int64 AddedAnime int AddedEpisodes int AddedFiles int AddedGroups int Leech float32 // rate of Files to AddedFiles Glory float32 // meaning undocumented ViewedPctDatabase float32 MyListPctDatabase float32 AnimePctDatabase float32 // Only valid if the titles database is loaded ViewedPctMyList float32 ViewedEpisodes int Votes int Reviews int ViewedTime time.Duration Cached time.Time }
func (*MyListStats) IsStale ¶
func (s *MyListStats) IsStale() bool
type RelatedEpisodes ¶
func (RelatedEpisodes) MarshalJSON ¶
func (er RelatedEpisodes) MarshalJSON() ([]byte, error)
func (RelatedEpisodes) UnmarshalJSON ¶
func (er RelatedEpisodes) UnmarshalJSON(b []byte) error
type Resources ¶
type Resources struct { AniDB, ANN, MyAnimeList, AnimeNfo, OfficialJapanese, OfficialEnglish, WikipediaEnglish, WikipediaJapanese, SyoboiSchedule, AllCinema, Anison, VNDB, MaruMegane Resource }
Links to third party websites
type UID ¶
type UID int
func (UID) MyList ¶
func (uid UID) MyList(fid FID) *MyListEntry
func (UID) MyListAnime ¶
func (uid UID) MyListAnime(aid AID) *MyListAnime
type UniqueTitleMap ¶
type User ¶
func UserByName ¶
func (*User) MyListAnime ¶
func (u *User) MyListAnime(aid AID) *MyListAnime
func (*User) Stats ¶
func (u *User) Stats() *MyListStats
Source Files
¶
- anidb.go
- anime.go
- animecache.go
- auth.go
- cache.go
- episode.go
- episodecache.go
- file.go
- filecache.go
- fileepcache.go
- globals.go
- group.go
- groupcache.go
- intent.go
- misc.go
- misccache.go
- mylist.go
- mylistanime.go
- mylistanimecache.go
- mylistcache.go
- mylistmanip.go
- titlecache.go
- titles.go
- udp.go
- user.go
- usercache.go
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
Low-level wrapper around the AniDB HTTP API.
|
Low-level wrapper around the AniDB HTTP API. |
Definitions and utilities used by the other go-anidb modules, or that don't fit within any of the other modules.
|
Definitions and utilities used by the other go-anidb modules, or that don't fit within any of the other modules. |
Implements parsing and searching of the anime-titles.dat database.
|
Implements parsing and searching of the anime-titles.dat database. |
Low-level AniDB UDP API client library Implements the commands essential to setting up and tearing down an API connection, as well as an asynchronous layer.
|
Low-level AniDB UDP API client library Implements the commands essential to setting up and tearing down an API connection, as well as an asynchronous layer. |