Documentation
¶
Overview ¶
Package serverindex 是媒体服务器索引:把服务器里的电影、剧与集全量同步进 media_server_items(拉全以后在一个事务里写, 没拉到的打删除标记、90 天后删行),同步时对 pt-tools 整理过、服务器里没有了的写待处理问题(media_issues 的 server_removed),并提供查询:条目在哪台服务器里、一季的哪些集在服务器里、算作已入库的集、问题列表。
Index ¶
- Constants
- Variables
- func Clear(tx *gorm.DB, key IssueKey, detail string, now time.Time) error
- func ClearUnmatched(tx *gorm.DB, mediaType string, tmdbID int, detail string, now time.Time) error
- func CountedEpisodes(ctx context.Context, db *gorm.DB, tmdbIDs []int) (map[EpisodeKey]bool, error)
- func Dismiss(ctx context.Context, db *gorm.DB, id uint, now time.Time) (models.MediaIssue, error)
- func EpisodeCount(eps []Episode) int
- func Forget(tx *gorm.DB, serverID uint) error
- func Issues(ctx context.Context, db *gorm.DB, f IssueFilter) ([]models.MediaIssue, error)
- func ItemIssues(ctx context.Context, db *gorm.DB, mediaType string, tmdbID int) ([]models.MediaIssue, error)
- func ItemMissing(ctx context.Context, db *gorm.DB, mediaType string, tmdbID int) ([]models.MediaIssue, error)
- func LocalPath(srv models.MediaServer, p string) string
- func OpenIssues(ctx context.Context, db *gorm.DB, mediaType string, tmdbID int) ([]models.MediaIssue, error)
- func OpenURL(srv models.MediaServer, itemID string) string
- func Raise(tx *gorm.DB, key IssueKey, info IssueInfo, now time.Time) error
- func Ref(h SeasonHit) string
- func SeasonEpisodes(ctx context.Context, db *gorm.DB, tmdbID, season int, countOnly bool) (map[int]SeasonHit, error)
- func SeasonsOf(eps []Episode) [][2]int
- func SeriesTMDB(ctx context.Context, db *gorm.DB, serverID uint, seriesItemID string) (int, error)
- func Servers(ctx context.Context, db *gorm.DB, countOnly bool) ([]models.MediaServer, error)
- type AddedItem
- type Episode
- type EpisodeKey
- type IssueFilter
- type IssueInfo
- type IssueKey
- type Presence
- type Result
- type SeasonHit
Constants ¶
const ( // MaxItems 是一台服务器最多同步多少项(电影、剧与集一起算);超过时这一轮不写 MaxItems = 200_000 // SyncTimeout 是一次同步(列完全部与写库)的总时限 SyncTimeout = 10 * time.Minute // PurgeAfter 是删除标记留多久:早于它、没有未处理问题的行才真正删掉 PurgeAfter = 90 * 24 * time.Hour )
Variables ¶
var ErrIssueNotFound = errors.New("问题不存在")
ErrIssueNotFound 表示问题不存在。
var ErrTooMany = errors.New("媒体服务器里的条目超过 20 万项,没有同步")
ErrTooMany 表示服务器里的条目超过 MaxItems。
Functions ¶
func ClearUnmatched ¶
ClearUnmatched 在删了整理记录以后看这一部(电影或剧)还开着、或忽略了的 server_removed 问题:对不上任何已整理记录的 (对应的规则同同步时写问题)改成解决了,说明写 detail。索引里那一项已经清掉了时按问题记的季集对。
func CountedEpisodes ¶
CountedEpisodes 是开了「算作已入库」的服务器里这些剧的全部集(日历用)。
func Issues ¶
func Issues(ctx context.Context, db *gorm.DB, f IssueFilter) ([]models.MediaIssue, error)
Issues 列出问题,最新的在前;Limit 为 0 时最多 500 条。
func ItemIssues ¶
func ItemIssues(ctx context.Context, db *gorm.DB, mediaType string, tmdbID int) ([]models.MediaIssue, error)
ItemIssues 是一部电影或剧还开着的 server_removed 问题(按季、集排)。
func ItemMissing ¶
func ItemMissing(ctx context.Context, db *gorm.DB, mediaType string, tmdbID int) ([]models.MediaIssue, error)
ItemMissing 是一部电影或剧还开着的 library_missing 问题(库里的文件不见了,按季、集排)。
func LocalPath ¶
func LocalPath(srv models.MediaServer, p string) string
LocalPath 把媒体服务器里的路径换成 pt-tools 里的路径(服务器设置的两个前缀反过来用);没设前缀时两边一样; 设了前缀而路径不在里面时为空。
func OpenIssues ¶
func OpenIssues(ctx context.Context, db *gorm.DB, mediaType string, tmdbID int) ([]models.MediaIssue, error)
OpenIssues 是一部电影或剧还开着的全部问题(服务器里删了的、库里的文件不见了的,按季、集排)。
func OpenURL ¶
func OpenURL(srv models.MediaServer, itemID string) string
OpenURL 是服务器里一项的打开链接(「打开链接用的地址」没填时用服务器地址)。
func SeasonEpisodes ¶
func SeasonEpisodes(ctx context.Context, db *gorm.DB, tmdbID, season int, countOnly bool) (map[int]SeasonHit, error)
SeasonEpisodes 是能用索引的服务器里一部剧一季的各集(集号 → 第一台有它的服务器与条目编号)。countOnly 为真时只看开了 「算作已入库」的服务器。
func SeriesTMDB ¶
SeriesTMDB 是服务器里一部剧(按条目编号)的 TMDB 编号;索引里没有时为 0。
Types ¶
type AddedItem ¶
type AddedItem struct {
Server models.MediaServer
ItemID string
MediaType string
TMDBID int
Title string
Season int
Episode int
AddedAt time.Time
}
AddedItem 是媒体服务器里新加的一项(不是 pt-tools 整理进库的):一部电影,或剧的一集(TMDBID 是剧的,Title 是剧名)。
type EpisodeKey ¶
type EpisodeKey struct{ TMDBID, Season, Episode int }
EpisodeKey 是一集:剧的 TMDB 编号、季、集。
type IssueFilter ¶
IssueFilter 是列问题的条件;空的一项不限。
type IssueInfo ¶
type IssueInfo struct {
MediaType string
TMDBID int
Season int
Episode int
Title string
Detail string
}
IssueInfo 是问题说的是哪一部、哪一集,以及说明。
type IssueKey ¶
IssueKey 是一个问题的唯一键:不适用的列写 0 或空串(server_removed 的 HistoryID 是 0,library_missing 的服务器两列是 0 与空串)。
func MissingKey ¶
MissingKey 是整理记录 historyID 的 library_missing 问题的键。
type Presence ¶
type Presence struct {
Server models.MediaServer
ItemID string
Episodes []Episode
}
Presence 是一台服务器里有没有一部电影或剧:ItemID 是电影或剧在服务器里的编号(没有时为空),Episodes 是剧在服务器里 有的集(按季、集排)。
type Result ¶
type Result struct {
Info server.Info `json:"-"`
Movies int `json:"movies"`
Series int `json:"series"`
Episodes int `json:"episodes"`
Added int `json:"added"`
Updated int `json:"updated"`
Removed int `json:"removed"`
Restored int `json:"restored"`
Purged int `json:"purged"`
Issues int `json:"issues"`
Partial bool `json:"partial,omitempty"`
Reset bool `json:"reset,omitempty"`
}
Result 是一次同步的结果。Movies、Series、Episodes 是同步以后服务器里有的;Partial 表示列的过程中服务器里的条目数变了, 这一轮没打删除标记;Reset 表示换了一台服务器(编号变了),旧的索引与问题清掉了。
type SeasonHit ¶
type SeasonHit struct {
Server models.MediaServer
ItemID string
}
SeasonHit 是一集在哪台服务器里:第一台有这一集的(按服务器编号)。