metadata

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProviderNotFound   = errors.New("metadata provider not found")
	ErrNoResults          = errors.New("no search results found")
	ErrAuthRequired       = errors.New("authentication required for this provider")
	ErrInvalidCredentials = errors.New("invalid authentication credentials")
)

Functions

func DetermineMediaTypeByLanguage added in v1.6.1

func DetermineMediaTypeByLanguage(lang string) string

DetermineMediaTypeByLanguage returns a suggested type (media/manhwa/manhua/etc.) based on the original language code.

func ListProviders

func ListProviders() []string

ListProviders returns a list of all registered provider names

func RegisterProvider

func RegisterProvider(name string, constructor func(apiToken string) Provider)

RegisterProvider registers a new metadata provider constructor

func UpdateMedia added in v1.6.1

func UpdateMedia(media MediaUpdater, meta *MediaMetadata, coverArtURL string)

UpdateMedia updates media fields from metadata

func UpdateMediaFromAggregated added in v1.11.0

func UpdateMediaFromAggregated(media MediaUpdater, aggregatedMeta *AggregatedMediaMetadata, coverArtURL string)

UpdateMediaFromAggregated updates media fields from aggregated metadata

Types

type AggregatedMediaMetadata added in v1.11.0

type AggregatedMediaMetadata struct {
	// Primary fields (consolidated from all providers)
	Title             string   `json:"title"`
	AlternativeTitles []string `json:"alternative_titles"`
	Description       string   `json:"description"`
	Year              int      `json:"year"`
	OriginalLanguage  string   `json:"original_language"`
	Status            string   `json:"status"` // ongoing, completed, hiatus, cancelled
	ContentRating     string   `json:"content_rating"`
	CoverArtURLs      []string `json:"cover_art_urls"`
	Tags              []string `json:"tags"`
	Type              string   `json:"type"`
	Author            string   `json:"author"` // Backward compatibility

	// Additional rich metadata fields
	Authors       []AuthorInfo `json:"authors"`
	Artists       []AuthorInfo `json:"artists"`
	StartDate     string       `json:"start_date"`
	EndDate       string       `json:"end_date"`
	ChapterCount  int          `json:"chapter_count"`
	VolumeCount   int          `json:"volume_count"`
	AverageScore  float64      `json:"average_score"`
	Popularity    int          `json:"popularity"`
	Favorites     int          `json:"favorites"`
	Demographic   string       `json:"demographic"`
	Publisher     string       `json:"publisher"`
	Magazine      string       `json:"magazine"`
	Serialization string       `json:"serialization"`
	Genres        []string     `json:"genres"`
	Characters    []string     `json:"characters"`
	Relations     []Relation   `json:"relations"`

	// Attribution and source data
	AttributionLinks []AttributionLink         `json:"attribution_links"`
	ProviderData     map[string]*MediaMetadata `json:"provider_data"`
}

AggregatedMediaMetadata combines metadata from multiple providers

func AggregateMetadata added in v1.11.0

func AggregateMetadata(title string, providerResults map[string]*MediaMetadata) *AggregatedMediaMetadata

AggregateMetadata combines metadata from multiple providers into a single aggregated result

func QueryAllProviders added in v1.11.0

func QueryAllProviders(title string) (*AggregatedMediaMetadata, error)

QueryAllProviders searches all available metadata providers for a title and returns aggregated results

type AniListProvider

type AniListProvider struct {
	BaseProvider
}

AniListProvider implements the Provider interface for AniList GraphQL API

func (*AniListProvider) FindBestMatch

func (a *AniListProvider) FindBestMatch(title string) (*MediaMetadata, error)

func (*AniListProvider) GetMetadata

func (a *AniListProvider) GetMetadata(id string) (*MediaMetadata, error)

func (*AniListProvider) Search

func (a *AniListProvider) Search(title string) ([]SearchResult, error)
type AttributionLink struct {
	Provider string `json:"provider"`
	URL      string `json:"url"`
	Title    string `json:"title"`
}

AttributionLink represents a link to the source metadata page

type AuthorInfo added in v1.11.0

type AuthorInfo struct {
	Name string
	Role string // author, artist, illustrator, etc.
}

AuthorInfo represents author/artist information

type BaseProvider added in v1.12.0

type BaseProvider struct {
	ProviderName string
	APIToken     string
	Config       ConfigProvider
	Client       *http.Client
	BaseURL      string
}

BaseProvider provides default implementations of common Provider interface methods. Embed this in concrete providers to avoid repeating boilerplate.

func (*BaseProvider) DoGetJSON added in v1.12.0

func (b *BaseProvider) DoGetJSON(url string, target any) error

