metadata

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package metadata 是刮削用的元数据:与来源无关的电影、剧集、季、集与图片,各个来源(TMDB、豆瓣、Bangumi、 Fanart.tv、OMDb、TheTVDB)的适配,以及按媒体库的设置把几个来源的数据合在一起(每一项记下来自哪个来源)。 识别与整理仍以 TMDB 的条目为准:这里只决定 NFO 与图片里写什么。

Index

Constants

View Source
const (
	LangAuto = ""     // 跟识别语言:用来源自己挑的那张(TMDB 按识别语言给的)
	LangNone = "none" // 没有文字的
)

海报与 Logo 优先的语言(媒体库的「图片语言」)。

View Source
const (
	SourceTMDB    = "tmdb"
	SourceDouban  = "douban"
	SourceBangumi = "bangumi"
	SourceFanart  = "fanart"
	SourceOMDb    = "omdb"
	SourceTVDB    = "tvdb"
)

来源。

View Source
const (
	KindMovie = "movie"
	KindTV    = "tv"
)

条目的种类(和 tmdb.KindMovie、tmdb.KindTV 一样)。

View Source
const (
	IDTMDB    = "tmdb"
	IDIMDb    = "imdb"
	IDTVDB    = "tvdb"
	IDDouban  = "douban"
	IDBangumi = "bangumi"
)

编号的种类:NFO 里 <uniqueid type="…"> 的 type。

View Source
const (
	RatingTMDB           = "themoviedb"
	RatingIMDb           = "imdb"
	RatingDouban         = "douban"
	RatingBangumi        = "bangumi"
	RatingRottenTomatoes = "tomatometerallcritics"
	RatingMetacritic     = "metacritic"
)

评分的名称:NFO 里 <rating name="…"> 的 name(Kodi 的写法)。Jellyfin 把名字里带 tomato 的当成影评人评分, 其余的都当成大众评分、按顺序覆盖,最后一个生效(见 Item.Ratings)。

View Source
const (
	StatusContinuing = "Continuing"
	StatusEnded      = "Ended"
)

剧集的状态(Kodi 与 Jellyfin 认的写法)。

View Source
const (
	ArtPoster    = "poster"
	ArtFanart    = "fanart"
	ArtClearart  = "clearart"
	ArtBanner    = "banner"
	ArtLandscape = "landscape"
	ArtDisc      = "discart"
	// ArtSeasonPoster 是季海报(Season 是季号)
	ArtSeasonPoster = "season_poster"
	// ArtThumb 是一集的截图(Season、Episode 是季号与集号)
	ArtThumb = "thumb"
)

图片的种类。

View Source
const LegacyDouban = "douban"

LegacyDouban 是旧版本的「简介与评分」选了豆瓣(MediaLibrary.ScrapeSource 为 douban):等于简介与评分都用豆瓣。

Variables

View Source
var (
	PlotSources    = []string{"", SourceDouban, SourceBangumi}
	RatingSources  = []string{"", SourceDouban, SourceBangumi, SourceOMDb}
	EpisodeSources = []string{"", SourceBangumi, SourceTVDB}
	ArtworkSources = []string{"", SourceFanart}
)

每一项可选的来源(空串是 TMDB)。

Functions

func FanartOnly

func FanartOnly(kind string) bool

FanartOnly 报告这种图片只有 Fanart.tv 有(TMDB 没有)。

func SourceLead

func SourceLead(id string) string

SourceLead 是写在中文前面的来源名:英文名后面空一格(豆瓣不空)。

func SourceName

func SourceName(id string) string

SourceName 是来源给人看的名字。

Types

type ArtRequest

type ArtRequest struct {
	Kinds     []string
	Seasons   []int
	ImageLang string
	RecogLang string
	// Thumbs 是要写截图的集:TMDB 没有其中一集的截图时去问 TheTVDB(见 Resolver.Resolve)
	Thumbs []EpisodeRef
}

