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) DeleteOverride(ctx context.Context, id uint) error
- func (s *Service) DeleteWord(ctx context.Context, id uint) 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) 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 ( 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
}
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) DeleteOverride ¶
DeleteOverride 删除一条手动纠正。
func (*Service) DeleteWord ¶
DeleteWord 删除一条识别词。
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 确认条目存在。同一个解析结果只保留最新的一条。
type Settings ¶
type Settings struct {
HasTMDBKey bool `json:"has_tmdb_key"`
Language string `json:"language"`
ProxyURL string `json:"proxy_url"`
}
Settings 是给界面看的设置:API Key 只说有没有;代理地址里的密码换成 ***。
type SettingsInput ¶
type SettingsInput struct {
TMDBKey *string `json:"tmdb_api_key,omitempty"`
Language string `json:"language"`
ProxyURL *string `json:"proxy_url,omitempty"`
}
SettingsInput 是保存设置的参数。TMDBKey、ProxyURL 为 nil 时不改,为空串时清除。 ProxyURL 与 Settings 返回的(密码换成 *** 的)地址相同时也不改。