DoGetJSON performs an HTTP GET and decodes the JSON response into target.

func (*BaseProvider) GetCoverImageURL added in v1.12.0

func (b *BaseProvider) GetCoverImageURL(metadata *MediaMetadata) string

func (*BaseProvider) HTTPClient added in v1.12.0

func (b *BaseProvider) HTTPClient() *http.Client

HTTPClient returns the provider's HTTP client, falling back to a default client.

func (*BaseProvider) Name added in v1.12.0

func (b *BaseProvider) Name() string

func (*BaseProvider) RequiresAuth added in v1.12.0

func (b *BaseProvider) RequiresAuth() bool

func (*BaseProvider) SetAuthToken added in v1.12.0

func (b *BaseProvider) SetAuthToken(token string)

func (*BaseProvider) SetConfig added in v1.12.0

func (b *BaseProvider) SetConfig(config ConfigProvider)

type ComicInfo added in v1.12.0

type ComicInfo struct {
	XMLName             xml.Name `xml:"ComicInfo"`
	Title               string   `xml:"Title,omitempty"`
	Series              string   `xml:"Series,omitempty"`
	Number              string   `xml:"Number,omitempty"`
	Count               int      `xml:"Count,omitempty"`
	Volume              int      `xml:"Volume,omitempty"`
	AlternateSeries     string   `xml:"AlternateSeries,omitempty"`
	AlternateNumber     string   `xml:"AlternateNumber,omitempty"`
	AlternateCount      int      `xml:"AlternateCount,omitempty"`
	Summary             string   `xml:"Summary,omitempty"`
	Notes               string   `xml:"Notes,omitempty"`
	Year                int      `xml:"Year,omitempty"`
	Month               int      `xml:"Month,omitempty"`
	Day                 int      `xml:"Day,omitempty"`
	Writer              string   `xml:"Writer,omitempty"`
	Penciller           string   `xml:"Penciller,omitempty"`
	Inker               string   `xml:"Inker,omitempty"`
	Colorist            string   `xml:"Colorist,omitempty"`
	Letterer            string   `xml:"Letterer,omitempty"`
	CoverArtist         string   `xml:"CoverArtist,omitempty"`
	Editor              string   `xml:"Editor,omitempty"`
	Translator          string   `xml:"Translator,omitempty"`
	Publisher           string   `xml:"Publisher,omitempty"`
	Imprint             string   `xml:"Imprint,omitempty"`
	Genre               string   `xml:"Genre,omitempty"`
	Tags                string   `xml:"Tags,omitempty"`
	Web                 string   `xml:"Web,omitempty"`
	PageCount           int      `xml:"PageCount,omitempty"`
	LanguageISO         string   `xml:"LanguageISO,omitempty"`
	Format              string   `xml:"Format,omitempty"`
	BlackAndWhite       string   `xml:"BlackAndWhite,omitempty"`
	Manga               string   `xml:"Manga,omitempty"`
	Characters          string   `xml:"Characters,omitempty"`
	Teams               string   `xml:"Teams,omitempty"`
	Locations           string   `xml:"Locations,omitempty"`
	ScanInformation     string   `xml:"ScanInformation,omitempty"`
	StoryArc            string   `xml:"StoryArc,omitempty"`
	StoryArcNumber      string   `xml:"StoryArcNumber,omitempty"`
	SeriesGroup         string   `xml:"SeriesGroup,omitempty"`
	AgeRating           string   `xml:"AgeRating,omitempty"`
	Pages               *Pages   `xml:"Pages,omitempty"`
	CommunityRating     float64  `xml:"CommunityRating,omitempty"`
	MainCharacterOrTeam string   `xml:"MainCharacterOrTeam,omitempty"`
	Review              string   `xml:"Review,omitempty"`
	GTIN                string   `xml:"GTIN,omitempty"`
}

ComicInfo represents the ComicInfo.xml structure according to ComicInfo 2.1 schema

func GenerateComicInfo added in v1.12.0

func GenerateComicInfo(meta *AggregatedMediaMetadata, chapterNumber string, chapterTitle string, pageCount int) *ComicInfo

GenerateComicInfo creates a ComicInfo struct from AggregatedMediaMetadata

func GenerateComicInfoFromMedia added in v1.12.0

func GenerateComicInfoFromMedia(media *models.Media, chapterNumber string, chapterTitle string, pageCount int) *ComicInfo

GenerateComicInfoFromMedia creates a ComicInfo struct from a Media model

func (*ComicInfo) ToXML added in v1.12.0

func (c *ComicInfo) ToXML() ([]byte, error)

ToXML marshals the ComicInfo to XML bytes

