Documentation
¶
Overview ¶
Package metadata 是刮削用的元数据:与来源无关的电影、剧集、季、集与图片,各个来源(TMDB、豆瓣、Bangumi、 Fanart.tv、OMDb、TheTVDB)的适配,以及按媒体库的设置把几个来源的数据合在一起(每一项记下来自哪个来源)。 识别与整理仍以 TMDB 的条目为准:这里只决定 NFO 与图片里写什么。
Index ¶
- Constants
- Variables
- func FanartOnly(kind string) bool
- func SourceLead(id string) string
- func SourceName(id string) string
- type ArtRequest
- type ArtSource
- type Artwork
- type Bangumi
- type BangumiAPI
- type Collection
- type Douban
- type DoubanAPI
- type Episode
- type EpisodeRef
- type Fanart
- type FanartAPI
- type Item
- type ItemSource
- type Need
- type Note
- type OMDb
- type OMDbAPI
- type Person
- type Provider
- type Query
- type Rating
- type Resolver
- type Result
- func (res *Result) Download(ctx context.Context, a Artwork) ([]byte, error)
- func (res *Result) Pick(kind string, season, episode int) *Artwork
- func (res *Result) Picks(kind string, season, episode int) []Artwork
- func (res *Result) Season(n int) *Season
- func (res *Result) Summary(eps []EpisodeRef) string
- type Season
- type SeasonRef
- type SeasonSource
- type Sources
- type TMDB
- func (t *TMDB) Art(ctx context.Context, q Query, req ArtRequest) ([]Artwork, error)
- func (t *TMDB) Download(ctx context.Context, a Artwork) ([]byte, error)
- func (t *TMDB) ID() string
- func (t *TMDB) Item(ctx context.Context, q Query) (*Item, error)
- func (t *TMDB) Season(ctx context.Context, q Query, ref SeasonRef) (*Season, error)
- type TMDBAPI
- type TVDB
- type TVDBAPI
Constants ¶
const ( LangAuto = "" // 跟识别语言:用来源自己挑的那张(TMDB 按识别语言给的) LangNone = "none" // 没有文字的 )
海报与 Logo 优先的语言(媒体库的「图片语言」)。
const ( SourceTMDB = "tmdb" SourceDouban = "douban" SourceBangumi = "bangumi" SourceFanart = "fanart" SourceOMDb = "omdb" SourceTVDB = "tvdb" )
来源。
const ( KindMovie = "movie" KindTV = "tv" )
条目的种类(和 tmdb.KindMovie、tmdb.KindTV 一样)。
const ( IDTMDB = "tmdb" IDIMDb = "imdb" IDTVDB = "tvdb" IDDouban = "douban" IDBangumi = "bangumi" )
编号的种类:NFO 里 <uniqueid type="…"> 的 type。
const ( RatingTMDB = "themoviedb" RatingIMDb = "imdb" RatingDouban = "douban" RatingBangumi = "bangumi" RatingRottenTomatoes = "tomatometerallcritics" RatingMetacritic = "metacritic" )
评分的名称:NFO 里 <rating name="…"> 的 name(Kodi 的写法)。Jellyfin 把名字里带 tomato 的当成影评人评分, 其余的都当成大众评分、按顺序覆盖,最后一个生效(见 Item.Ratings)。
const ( StatusContinuing = "Continuing" StatusEnded = "Ended" )
剧集的状态(Kodi 与 Jellyfin 认的写法)。
const ( ArtPoster = "poster" ArtFanart = "fanart" ArtLogo = "logo" ArtClearart = "clearart" ArtBanner = "banner" ArtLandscape = "landscape" ArtDisc = "discart" // ArtSeasonPoster 是季海报(Season 是季号) ArtSeasonPoster = "season_poster" // ArtThumb 是一集的截图(Season、Episode 是季号与集号) ArtThumb = "thumb" )
图片的种类。
const LegacyDouban = "douban"
LegacyDouban 是旧版本的「简介与评分」选了豆瓣(MediaLibrary.ScrapeSource 为 douban):等于简介与评分都用豆瓣。
Variables ¶
var ( PlotSources = []string{"", SourceDouban, SourceBangumi} RatingSources = []string{"", SourceDouban, SourceBangumi, SourceOMDb} EpisodeSources = []string{"", SourceBangumi, SourceTVDB} ArtworkSources = []string{"", SourceFanart} )
每一项可选的来源(空串是 TMDB)。
Functions ¶
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 的。
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 ¶
Collection 是电影所属的系列(TMDB 的 collection)。
type Douban ¶
type Douban struct {
// contains filtered or unexported fields
}
Douban 是豆瓣来源:电影、剧集每一季的简介与评分。豆瓣上剧集一季是一个条目,整部剧集用第 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 Fanart ¶
type Fanart struct {
// contains filtered or unexported fields
}
Fanart 是 Fanart.tv 来源:海报、背景、高清 Logo、clearart、横幅、横版海报、碟片与季海报。 电影按 TMDB 编号找,剧集按 TVDB 编号找(TMDB 的详情里有时才有)。
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 是一部电影或一部剧集。
type ItemSource ¶
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。
type OMDb ¶
type OMDb struct {
// contains filtered or unexported fields
}
OMDb 是 OMDb 来源:按 IMDb 编号取 IMDb 评分、烂番茄、Metacritic 与分级。
type Person ¶
type Person struct {
// ID 是 TMDB 上这个人的编号(TMDB 以外的来源为 0)
ID int
Name string
Role string
Order int
Thumb string
}
Person 是一位演员:名字、饰演的角色、排第几、头像地址(完整的 URL,没有时为空)。
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 推送的电影才有)。别的来源按它找同一部。
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 ¶
NewResolver 用这些来源建一个 Resolver(nil 的跳过)。没有的来源当作不可用:设置里选了它时用 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) Pick ¶
Pick 按图片的设置挑一张:kind 是种类,season 与 episode 是季海报与截图的季号、集号。按来源的先后, 第一个有这种图的来源里按语言挑(见 choose)。没有时返回 nil。
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 是剧集的一季。
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 ¶
ParseSources 读媒体库存的数据来源(JSON)。为空时按旧版本的「简介与评分」(legacy):douban 是简介与评分都用豆瓣。 读不出来或有不认识的来源时当作全用 TMDB(不会因为设置坏了写错,界面上重新保存即可)。
type TMDB ¶
type TMDB struct {
// contains filtered or unexported fields
}
TMDB 是 TMDB 来源:电影与剧集的完整信息、每一季与每一集、海报、背景、Logo、季海报与集截图。 一次刮削里同一个条目的详情与同一季只取一次(几处同时要时等第一次的结果)。
func (*TMDB) Art ¶
Art 取图片:详情里 TMDB 按识别语言挑的海报与背景(Default);要 Logo 或选了图片语言时再取图片列表(缓存一周), 取不到时只有详情里的那两张,同时返回错误;剧集再取要的那几季的季海报与集截图。
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 ¶
NewTVDB 建 TheTVDB 来源:recogLang 是识别语言(例如 zh-CN),按它选 TheTVDB 的语言。c 为 nil 时返回 nil(没填 Key)。