ArtRequest 是要的图片:种类、哪几季的季海报与截图、海报与 Logo 优先的语言(见 LangAuto)、识别语言(例如 zh-CN)。

type ArtSource

type ArtSource interface {
	Provider
	Art(ctx context.Context, q Query, req ArtRequest) ([]Artwork, error)
	Download(ctx context.Context, a Artwork) ([]byte, error)
}

ArtSource 提供图片。取到了一部分时可以同时返回图片与错误(例如 TMDB 的图片列表取不到,详情里的海报还在)。

type Artwork

type Artwork struct {
	Source  string
	Kind    string
	Season  int
	Episode int
	Lang    string
	// Likes 是评分或点赞数,同一来源同一种图片里按它从高到低排
	Likes float64
	// Default 表示这是来源自己按识别语言挑的那张(TMDB 详情里的 poster_path、backdrop_path,季详情里的海报,集的截图)
	Default bool
	// Ref 是来源下载这张图用的引用(TMDB 是 /xxx.jpg 这样的路径,Fanart.tv 是图片地址)
	Ref string
}

Artwork 是一个来源的一张图片。Lang 是图上文字的语言(ISO 639-1),空串是没有文字。

type Bangumi

type Bangumi struct {
	// contains filtered or unexported fields
}

Bangumi 是 Bangumi 来源:动画的中文简介、评分与每一集的中文标题。Bangumi 上一季是一个条目,整部剧集用第 1 季的。 只用于动画(Query.Anime)。日文的简介不用(含假名的当作日文),用 TMDB 的。

func NewBangumi

func NewBangumi(c BangumiAPI) *Bangumi

NewBangumi 建 Bangumi 来源;c 为 nil 时返回 nil。

func (*Bangumi) ID

func (b *Bangumi) ID() string

ID 是来源编号。

func (*Bangumi) Item

func (b *Bangumi) Item(ctx context.Context, q Query) (*Item, error)

Item 取电影或剧集第 1 季的简介与评分(按首播日期找)。

func (*Bangumi) Season

func (b *Bangumi) Season(ctx context.Context, q Query, ref SeasonRef) (*Season, error)

Season 取一季:简介与每一集的中文标题(没有中文标题的集不填,用 TMDB 的)。按这一季在 TMDB 上的首播日期找。

type BangumiAPI

type BangumiAPI interface {
	Find(ctx context.Context, q bangumi.Query) (*bangumi.Subject, error)
	Episodes(ctx context.Context, id int) ([]bangumi.Episode, error)
}

BangumiAPI 是 Bangumi 适配要用的接口(生产环境是 *bangumi.Client)。

type Collection

type Collection struct {
	TMDBID int
	Name   string
}

Collection 是电影所属的系列(TMDB 的 collection)。

type Douban

type Douban struct {
	// contains filtered or unexported fields
}

Douban 是豆瓣来源:电影、剧集每一季的简介与评分。豆瓣上剧集一季是一个条目,整部剧集用第 1 季的。

func NewDouban

func NewDouban(c DoubanAPI) *Douban

NewDouban 建豆瓣来源;c 为 nil 时返回 nil。

func (*Douban) ID

func (d *Douban) ID() string

ID 是来源编号。

func (*Douban) Item

func (d *Douban) Item(ctx context.Context, q Query) (*Item, error)

Item 取电影或剧集第 1 季的简介与评分。

func (*Douban) Season

func (d *Douban) Season(ctx context.Context, q Query, ref SeasonRef) (*Season, error)

Season 取一季的简介:第 1 季的年份用整部的,后面几季用这一季首播的年份(不知道时不看年份)。

type DoubanAPI

type DoubanAPI interface {
	Find(ctx context.Context, q douban.Query) (*douban.Subject, error)
	Subject(ctx context.Context, kind, id string) (*douban.Subject, error)
}

DoubanAPI 是豆瓣适配要用的接口(生产环境是 *douban.Client)。

type Episode