type ConfigProvider

type ConfigProvider interface {
	GetMetadataProvider() string
	GetContentRatingLimit() int
}

ConfigProvider is an interface for accessing app configuration This allows the metadata package to get provider config without importing models

type JikanProvider

type JikanProvider struct {
	BaseProvider
}

JikanProvider implements the Provider interface for Jikan API (unofficial MAL API)

func (*JikanProvider) FindBestMatch

func (j *JikanProvider) FindBestMatch(title string) (*MediaMetadata, error)

func (*JikanProvider) GetMetadata

func (j *JikanProvider) GetMetadata(id string) (*MediaMetadata, error)

func (*JikanProvider) Search

func (j *JikanProvider) Search(title string) ([]SearchResult, error)

type KitsuProvider added in v1.6.6

type KitsuProvider struct {
	BaseProvider
}

KitsuProvider implements the Provider interface for Kitsu API

func (*KitsuProvider) FindBestMatch added in v1.6.6

func (k *KitsuProvider) FindBestMatch(title string) (*MediaMetadata, error)

func (*KitsuProvider) GetMetadata added in v1.6.6

func (k *KitsuProvider) GetMetadata(id string) (*MediaMetadata, error)

func (*KitsuProvider) Search added in v1.6.6

func (k *KitsuProvider) Search(title string) ([]SearchResult, error)

type LibraryConfigProvider added in v1.6.6

type LibraryConfigProvider interface {
	ConfigProvider
	GetLibraryMetadataProvider() string
}

LibraryConfigProvider extends ConfigProvider with library-specific settings

type MangaDexProvider added in v1.7.0

type MangaDexProvider struct {
	BaseProvider
}

MangaDexProvider implements the Provider interface for MangaDex API

func (*MangaDexProvider) FindBestMatch added in v1.7.0

func (m *MangaDexProvider) FindBestMatch(title string) (*MediaMetadata, error)

func (*MangaDexProvider) GetMetadata added in v1.7.0

func (m *MangaDexProvider) GetMetadata(id string) (*MediaMetadata, error)

func (*MangaDexProvider) Search added in v1.7.0

func (m *MangaDexProvider) Search(title string) ([]SearchResult, error)

type MangaUpdatesProvider added in v1.6.6

type MangaUpdatesProvider struct {
	BaseProvider
}

MangaUpdatesProvider implements the Provider interface for MangaUpdates API

func (*MangaUpdatesProvider) FindBestMatch added in v1.6.6

func (m *MangaUpdatesProvider) FindBestMatch(title string) (*MediaMetadata, error)

func (*MangaUpdatesProvider) GetMetadata added in v1.6.6

func (m *MangaUpdatesProvider) GetMetadata(id string) (*MediaMetadata, error)

func (*MangaUpdatesProvider) Search added in v1.6.6

func (m *MangaUpdatesProvider) Search(title string) ([]SearchResult, error)

type MediaMetadata added in v1.6.1

type MediaMetadata struct {
	Title             string
	Description       string
	Year              int
	OriginalLanguage  string
	Status            string // ongoing, completed, hiatus, cancelled
	ContentRating     string // safe, suggestive, erotica, explicit
	CoverArtURL       string
	Tags              []string
	Type              string // media, manhwa, manhua, webtoon, etc.
	AlternativeTitles []string
	Author            string
	ExternalID        string // Provider-specific ID

	// Additional rich metadata fields
	Authors       []AuthorInfo // Multiple authors/creators
	Artists       []AuthorInfo // Separate from authors for some media
	StartDate     string       // Full start date (YYYY-MM-DD)
	EndDate       string       // Full end date (YYYY-MM-DD)
	ChapterCount  int          // Total chapters
	VolumeCount   int          // Total volumes
	AverageScore  float64      // Average rating/score
	Popularity    int          // Popularity rank
	Favorites     int          // Number of favorites
	Demographic   string       // Target demographic (shonen, seinen, josei, etc.)
	Publisher     string       // Publishing company
	Magazine      string       // Serialization magazine
	Serialization string       // Serialization info
	Genres        []string     // Separate from tags for structured genres
	Characters    []string     // Main characters
	Relations     []Relation   // Related works (prequels, sequels, etc.)
}

MediaMetadata represents the standardized metadata structure returned by all providers

func DefaultFindBestMatch added in v1.12.0

func DefaultFindBestMatch(s Searcher, title string) (*MediaMetadata, error)

type MediaUpdater added in v1.6.1

