anidb

package module
v0.0.0-...-57d0119 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2014 License: MIT Imports: 25 Imported by: 3

Documentation

Overview

Attempt at high level client library for AniDB's APIs

Index

Constants

View Source
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")
)
View Source
const (
	GroupParticipantIn = GroupRelationType(1 + iota)
	GroupParentOf

	GroupMergedFrom
	GroupNowKnownAs
	GroupOther

	GroupChildOf = GroupRelationType(102)
)
View Source
const (
	MyListStateUnknown = MyListState(iota)
	MyListStateHDD
	MyListStateCD
	MyListStateDeleted
)
View Source
const (
	FileStateOriginal = FileState(iota)
	FileStateCorrupted
	FileStateEdited

	FileStateOther = 100
)
View Source
const (
	FileStateSelfRip = FileState(10 + iota)
	FileStateDVD
	FileStateVHS
	FileStateTV
	FileStateTheaters
	FileStateStreamed
)

Variables

View Source
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
)
View Source
var Cache fscache.CacheDir

Functions

func AnimeCount

func AnimeCount() int

Returns the number of anime in the titles database

func Banned

func Banned() bool

Returns whether the last UDP API access returned a 555 BANNED message.

func CacheGet

func CacheGet(v interface{}, key ...fscache.CacheKey) (err error)

func CacheSet

func CacheSet(v interface{}, key ...fscache.CacheKey) (err error)

func RefreshTitles

func RefreshTitles() error

Loads the database from anime-titles.dat.gz in the cache dir.

func SearchAnimeAll

func SearchAnimeAll(name string) titles.ResultSet

Searches for all anime that match the given anime name, case sensitive.

func SearchAnimeFoldAll

func SearchAnimeFoldAll(name string) titles.ResultSet

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

func SearchAnime(name string) AID

Searches for the given anime name, case sensitive.

Returns the match with the smallest AID.

func SearchAnimeFold

func SearchAnimeFold(name string) AID

Searches for the given anime name, case folding.

Returns the match with the smallest AID.

func (AID) Anime

func (aid AID) Anime() *Anime

Returns a cached Anime. Returns nil if there is no cached Anime with this 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 NewAniDB

func NewAniDB() *AniDB

Initialises a new AniDB.

func (*AniDB) AnimeByID

func (adb *AniDB) AnimeByID(aid AID) <-chan *Anime

Retrieves an Anime by its AID. Uses both the HTTP and UDP APIs, but can work without the UDP API.

func (*AniDB) AnimeByName

func (adb *AniDB) AnimeByName(name string) <-chan *Anime

Convenience method that runs AnimeByID on the result of SearchAnime.

func (*AniDB) AnimeByNameFold

func (adb *AniDB) AnimeByNameFold(name string) <-chan *Anime

Convenience method that runs AnimeByID on the result of SearchAnimeFold.

func (*AniDB) Auth

func (adb *AniDB) Auth(username, password, udpKey string) (err error)

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

func (adb *AniDB) EpisodeByID(eid EID) <-chan *Episode

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

func (adb *AniDB) FIDsByGID(ep *Episode, gid GID) <-chan FID

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

func (adb *AniDB) FileByEd2kSize(ed2k string, size int64) <-chan *File

Retrieves a File by its Ed2kHash + Filesize combination. Uses the UDP API.

func (*AniDB) FileByID

func (adb *AniDB) FileByID(fid FID) <-chan *File

Retrieves a File by its FID. Uses the UDP API.

func (*AniDB) FilesByGID

func (adb *AniDB) FilesByGID(ep *Episode, gid GID) <-chan *File

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

func (adb *AniDB) FilesByGroup(ep *Episode, g *Group) <-chan *File

Gets the Files that the given Group has released for the given Episode. Convenience method that calls FilesByGID.

func (*AniDB) GetCurrentUser

func (adb *AniDB) GetCurrentUser() <-chan *User

func (*AniDB) GetUserByID

func (adb *AniDB) GetUserByID(uid UID) <-chan *User

This is an (almost) entirely local representation.

func (*AniDB) GetUserByName

func (adb *AniDB) GetUserByName(username string) <-chan *User

func (*AniDB) GetUserName

func (adb *AniDB) GetUserName(uid UID) <-chan string

func (*AniDB) GetUserUID

func (adb *AniDB) GetUserUID(username string) <-chan UID

func (*AniDB) GroupByID