type Episode struct {
	Season    int
	Number    int
	IDs       map[string]string
	Title     string
	Plot      string
	Aired     string
	Runtime   int
	Ratings   []Rating
	Directors []string
	Writers   []string
	// From 是每一项(title、plot)来自哪个来源;没有记的是 TMDB 的
	From map[string]string
}

Episode 是剧集的一集。

type EpisodeRef

type EpisodeRef struct{ Season, Episode int }

EpisodeRef 是一集:季号与集号。

type Fanart

type Fanart struct {
	// contains filtered or unexported fields
}

Fanart 是 Fanart.tv 来源:海报、背景、高清 Logo、clearart、横幅、横版海报、碟片与季海报。 电影按 TMDB 编号找,剧集按 TVDB 编号找(TMDB 的详情里有时才有)。

func NewFanart

func NewFanart(c FanartAPI) *Fanart

NewFanart 建 Fanart.tv 来源;c 为 nil 时返回 nil(没填 API Key)。

func (*Fanart) Art

func (f *Fanart) Art(ctx context.Context, q Query, req ArtRequest) ([]Artwork, error)

Art 取图片:只返回要的种类,季海报只返回要的那几季的。

func (*Fanart) Download

func (f *Fanart) Download(ctx context.Context, a Artwork) ([]byte, error)

Download 下载一张 Fanart.tv 图片。

func (*Fanart) ID

func (f *Fanart) ID() string

ID 是来源编号。

type FanartAPI

type FanartAPI interface {
	Movie(ctx context.Context, id string) (fanart.Images, error)
	TV(ctx context.Context, tvdbID int) (fanart.Images, error)
	Download(ctx context.Context, url string) ([]byte, error)
}

FanartAPI 是 Fanart.tv 适配要用的接口(生产环境是 *fanart.Client)。

type Item

type Item struct {
	Kind          string
	IDs           map[string]string
	Title         string
	OriginalTitle string
	Year          int
	// Premiered 是上映或首播日期(yyyy-mm-dd)
	Premiered string
	Plot      string
	Tagline   string
	// Runtime 是片长(分钟):电影是整部,剧集是一集
	Runtime   int
	Genres    []string
	Countries []string
	// Studios 是出品公司(剧集是播出的电视网)
	Studios []string
	// Certification 是分级(例如 PG-13、TV-MA)
	Certification string
	// Status 是剧集的状态(StatusContinuing、StatusEnded),电影为空
	Status string
	// Ratings 里主要的评分排在最后:Jellyfin 与 Emby 按顺序读,最后一个生效
	Ratings    []Rating
	Directors  []string
	Writers    []string
	Cast       []Person
	Collection *Collection
}

Item 是一部电影或一部剧集。

func FromTMDB

func FromTMDB(r tmdb.Result) *Item

FromTMDB 是识别出的 TMDB 条目对应的基本信息(取不到完整信息时 NFO 写它)。

func (*Item) ID

func (it *Item) ID(kind string) string

ID 返回条目的一种编号;没有时为空串。

type ItemSource

type ItemSource interface {
	Provider
	Item(ctx context.Context, q Query) (*Item, error)
}

ItemSource 提供电影或整部剧集的信息(豆瓣与 Bangumi 用第 1 季的条目)。没找到时返回 nil、nil。

type Need

type Need struct {
	// Item 表示要写电影或剧集的 NFO
	Item bool
	// Seasons 是要写 season.nfo 的季
	Seasons []int
	// Episodes 是要写每一集 NFO 的季(要每一集的标题与简介)
	Episodes []int
	// Art 是要的图片;Kinds 为空时不要
	Art ArtRequest
}

Need 是这次刮削要写的内容(由要写的文件推出来)。没有要写的 NFO 时不去问只提供文字的来源,没有要写的图片时不取图片。

type Note

type Note string

Note 是不算出错的说明(例如 Fanart.tv 要 TVDB 编号、TMDB 上这部没有):来源返回它时写进 Result.Notes,不写进 Errors。

func (Note) Error

func (n Note) Error() string

type OMDb

