Documentation
¶
Overview ¶
Package recognize 是媒体识别服务:套用识别词、解析标题,再到 TMDB 找对应的条目 (有 IMDb 编号时直接查找,否则按中英文名和年份搜索打分),支持按 TMDB 编号手动纠正。 也管 TMDB 的设置(API Key 与代理加密保存、只写不读)与识别词。
Index ¶
- Constants
- Variables
- func Normalize(s string) string
- type Candidate
- type Cipher
- type Config
- type Input
- type OverrideInput
- type Result
- type Service
- func (s *Service) Candidates(ctx context.Context, in Input, limit int) ([]Candidate, error)
- func (s *Service) DeleteOverride(ctx context.Context, id uint) error
- func (s *Service) DeleteWord(ctx context.Context, id uint) error
- func (s *Service) Fanart(ctx context.Context) (*fanart.Client, error)
- func (s *Service) Images(ctx context.Context) (*tmdb.ImageClient, error)
- func (s *Service) OMDb(ctx context.Context) (*omdb.Client, error)
- func (s *Service) Overrides(ctx context.Context) ([]models.MediaOverride, error)
- func (s *Service) Parse(ctx context.Context, title, subtitle string) (meta.Meta, error)
- func (s *Service) Recognize(ctx context.Context, in Input) (*Result, error)
- func (s *Service) SaveSettings(ctx context.Context, in SettingsInput) (Settings, error)
- func (s *Service) SaveWord(ctx context.Context, r models.MediaWordRule) (*models.MediaWordRule, error)
- func (s *Service) SetOverride(ctx context.Context, in OverrideInput) (*models.MediaOverride, error)
- func (s *Service) Settings(ctx context.Context) (Settings, error)
- func (s *Service) TMDB(ctx context.Context) (*tmdb.Client, error)
- func (s *Service) TestFanart(ctx context.Context) error
- func (s *Service) TestOMDb(ctx context.Context) error
- func (s *Service) TestTMDB(ctx context.Context) error
- func (s *Service) Words(ctx context.Context) ([]models.MediaWordRule, error)
- type Settings
- type SettingsInput
Constants ¶
const ( AcceptScore = 0.95 AcceptMargin = 0.1 )
AcceptScore 是认定为匹配的最低分;名字至少要部分相同(titleScore ≥ 0.75)。 名字只是部分相同时,第一名还要比第二名高出 AcceptMargin,否则只列候选。
const ( KeyUser = "user" // 自己填的 KeyBuiltin = "builtin" // 没填,用构建时内置的 KeyNone = "none" // 没有能用的:没填,这个版本也没有内置的,或者换了接口地址(内置的只发给官方地址) )
识别现在用的 TMDB API Key(Settings.KeySource)。
const ( SourceNone = "none" SourceOverride = "override" SourceIMDb = "imdb" SourceSearch = "search" )
识别结果的来源。
Variables ¶
var ( // ErrInvalid 表示参数不对(错误信息写明哪一项)。 ErrInvalid = errors.New("参数无效") // ErrNotFound 表示要改或删的记录不存在。 ErrNotFound = errors.New("记录不存在") )
var Languages = []string{"zh-CN", "zh-TW", "zh-HK", "en-US", "ja-JP"}
Languages 是可选的 TMDB 语言(第一个是默认值)。
Functions ¶
Types ¶
type Cipher ¶
type Cipher interface {
Encrypt(plain string) (string, error)
Decrypt(cipherText string) (string, error)
}
Cipher 加解密 API Key 与代理地址(生产环境是 ConfigStore 的 EncryptCookie / DecryptCookie)。
type Config ¶
type Config struct {
DB *gorm.DB
Cipher Cipher
// BaseURL 是 TMDB 接口地址;为空时用官方地址(qa 构建可指向假服务)。
BaseURL string
// ImageBaseURL 是 TMDB 图片地址(到 /t/p/ 为止);为空时用官方地址(qa 构建可指向假服务)。
ImageBaseURL string
// RatePerSecond 是 TMDB 请求的限速(为 0 时用客户端的默认值)。
RatePerSecond float64
// FanartBaseURL、OMDbBaseURL 是 Fanart.tv 与 OMDb 的接口地址;为空时用官方地址(测试与 qa 构建可指向假服务)。
FanartBaseURL, OMDbBaseURL string
// FanartImageHosts 是允许下载 Fanart.tv 图片的主机;为空时只认 fanart.tv 自己的(测试里换成假服务的)。
FanartImageHosts []string
}
Config 是服务的依赖。
type Input ¶
type Input struct {
Title string `json:"title"`
Subtitle string `json:"subtitle"`
IMDbID string `json:"imdb_id"`
}
Input 是识别的输入。
type OverrideInput ¶
type OverrideInput struct {
Title string `json:"title"`
Subtitle string `json:"subtitle"`
TMDBID int `json:"tmdb_id"`
MediaType string `json:"media_type"`
}
OverrideInput 是手动纠正的参数:这个标题(按解析结果)固定识别成 TMDB 上的这个条目。
type Result ¶
type Result struct {
Meta meta.Meta `json:"meta"`
Summary string `json:"summary"`
RuleHits []uint `json:"rule_hits,omitempty"`
Match *tmdb.Result `json:"match,omitempty"`
Source string `json:"source"`
Score float64 `json:"score,omitempty"`
Candidates []Candidate `json:"candidates,omitempty"`
OverrideID uint `json:"override_id,omitempty"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
}
Result 是识别结果。TMDB 出错时 Meta 照样有,Error 写明原因。
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 是媒体识别服务。
func (*Service) Candidates ¶
Candidates 是一个标题在 TMDB 上的候选:套用识别词解析以后电影与剧集都搜,按分数排,最多 limit 个(1 到 20)。 不看手动纠正与 IMDb 编号:给自动识别认不出的标题让人或 AI 挑。解析出的名字为空时没有候选;没填 TMDB API Key 时返回 tmdb.ErrNoKey。
func (*Service) DeleteOverride ¶
DeleteOverride 删除一条手动纠正。
func (*Service) DeleteWord ¶
DeleteWord 删除一条识别词。
func (*Service) Fanart ¶
Fanart 按当前设置建 Fanart.tv 客户端(刮削时取图片,走媒体识别的代理,和 TMDB 共用缓存):项目的 Key,填了个人 Key 时一起发; 没填项目的 Key 时返回 fanart.ErrNoKey。
func (*Service) OMDb ¶
OMDb 按当前设置建 OMDb 客户端(刮削时取 IMDb 等评分,走媒体识别的代理,和 TMDB 共用缓存);没填 API Key 时返回 omdb.ErrNoKey。
func (*Service) SaveSettings ¶
SaveSettings 保存设置。
func (*Service) SaveWord ¶
func (s *Service) SaveWord(ctx context.Context, r models.MediaWordRule) (*models.MediaWordRule, error)
SaveWord 新建(ID 为 0)或修改一条识别词。
func (*Service) SetOverride ¶
func (s *Service) SetOverride(ctx context.Context, in OverrideInput) (*models.MediaOverride, error)
SetOverride 保存一条手动纠正:先到 TMDB 确认条目存在。同一个解析结果只保留最新的一条。
func (*Service) TestFanart ¶
TestFanart 用当前设置访问一次 Fanart.tv,确认 API Key 与代理可用。
type Settings ¶
type Settings struct {
HasTMDBKey bool `json:"has_tmdb_key"`
// KeySource 是识别现在用哪个 Key(KeyUser、KeyBuiltin、KeyNone)
KeySource string `json:"key_source"`
// BuiltinKey 表示这个版本内置了 Key(发布的 Release 与 Docker 镜像有,从源码编译的没有)
BuiltinKey bool `json:"builtin_key"`
Language string `json:"language"`
ProxyURL string `json:"proxy_url"`
APIBaseURL string `json:"api_base_url"`
ImageBaseURL string `json:"image_base_url"`
// HasFanartKey、HasOMDbKey 说刮削用的 Fanart.tv(项目的 Key)与 OMDb 的 API Key 填了没有,HasFanartClientKey 说
// Fanart.tv 的个人 Key 填了没有
HasFanartKey bool `json:"has_fanart_key"`
HasFanartClientKey bool `json:"has_fanart_client_key"`
HasOMDbKey bool `json:"has_omdb_key"`
}
Settings 是给界面看的设置:API Key 只说有没有(HasTMDBKey 是自己填的那个);代理地址里的密码换成 ***。 APIBaseURL、ImageBaseURL 是换掉的地址,空 = 官方地址。
type SettingsInput ¶
type SettingsInput struct {
TMDBKey *string `json:"tmdb_api_key,omitempty"`
Language string `json:"language"`
ProxyURL *string `json:"proxy_url,omitempty"`
APIBaseURL *string `json:"api_base_url,omitempty"`
ImageBaseURL *string `json:"image_base_url,omitempty"`
// FanartKey、OMDbKey 是刮削用的 Fanart.tv(项目的 Key)与 OMDb 的 API Key,FanartClientKey 是 Fanart.tv 的个人 Key
// (可选;加上以后新上传的图片更快能用,见 Fanart、OMDb)
FanartKey *string `json:"fanart_api_key,omitempty"`
FanartClientKey *string `json:"fanart_client_key,omitempty"`
OMDbKey *string `json:"omdb_api_key,omitempty"`
}
SettingsInput 是保存设置的参数。TMDBKey、ProxyURL、APIBaseURL、ImageBaseURL、FanartKey、OMDbKey 为 nil 时不改, 为空串时清除(两个地址清除以后用官方地址)。ProxyURL 与 Settings 返回的(密码换成 *** 的)地址相同时也不改。