func (adb *AniDB) GroupByID(gid GID) <-chan *Group

Retrieves a Group by its GID. Uses the UDP API.

func (*AniDB) GroupByName

func (adb *AniDB) GroupByName(gname string) <-chan *Group

Retrieves a Group by its name. Either full or short names are matched. Uses the UDP API.

func (*AniDB) Logout

func (adb *AniDB) Logout() error

Logs the user out and removes the credentials from the AniDB struct.

func (*AniDB) MyListAdd

func (adb *AniDB) MyListAdd(f *File, set *MyListSet) <-chan LID

func (*AniDB) MyListAddByEd2kSize

func (adb *AniDB) MyListAddByEd2kSize(ed2k string, size int64, set *MyListSet) <-chan LID

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) MyListDel

func (adb *AniDB) MyListDel(f *File) <-chan bool

func (*AniDB) MyListEdit

func (adb *AniDB) MyListEdit(f *File, set *MyListSet) <-chan bool

func (*AniDB) MyListStats

func (adb *AniDB) MyListStats(user *User) <-chan *MyListStats

func (*AniDB) SetCredentials

func (adb *AniDB) SetCredentials(username, password, udpKey string)

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

func (adb *AniDB) UpdateTitles() error

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) User

func (adb *AniDB) User() *User

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

func (a *Anime) Episode(ep *misc.Episode) *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 (a *Anime) EpisodeByEID(eid EID) *Episode

func (*Anime) EpisodeByNumber

func (a *Anime) EpisodeByNumber(number int) *Episode

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

func (a *Anime) EpisodeByString(name string) *Episode

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) IsStale

func (a *Anime) IsStale() bool

func (*Anime) MyList

func (a *Anime) MyList(adb *AniDB) <-chan *MyListAnime

type AnimeType

type AnimeType string

See the constants list for the valid values.

type AudioStream

type AudioStream struct {
	Codec    string
	Bitrate  int
	Language Language
}

type EID

type EID int

Unique Episode IDentifier.

func (EID) Episode

func (eid EID) Episode() *Episode

Retrieves the Episode corresponding to this EID from the cache.

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
}

func (*Episode) Anime

func (ep *Episode) Anime() *Anime

func (*Episode) IsStale

func (e *Episode) IsStale() bool

type FID

type FID int

func (FID) File

func (fid FID) File() *File

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) Anime

func (f *File) Anime() *Anime

func (*File) Episode

func (f *File) Episode() *Episode

func (*File) Group

func (f *File) Group() *Group

func (*File) IsStale

func (f *File) IsStale() bool

func (*File) Prefetch

func (f *File) Prefetch(adb *AniDB) <-chan *File

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 FileState

type FileState int

type FileVersion

type FileVersion int

func (FileVersion) String

func (v FileVersion) String() string

type GID

type GID int

Unique Group IDentifier

func (GID) Group

func (gid GID) Group() *Group

Retrieves the Group from the cache.

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
}

func (*Group) IsStale

func (g *Group) IsStale() bool

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 LID

type LID int64

func (LID) MyListEntry

func (lid LID) MyListEntry() *MyListEntry

type LIDMap

type LIDMap map[UID]LID

func (LIDMap) MarshalJSON

func (m LIDMap) MarshalJSON() ([]byte, error)

func (LIDMap) UnmarshalJSON

func (m LIDMap) UnmarshalJSON(b []byte) error

type Language

type Language string

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 Rating

type Rating struct {
	Rating    float32
	VoteCount int
}

type RelatedEpisodes

type RelatedEpisodes map[EID]float32

func (RelatedEpisodes) MarshalJSON

func (er RelatedEpisodes) MarshalJSON() ([]byte, error)

func (RelatedEpisodes) UnmarshalJSON

func (er RelatedEpisodes) UnmarshalJSON(b []byte) error

type Resource

type Resource []string

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 TitleMap

type TitleMap map[Language][]string

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

func (UID) User

func (uid UID) User() *User

type UniqueTitleMap

type UniqueTitleMap map[Language]string

type User

type User struct {
	UID UID

	Username string
}

func UserByName

func UserByName(name string) *User

func (*User) MyListAnime

func (u *User) MyListAnime(aid AID) *MyListAnime

func (*User) Stats

func (u *User) Stats() *MyListStats

type VideoInfo

type VideoInfo struct {
	Codec      string
	Bitrate    int
	Resolution image.Rectangle
	ColorDepth int
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL