anidb

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2021 License: Apache-2.0 Imports: 12 Imported by: 2

README

go.felesatra.moe/anidb

See https://pkg.go.dev/go.felesatra.moe/anidb

Documentation

Overview

Package anidb provides Go bindings for AniDB APIs.

Read the AniDB API documentation for up to date information, especially about request limits. You are responsible for configuring rate limiting correctly.

Documentation for the AniDB APIs can be found at https://wiki.anidb.net/w/API.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Anime

type Anime struct {
	AID          int       `xml:"id,attr"`
	Titles       []Title   `xml:"titles>title"`
	Type         string    `xml:"type"`
	EpisodeCount int       `xml:"episodecount"`
	StartDate    string    `xml:"startdate"`
	EndDate      string    `xml:"enddate"`
	Episodes     []Episode `xml:"episodes>episode"`
}

An Anime holds information for an anime returned from the AniDB HTTP API.

func RequestAnime

func RequestAnime(c Client, aid int) (*Anime, error)

RequestAnime requests anime information from AniDB. This is deprecated; use the Client.RequestAnime method instead.

type AnimeT

type AnimeT struct {
	AID    int     `xml:"aid,attr"`
	Titles []Title `xml:"title"`
}

An AnimeT is like Anime but holds title information only. This is used for representing anime titles from the AniDB title dump.

func DecodeTitles

func DecodeTitles(d []byte) ([]AnimeT, error)

DecodeTitles decodes XML title information from an AniDB title dump. The input should be uncompressed XML.

func RequestTitles

func RequestTitles() ([]AnimeT, error)

RequestTitles requests title information from AniDB.

TitlesCache is more convenient to use, as AniDB has severe rate limits on this.

type Client

type Client struct {
	Name    string
	Version int
	// Limiter specifies a rate limiter to use.
	// If unset, no rate limiting is done.
	Limiter Limiter
}

A Client is a client for the AniDB HTTP API. Read the AniDB API documentation about registering a client.

Example
package main

import (
	"fmt"

	"go.felesatra.moe/anidb"
)

func main() {
	c := anidb.Client{
		Name:    "go.felesatra.moe/anidb example",
		Version: 1,
	}
	a, err := c.RequestAnime(8076)
	if err != nil {
		panic(err)
	}
	fmt.Print(a.EpisodeCount)
}
Output:

func (*Client) RequestAnime added in v1.1.0

func (c *Client) RequestAnime(aid int) (*Anime, error)

RequestAnime requests anime information from AniDB.

type EpTitle

type EpTitle struct {
	Title string `xml:",chardata"`
	Lang  string `xml:"http://www.w3.org/XML/1998/namespace lang,attr"`
}

An EpTitle holds information for a single episode title returned from the AniDB HTTP API.

type Episode

type Episode struct {
	EID int `xml:"id,attr"`
	// EpNo is a concatenation of a type string and episode number.  It
	// should be unique among the episodes for an anime, so it can serve
	// as a unique identifier.
	EpNo string `xml:"epno"`
	// Length is the length of the episode in minutes.
	Length int       `xml:"length"`
	Titles []EpTitle `xml:"title"`
}

An Episode holds information for an episode returned from the AniDB HTTP API.

type Limiter added in v1.1.0

type Limiter interface {
	Wait(context.Context) error
}

A Limiter implements rate limiting. The golang.org/x/time/rate package provides an implementation.

type Title

type Title struct {
	Name string `xml:",chardata"`
	Type string `xml:"type,attr"`
	Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr"`
}

A Title holds information for a single anime title returned from the AniDB HTTP API.

type TitlesCache added in v1.1.0

type TitlesCache struct {
	// Path is the path to the cache file.
	Path string
	// Titles is the titles loaded from the cache.
	Titles []AnimeT
	// Updated indicates if the cached titles were updated.
	// This is set to true when any method updates the cache.
	Updated bool
}

A TitlesCache is a cache for AniDB titles data.

Example
package main

import (
	"strings"

	"go.felesatra.moe/anidb"
)

func main() {
	c, err := anidb.DefaultTitlesCache()
	if err != nil {
		panic(err)
	}
	defer c.SaveIfUpdated()
	titles, err := c.GetTitles()
	if err != nil {
		panic(err)
	}
	var matched []anidb.AnimeT
	for _, anime := range titles {
		for _, t := range anime.Titles {
			if strings.Index(t.Name, "bofuri") >= 0 {
				matched = append(matched)
			}
		}
	}
}
Output:

func DefaultTitlesCache added in v1.1.0

func DefaultTitlesCache() (*TitlesCache, error)

DefaultTitlesCache opens a TitlesCache at a default location, using XDG_CACHE_DIR.

func OpenTitlesCache added in v1.1.0

func OpenTitlesCache(path string) (*TitlesCache, error)

OpenTitlesCache opens a TitlesCache.

func (*TitlesCache) GetFreshTitles added in v1.1.0

func (c *TitlesCache) GetFreshTitles() ([]AnimeT, error)

GetFreshTitles downloads titles from AniDB and stores it in the cache. See AniDB API documentation about rate limits.

func (*TitlesCache) GetTitles added in v1.1.0

func (c *TitlesCache) GetTitles() ([]AnimeT, error)

GetTitles gets titles from the cache. If the cache has not been populated yet, downloads titles from AniDB.

func (*TitlesCache) Save added in v1.1.0

func (c *TitlesCache) Save() error

Save saves the cached titles to the cache file. This method sets Updated to false if successful. See also the SaveIfUpdated method, which is probably more useful.

func (*TitlesCache) SaveIfUpdated added in v1.2.0

func (c *TitlesCache) SaveIfUpdated() error

SaveIfUpdated saves the cached titles to the cache file if they have been updated. This method sets Updated to false if successful.

Directories

Path Synopsis
cache
titles
Package titles provides a cache for AniDB titles data.
Package titles provides a cache for AniDB titles data.

Jump to

Keyboard shortcuts

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