type OMDb struct {
	// contains filtered or unexported fields
}

OMDb 是 OMDb 来源:按 IMDb 编号取 IMDb 评分、烂番茄、Metacritic 与分级。

func NewOMDb

func NewOMDb(c OMDbAPI) *OMDb

NewOMDb 建 OMDb 来源;c 为 nil 时返回 nil(没填 API Key)。

func (*OMDb) ID

func (o *OMDb) ID() string

ID 是来源编号。

func (*OMDb) Item

func (o *OMDb) Item(ctx context.Context, q Query) (*Item, error)

Item 取评分与分级。

type OMDbAPI

type OMDbAPI interface {
	ByIMDb(ctx context.Context, imdbID string) (*omdb.Title, error)
}

OMDbAPI 是 OMDb 适配要用的接口(生产环境是 *omdb.Client)。

type Person

type Person struct {
	// ID 是 TMDB 上这个人的编号(TMDB 以外的来源为 0)
	ID    int
	Name  string
	Role  string
	Order int
	Thumb string
}

Person 是一位演员:名字、饰演的角色、排第几、头像地址(完整的 URL,没有时为空)。

type Provider

type Provider interface {
	ID() string
}

Provider 是一个来源。下面几个接口按能力实现,一个来源可以实现其中几个。

type Query

type Query struct {
	Kind string
	// IDs 是已知的编号:tmdb、imdb,剧集取到 TMDB 详情以后还有 tvdb;站点给了豆瓣编号时有 douban
	IDs           map[string]string
	Title         string
	OriginalTitle string
	Year          int
	Premiered     string
	// Anime 表示 TMDB 类型里有「动画」:只有动画才去 Bangumi 找
	Anime bool
}

Query 是要找的条目:识别出的 TMDB 条目(编号、中文名、原名、年份、上映或首播日期、是不是动画), 以及站点给的豆瓣编号(pt-tools 推送的电影才有)。别的来源按它找同一部。

func QueryFor

func QueryFor(r tmdb.Result, doubanID string) Query

QueryFor 是用识别出的 TMDB 条目去别的来源找时的条件(doubanID 是站点给的豆瓣编号,没有时为空)。

type Rating

type Rating struct {
	Name  string
	Value float64
	// Max 是满分:10,烂番茄与 Metacritic 是 100
	Max   int
	Votes int
}

Rating 是一个来源的评分。

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver 按媒体库的数据来源,从几个来源取数据并合在一起。TMDB 是基础:识别出的条目、季与集都以它为准, 别的来源只替换设置里选了它的那几项,找不到时用 TMDB 的。

func NewResolver

func NewResolver(ps ...Provider) *Resolver

NewResolver 用这些来源建一个 Resolver(nil 的跳过)。没有的来源当作不可用:设置里选了它时用 TMDB 的,并写明原因。

func (*Resolver) Has

func (r *Resolver) Has(id string) bool

Has 报告有没有这个来源。

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, q Query, base *Item, src Sources, need Need) *Result

Resolve 取数据并合在一起:base 是识别出的 TMDB 条目(取不到 TMDB 的完整信息时用它)。不会返回错误: 来源出错时写进 Errors、用 TMDB 的。

type Result

type Result struct {
	Item    *Item
	Seasons map[int]*Season
	// Used 是文字的每一项(plot、rating、episode)实际用了哪个来源
	Used   map[string]string
	Notes  []string
	Errors []string
	// contains filtered or unexported fields
}

Result 是合在一起的数据。Notes 是用了 TMDB 代替的说明(没找到、没填 Key 一类),Errors 是来源出错。

func (*Result) Download

func (res *Result) Download(ctx context.Context, a Artwork) ([]byte, error)

Download 下载 Pick 挑出的一张图。

func (*Result) Pick

func (res *Result) Pick(kind string, season, episode int) *Artwork

Pick 按图片的设置挑一张:kind 是种类,season 与 episode 是季海报与截图的季号、集号。按来源的先后, 第一个有这种图的来源里按语言挑(见 choose)。没有时返回 nil。

