serverindex

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 11 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 serverindex 是媒体服务器索引:把服务器里的电影、剧与集全量同步进 media_server_items(拉全以后在一个事务里写, 没拉到的打删除标记、90 天后删行),同步时对 pt-tools 整理过、服务器里没有了的写待处理问题(media_issues 的 server_removed),并提供查询:条目在哪台服务器里、一季的哪些集在服务器里、算作已入库的集、问题列表。

Index

Constants

View Source
const (
	// MaxItems 是一台服务器最多同步多少项(电影、剧与集一起算);超过时这一轮不写
	MaxItems = 200_000
	// SyncTimeout 是一次同步(列完全部与写库)的总时限
	SyncTimeout = 10 * time.Minute
	// PurgeAfter 是删除标记留多久:早于它、没有未处理问题的行才真正删掉
	PurgeAfter = 90 * 24 * time.Hour
)

Variables

View Source
var ErrIssueNotFound = errors.New("问题不存在")

ErrIssueNotFound 表示问题不存在。

View Source
var ErrTooMany = errors.New("媒体服务器里的条目超过 20 万项,没有同步")

ErrTooMany 表示服务器里的条目超过 MaxItems。

Functions

func Clear

func Clear(tx *gorm.DB, key IssueKey, detail string, now time.Time) error

Clear 记下问题没有了:还开着的与用户忽略的改成解决了(resolved),写上说明;没有这个问题或已经解决的不动。

func ClearUnmatched

func ClearUnmatched(tx *gorm.DB, mediaType string, tmdbID int, detail string, now time.Time) error

ClearUnmatched 在删了整理记录以后看这一部(电影或剧)还开着、或忽略了的 server_removed 问题:对不上任何已整理记录的 (对应的规则同同步时写问题)改成解决了,说明写 detail。索引里那一项已经清掉了时按问题记的季集对。

func CountedEpisodes

func CountedEpisodes(ctx context.Context, db *gorm.DB, tmdbIDs []int) (map[EpisodeKey]bool, error)

CountedEpisodes 是开了「算作已入库」的服务器里这些剧的全部集(日历用)。

func Dismiss

func Dismiss(ctx context.Context, db *gorm.DB, id uint, now time.Time) (models.MediaIssue, error)

Dismiss 是用户忽略一个还开着的问题。问题不存在时返回 ErrIssueNotFound;已经不是开着的不动,返回它现在的样子。

func EpisodeCount

func EpisodeCount(eps []Episode) int

EpisodeCount 是这些项一共几集(同一集有几个文件时算一集)。

func Forget

func Forget(tx *gorm.DB, serverID uint) error

Forget 删掉一台服务器的索引与 server_removed 问题(删除服务器、换了一台服务器时)。

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 Raise

func Raise(tx *gorm.DB, key IssueKey, info IssueInfo, now time.Time) error

Raise 记下发现了一个问题:没有就新建(open);解决过的(resolved)改回 open;还开着的更新说明;用户忽略的(dismissed)不动。

func Ref

func Ref(h SeasonHit) string

Ref 是算作已入库的一集在台账里记的出处:服务器编号:条目编号。

func SeasonEpisodes

func SeasonEpisodes(ctx context.Context, db *gorm.DB, tmdbID, season int, countOnly bool) (map[int]SeasonHit, error)

SeasonEpisodes 是能用索引的服务器里一部剧一季的各集(集号 → 第一台有它的服务器与条目编号)。countOnly 为真时只看开了 「算作已入库」的服务器。

func SeasonsOf

func SeasonsOf(eps []Episode) [][2]int

SeasonsOf 是一台服务器里一部剧有的各季与每季的集数(季号从小到大,特别篇第 0 季排最后)。

func SeriesTMDB

func SeriesTMDB(ctx context.Context, db *gorm.DB, serverID uint, seriesItemID string) (int, error)

SeriesTMDB 是服务器里一部剧(按条目编号)的 TMDB 编号;索引里没有时为 0。

func Servers

func Servers(ctx context.Context, db *gorm.DB, countOnly bool) ([]models.MediaServer, error)

Servers 是能用索引的服务器:启用的、索引开着、同步成功过,按编号排。countOnly 为真时只要开了「算作已入库」的。

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 是剧名)。

func RecentAdded

func RecentAdded(ctx context.Context, db *gorm.DB, limit int) ([]AddedItem, error)

RecentAdded 是能用索引的服务器里最近新加的电影与集(最新在前,最多 limit 项)。pt-tools 整理进库的不算(对整理记录的规则同写问题: 有 pt-tools 的路径时按路径,换不了路径时按编号与季集),没有 TMDB 编号的也不算(打不开条目详情)。

type Episode

type Episode struct {
	ItemID     string
	Season     int
	Episode    int
	EpisodeEnd int
}

Episode 是服务器里的一集。

type EpisodeKey

type EpisodeKey struct{ TMDBID, Season, Episode int }

EpisodeKey 是一集:剧的 TMDB 编号、季、集。

type IssueFilter

type IssueFilter struct {
	Status    string
	Kind      string
	MediaType string
	TMDBID    int
	Limit     int
}

IssueFilter 是列问题的条件;空的一项不限。

type IssueInfo

type IssueInfo struct {
	MediaType string
	TMDBID    int
	Season    int
	Episode   int
	Title     string
	Detail    string
}

IssueInfo 是问题说的是哪一部、哪一集,以及说明。

type IssueKey

type IssueKey struct {
	Kind         string
	ServerID     uint
	ServerItemID string
	HistoryID    uint
}

IssueKey 是一个问题的唯一键:不适用的列写 0 或空串(server_removed 的 HistoryID 是 0,library_missing 的服务器两列是 0 与空串)。

func MissingKey

func MissingKey(historyID uint) IssueKey

MissingKey 是整理记录 historyID 的 library_missing 问题的键。

type Presence

type Presence struct {
	Server   models.MediaServer
	ItemID   string
	Episodes []Episode
}

Presence 是一台服务器里有没有一部电影或剧:ItemID 是电影或剧在服务器里的编号(没有时为空),Episodes 是剧在服务器里 有的集(按季、集排)。

func Lookup

func Lookup(ctx context.Context, db *gorm.DB, mediaType string, tmdbID int) ([]Presence, error)

Lookup 是能用索引的服务器里各有没有这部电影或剧(每台一项,没有的 ItemID 为空)。

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 表示换了一台服务器(编号变了),旧的索引与问题清掉了。

func Sync

func Sync(ctx context.Context, db *gorm.DB, srv models.MediaServer, c server.Client, now time.Time) (Result, error)

Sync 同步一台服务器的索引:先 Test(读名字、版本、编号),再列到底,最后在一个事务里写库、写问题、清理、改服务器上的 同步结果。中途出错、超时、超量时不写索引,只把原因记进服务器的 index_error(被取消的不记)。调用方保证同一台服务器 不会同时同步。

type SeasonHit

type SeasonHit struct {
	Server models.MediaServer
	ItemID string
}

SeasonHit 是一集在哪台服务器里:第一台有这一集的(按服务器编号)。

Jump to

Keyboard shortcuts

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