type MediaUpdater interface {
	SetName(string)
	SetDescription(string)
	SetYear(int)
	SetOriginalLanguage(string)
	SetStatus(string)
	SetContentRating(string)
	SetType(string)
	SetCoverArtURL(string)
	// Enhanced metadata setters
	SetAuthors([]models.AuthorInfo)
	SetArtists([]models.AuthorInfo)
	SetStartDate(string)
	SetEndDate(string)
	SetChapterCount(int)
	SetVolumeCount(int)
	SetAverageScore(float64)
	SetPopularity(int)
	SetFavorites(int)
	SetDemographic(string)
	SetPublisher(string)
	SetMagazine(string)
	SetSerialization(string)
	SetGenres([]string)
	SetCharacters([]string)
	SetAlternativeTitles([]string)
	SetAttributionLinks([]models.AttributionLink)
}

ApplyMetadataToMedia is a helper interface for updating media models This allows the metadata package to provide update functionality without importing models

type Page added in v1.12.0

type Page struct {
	Image       int    `xml:"Image,attr"`
	Type        string `xml:"Type,attr,omitempty"`
	DoublePage  bool   `xml:"DoublePage,attr,omitempty"`
	ImageSize   int64  `xml:"ImageSize,attr,omitempty"`
	Key         string `xml:"Key,attr,omitempty"`
	Bookmark    string `xml:"Bookmark,attr,omitempty"`
	ImageWidth  int    `xml:"ImageWidth,attr,omitempty"`
	ImageHeight int    `xml:"ImageHeight,attr,omitempty"`
}

Page represents a single page in the comic

type Pages added in v1.12.0

type Pages struct {
	Page []Page `xml:"Page"`
}

Pages represents the Pages element containing Page elements

type Provider

type Provider interface {
	// Name returns the provider name (e.g., "mangadex", "anilist", "jikan")
	Name() string

	// Search searches for media by title and returns a list of results
	Search(title string) ([]SearchResult, error)

	// GetMetadata fetches detailed metadata for a specific media by provider ID
	GetMetadata(id string) (*MediaMetadata, error)

	// FindBestMatch searches for media and returns the best matching result
	FindBestMatch(title string) (*MediaMetadata, error)

	// RequiresAuth returns true if this provider requires an API token
	RequiresAuth() bool

	// SetAuthToken sets the authentication token for the provider
	SetAuthToken(token string)

	// SetConfig sets the configuration for the provider
	SetConfig(config ConfigProvider)

	// GetCoverImageURL returns the actual downloadable URL for cover art
	// This allows each provider to handle URL construction differently
	GetCoverImageURL(metadata *MediaMetadata) string
}

Provider is the interface that all metadata providers must implement

func GetProvider

func GetProvider(name string, apiToken string) (Provider, error)

GetProvider returns a provider instance by name with the given API token

func GetProviderForLibrary added in v1.6.6

func GetProviderForLibrary(libraryProvider sql.NullString, config ConfigProvider) (Provider, error)

GetProviderForLibrary returns the metadata provider for a specific library, falling back to global config

func GetProviderFromConfig

func GetProviderFromConfig(config ConfigProvider) (Provider, error)

GetProviderFromConfig returns the configured metadata provider instance

func NewAniListProvider

func NewAniListProvider(apiToken string) Provider

NewAniListProvider creates a new AniList metadata provider

func NewJikanProvider

func NewJikanProvider(apiToken string) Provider

NewJikanProvider creates a new Jikan API metadata provider

func NewKitsuProvider added in v1.6.6

func NewKitsuProvider(apiToken string) Provider

NewKitsuProvider creates a new Kitsu metadata provider

func NewMangaDexProvider added in v1.7.0

func NewMangaDexProvider(apiToken string) Provider

NewMangaDexProvider creates a new MangaDex metadata provider

func NewMangaUpdatesProvider added in v1.6.6

func NewMangaUpdatesProvider(apiToken string) Provider

NewMangaUpdatesProvider creates a new MangaUpdates metadata provider

type Relation added in v1.11.0

type Relation struct {
	Type  string // prequel, sequel, adaptation, etc.
	Title string
	ID    string // External ID
}

Relation represents a related work

type SearchResult

type SearchResult struct {
	ID              string
	Title           string
	Description     string
	CoverArtURL     string
	Year            int
	SimilarityScore float64
	Tags            []string
}

SearchResult represents a single media search result

type Searcher added in v1.12.0

type Searcher interface {
	Search(title string) ([]SearchResult, error)
	GetMetadata(id string) (*MediaMetadata, error)
}

DefaultFindBestMatch is the standard FindBestMatch implementation that selects the search result with the highest similarity score. Providers with custom scoring logic can implement their own FindBestMatch instead.

Jump to

Keyboard shortcuts

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