func (*Result) Picks

func (res *Result) Picks(kind string, season, episode int) []Artwork

Picks 是每个有这种图的来源里挑出的一张,按来源的先后排:前一张下载不了时用后一张。

func (*Result) Season

func (res *Result) Season(n int) *Season

Season 返回第 n 季;没有取到时返回只有季号的一季。

func (*Result) Summary

func (res *Result) Summary(eps []EpisodeRef) string

Summary 是这次写的文字每一项实际用了哪些来源,例如「简介 豆瓣,评分 豆瓣,每一集 Bangumi、TMDB」:简介看电影或剧集 (要写它的 NFO 时)与要写的每一季,评分看电影或剧集,每一集看 eps 这几集的标题与简介(混着用时都列出来)。

type Season

type Season struct {
	Number    int
	Title     string
	Plot      string
	Premiered string
	IDs       map[string]string
	Episodes  []Episode
	// From 是每一项(plot)来自哪个来源;没有记的是 TMDB 的
	From map[string]string
}

Season 是剧集的一季。

func (*Season) Episode

func (s *Season) Episode(n int) *Episode

Episode 返回第 n 集;没有时返回 nil。

type SeasonRef

type SeasonRef struct {
	Number    int
	Premiered string
	// Episodes 表示要这一季每一集的标题与简介(只要简介时不去取每一集)
	Episodes bool
}

SeasonRef 是要找的一季:季号,以及 TMDB 上这一季的首播日期(豆瓣、Bangumi 一季是一个条目,按它找同一季)。

type SeasonSource

type SeasonSource interface {
	Provider
	// Season 取一季。找到了这一季、每一集取不到时可以同时返回这一季与错误(简介照样用)。
	Season(ctx context.Context, q Query, s SeasonRef) (*Season, error)
}

SeasonSource 提供剧集一季(含每一集)的信息。没找到时返回 nil、nil。

type Sources

type Sources struct {
	Plot    string `json:"plot"`
	Rating  string `json:"rating"`
	Episode string `json:"episode"`
	Artwork string `json:"artwork"`
}

Sources 是媒体库的数据来源:每一项选一个优先的来源,那个来源找不到或没有这一项时用 TMDB 的。空串是 TMDB。

  • Plot:电影、剧集与每一季的简介(豆瓣与 Bangumi 一季是一个条目,剧集的简介用第 1 季的);
  • Rating:主要的评分(NFO 里写在最后,Jellyfin 与 Emby 显示它);取到的其它来源的评分也写进 NFO;
  • Episode:每一集的标题与简介(只有剧集有):TMDB、Bangumi 或 TheTVDB;
  • Artwork:海报、背景、Logo 与季海报先用哪个来源的;Fanart.tv 才有的几种图(clearart、横幅、横版海报、碟片) 总是用 Fanart.tv 的。

Bangumi 只用于动画(TMDB 类型里有「动画」的条目),别的条目用 TMDB 的。

func ParseSources

func ParseSources(raw, legacy string) Sources

ParseSources 读媒体库存的数据来源(JSON)。为空时按旧版本的「简介与评分」(legacy):douban 是简介与评分都用豆瓣。 读不出来或有不认识的来源时当作全用 TMDB(不会因为设置坏了写错,界面上重新保存即可)。

func (Sources) Clean

func (s Sources) Clean() Sources

Clean 去掉每一项两边的空白,tmdb 写成空串。

func (Sources) ForKind

func (s Sources) ForKind(kind string) Sources

ForKind 去掉这种媒体库用不上的项:电影没有「每一集」。

func (Sources) Normalize

func (s Sources) Normalize() (string, error)

Normalize 检查每一项都是可选的来源(先 Clean),返回存进数据库的 JSON(全是 TMDB 时为空串)。

type TMDB

type TMDB struct {
	// contains filtered or unexported fields
}

TMDB 是 TMDB 来源:电影与剧集的完整信息、每一季与每一集、海报、背景、Logo、季海报与集截图。 一次刮削里同一个条目的详情与同一季只取一次(几处同时要时等第一次的结果)。

func NewTMDB

func NewTMDB(c TMDBAPI) *TMDB

NewTMDB 建 TMDB 来源;c 为 nil 时返回 nil(TMDB 不能用)。

func (*TMDB) Art

func (t *TMDB) Art(ctx context.Context, q Query, req ArtRequest) ([]Artwork, error)

Art 取图片:详情里 TMDB 按识别语言挑的海报与背景(Default);要 Logo 或选了图片语言时再取图片列表(缓存一周), 取不到时只有详情里的那两张,同时返回错误;剧集再取要的那几季的季海报与集截图。

func (*TMDB) Download

func (t *TMDB) Download(ctx context.Context, a Artwork) ([]byte, error)

Download 下载一张 TMDB 图片。

func (*TMDB) ID

func (t *TMDB) ID() string

ID 是来源编号。

func (*TMDB) Item

func (t *TMDB) Item(ctx context.Context, q Query) (*Item, error)

Item 取完整信息:详情(多半读缓存)加上演职员、分级、出品公司等(见 tmdb.Extras)。

func (*TMDB) Season

func (t *TMDB) Season(ctx context.Context, q Query, ref SeasonRef) (*Season, error)

Season 取一季(含每一集的标题、简介、播出日期、导演、编剧与评分)。

type TMDBAPI

type TMDBAPI interface {
	Details(ctx context.Context, kind string, id int) (*tmdb.Result, error)
	Extras(ctx context.Context, kind string, id int) (*tmdb.Extras, error)
	Season(ctx context.Context, tvID, number int) (*tmdb.Season, error)
	Images(ctx context.Context, kind string, id int) (*tmdb.Images, error)
	Image(ctx context.Context, path, size string) ([]byte, error)
	ProfileURL(path string) string
}

TMDBAPI 是 TMDB 适配要用的接口(生产环境是 *tmdb.Client)。

type TVDB

type TVDB struct {
	// contains filtered or unexported fields
}

TVDB 是 TheTVDB 来源:剧集每一集的标题、简介(识别语言的)与截图。按 TMDB 上的 TVDB 编号找,按播出顺序(Aired Order), 不按名字找。只用识别语言的文字(这一集在 TheTVDB 上有这种语言的翻译,或者剧集的原语言就是它),占位的标题(「第 1 集」、 纯数字、Episode 1 一类)不用;第 0 季(特别篇)不用。一次刮削里同一部剧只取一次。

func NewTVDB

func NewTVDB(c TVDBAPI, recogLang string) *TVDB

NewTVDB 建 TheTVDB 来源:recogLang 是识别语言(例如 zh-CN),按它选 TheTVDB 的语言。c 为 nil 时返回 nil(没填 Key)。

func (*TVDB) Art

func (t *TVDB) Art(ctx context.Context, q Query, req ArtRequest) ([]Artwork, error)

Art 取要的那几季的集截图(只有集截图)。

func (*TVDB) Download

func (t *TVDB) Download(ctx context.Context, a Artwork) ([]byte, error)

Download 下载一张 TheTVDB 图片。

func (*TVDB) ID

func (t *TVDB) ID() string

ID 是来源编号。

func (*TVDB) Season

func (t *TVDB) Season(ctx context.Context, q Query, ref SeasonRef) (*Season, error)

Season 取一季每一集的标题、简介(能用的才填)、播出日期与 TheTVDB 上的编号。没有这部或这一季时返回 nil、nil。

type TVDBAPI

type TVDBAPI interface {
	Episodes(ctx context.Context, seriesID int, lang string) (*tvdb.SeriesEpisodes, error)
	Download(ctx context.Context, url string) ([]byte, error)
}

TVDBAPI 是 TheTVDB 适配要用的接口(生产环境是 *tvdb.Client)。

Jump to

Keyboard shortcuts

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