subscribe

package
v1.0.0-rc.21 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package subscribe 是订阅:按电影或剧集的一季找资源(RSS 拉到的种子与定时主动搜索),按质量档案挑、推送到下载器, 剧集按 TMDB 的分集找缺的集;洗版时接着找更好的版本,入库后替换旧文件;豆瓣想看定时建订阅。

Index

Constants

View Source
const (
	DefaultSearchIntervalHours = 12
	MinSearchIntervalHours     = 6
)

设置的默认值与范围。

View Source
const (
	EpisodeLibrary     = "library"
	EpisodeDownloading = "downloading"
	EpisodeMissing     = "missing"
	EpisodeUpcoming    = "upcoming"
)

一集的情况。

View Source
const (
	NoticeDownloaded     = "subscribe_downloaded"
	NoticeDoubanAbnormal = "douban_abnormal"
)

通知的种类。

View Source
const ExploreSearch = "search"

探索页的列表:本周趋势、热门,或者搜索。

Variables

View Source
var (
	Resolutions = []string{"4320p", "2160p", "1440p", "1080p", "720p", "576p", "480p"}
	Sources     = []string{"UHD BluRay", "BluRay", "WEB-DL", "WEBRip", "HDTV", "DVD"}
	Codecs      = []string{"H.265", "AV1", "H.264", "VC-1", "MPEG-2", "XviD"}
)

分辨率、来源、编码的可选值(internal/media/meta 解析出的写法),列表里从好到差。档案里没有选时按这个顺序比较 分辨率与来源,编码不比。

View Source
var (
	ErrInvalid  = errors.New("参数不对")
	ErrNotFound = errors.New("没有这条记录")
	// ErrBusy 是同一件事正在做(例如这个豆瓣来源正在拉取)
	ErrBusy = errors.New("正在处理")
)

错误。接口层按它们回 400 / 404。

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	Site string
	Item v2.TorrentItem
	Meta meta.Meta
	From string
	// SiteHR 是站点整站都有 H&R 要求
	SiteHR bool
}

Candidate 是一个候选种子:站点上的种子、从标题解析出的信息,以及从哪里来的(rss 或 search)。

type Config

type Config struct {
	DB          *gorm.DB
	Recognizer  Recognizer
	Search      Searcher
	Sites       SitesFunc
	SiteNames   func() []string
	Push        PushFunc
	Downloaders Downloaders
	Library     Library
	Organizer   Organizer
	Notify      Notifier
	Logger      *zap.SugaredLogger
	Now         func() time.Time
	// Jitter 是主动搜索与豆瓣拉取的随机偏移(测试里换成固定的)
	Jitter func(limit time.Duration) time.Duration
	// HTTP 拉豆瓣用(为空时用带超时的默认客户端,走系统代理)
	HTTP *http.Client
	// DoubanBase 是豆瓣的地址(测试与 QA 换成假服务)
	DoubanBase string
}

Config 是订阅服务的依赖。

type DoubanSourceInput

type DoubanSourceInput struct {
	UserID    string `json:"user_id"`
	Name      string `json:"name"`
	Enabled   bool   `json:"enabled"`
	Confirm   bool   `json:"confirm"`
	ProfileID uint   `json:"profile_id"`
}

DoubanSourceInput 是新建或修改豆瓣来源的内容。

type DoubanSourceView

type DoubanSourceView struct {
	models.MediaDoubanSource
	Subscribed int `json:"subscribed"`
	Unmatched  int `json:"unmatched"`
}

DoubanSourceView 是豆瓣来源加上建过的订阅数(包括后来删掉的)与没找到条目的数。

type Downloaders

type Downloaders interface {
	Get(ctx context.Context, id uint) (downloader.Downloader, models.DownloaderSetting, error)
}

Downloaders 按编号取下载器(洗版以后删旧种子用)。

type EpisodeState

type EpisodeState struct {
	Number  int    `json:"number"`
	Name    string `json:"name,omitempty"`
	AirDate string `json:"air_date,omitempty"`
	State   string `json:"state"`
}

EpisodeState 是一集的情况:library 已入库、downloading 下载中、missing 缺、upcoming 还没播出。

type ExploreItem

type ExploreItem struct {
	tmdb.Result
	InLibrary bool `json:"in_library"`
	// Subscribed 是这个条目有订阅(剧集是任意一季);SubscriptionID 是其中最新的一个
	Subscribed     bool `json:"subscribed"`
	SubscriptionID uint `json:"subscription_id,omitempty"`
}

ExploreItem 是探索页的一个条目,标上库里有没有、订阅过没有。

type ExplorePage

type ExplorePage struct {
	Items      []ExploreItem `json:"items"`
	Page       int           `json:"page"`
	TotalPages int           `json:"total_pages"`
}

ExplorePage 是探索页的一页。

type Library

type Library interface {
	InLibrary(ctx context.Context, kind string, tmdbID int, imdbID, title string) (bool, error)
}

Library 报告条目在不在媒体服务器里(没有配媒体服务器时返回 false;生产环境是 *organize.Service)。

type Notice

type Notice struct {
	Channels []uint
	Kind     string
	Subject  string
	EventKey string
	Title    string
	Body     string
	ImageURL string
}

Notice 是一条订阅的通知:下载了订阅的资源,或豆瓣想看拉取连续失败。

type Notifier

type Notifier func(ctx context.Context, n Notice) error

Notifier 发通知(生产环境经监控通知投递器)。

type Organizer

type Organizer interface {
	Retire(ctx context.Context, id uint, reason string) ([]string, error)
	Retry(ctx context.Context, id uint) (*organize.Result, error)
	// Retrying 报告失败的记录是不是正在重试(排上队以后记录里的重试时间是空的)
	Retrying(id uint) bool
}

Organizer 是整理入库里洗版要用的两个动作(生产环境是 *organize.Service)。

type Profile

type Profile struct {
	ID          uint     `json:"id"`
	Name        string   `json:"name"`
	Resolutions []string `json:"resolutions"`
	Sources     []string `json:"sources"`
	Codecs      []string `json:"codecs"`
	Remux       string   `json:"remux"`
	HDR         string   `json:"hdr"`
	ChineseSubs string   `json:"chinese_subs"`
	Free        string   `json:"free"`
	Groups      []string `json:"groups"`
	MinSizeGB   float64  `json:"min_size_gb"`
	MaxSizeGB   float64  `json:"max_size_gb"`
	MinSeeders  int      `json:"min_seeders"`
	ExcludeHR   bool     `json:"exclude_hr"`
}

Profile 是解开 JSON 以后的质量档案。

func (Profile) Score

func (p Profile) Score(c Candidate, episodes int) Verdict

Score 按档案给候选种子打分。episodes 是种子里有几集(剧集按每集算体积;电影与认不出集数的传 1)。 RSS 里刚发布的种子做种数还没有意义,最少做种数只对搜索到的种子生效。

func (Profile) TargetReached

func (p Profile) TargetReached(m meta.Meta) bool

TargetReached 报告资源是不是已经达到档案里排第一的分辨率与来源(档案要优先 Remux 时还要是 Remux): 洗版到这里就停。档案里没有选分辨率或来源时,那一项不限。

type ProfileInput

type ProfileInput struct {
	Name        string   `json:"name"`
	Resolutions []string `json:"resolutions"`
	Sources     []string `json:"sources"`
	Codecs      []string `json:"codecs"`
	Remux       string   `json:"remux"`
	HDR         string   `json:"hdr"`
	ChineseSubs string   `json:"chinese_subs"`
	Free        string   `json:"free"`
	Groups      []string `json:"groups"`
	MinSizeGB   float64  `json:"min_size_gb"`
	MaxSizeGB   float64  `json:"max_size_gb"`
	MinSeeders  int      `json:"min_seeders"`
	ExcludeHR   bool     `json:"exclude_hr"`
}

ProfileInput 是新建或修改质量档案的内容。

type Progress

type Progress struct {
	Total       int   `json:"total"`
	Aired       int   `json:"aired"`
	InLibrary   int   `json:"in_library"`
	Downloading int   `json:"downloading"`
	Missing     []int `json:"missing,omitempty"`
	// Episodes 是每一集的情况(详情里才有)
	Episodes []EpisodeState `json:"episodes,omitempty"`
}

Progress 是订阅的进度。电影:Total 为 1,入了库 InLibrary 为 1。剧集按 TMDB 这一季的分集算,只算已经播出的。

type PushFunc

PushFunc 是推送入口(生产环境是 internal.PushTorrentToDownloader,磁盘与站点容量闸门都在里面)。

type Recognizer

type Recognizer interface {
	Recognize(ctx context.Context, in recognize.Input) (*recognize.Result, error)
	Parse(ctx context.Context, title, subtitle string) (meta.Meta, error)
	TMDB(ctx context.Context) (*tmdb.Client, error)
}

Recognizer 是媒体识别(生产环境是 *recognize.Service)。

type Searcher

type Searcher interface {
	Search(ctx context.Context, q v2.MultiSiteSearchQuery) (*v2.MultiSiteSearchResult, error)
}

Searcher 是多站点搜索(生产环境是 CachedSearchOrchestrator)。

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service 是订阅服务。

func New

func New(cfg Config) *Service

New 建订阅服务;Start 以后才接 RSS 与定时搜索。

func (*Service) CreateSubscription

func (s *Service) CreateSubscription(ctx context.Context, in SubscriptionInput, source string) (*models.MediaSubscription, error)

CreateSubscription 按 TMDB 条目建订阅:取详情(名字、年份、IMDb、海报、别名),剧集取这一季的集数。 同一个条目的同一季已经订阅过时返回 ErrInvalid。

func (*Service) DeleteDoubanSource

func (s *Service) DeleteDoubanSource(ctx context.Context, id uint) error

DeleteDoubanSource 删除豆瓣来源与它见过的条目(建过的订阅留着)。

func (*Service) DeleteProfile

func (s *Service) DeleteProfile(ctx context.Context, id uint) error

DeleteProfile 删除质量档案:还有订阅、豆瓣来源在用或是默认档案时不删。

func (*Service) DeleteSubscription

func (s *Service) DeleteSubscription(ctx context.Context, id uint) error

DeleteSubscription 删除订阅与它下载过的种子记录(下载器里的种子与库里的文件不动)。

func (*Service) DoubanItems

func (s *Service) DoubanItems(ctx context.Context, id uint) ([]models.MediaDoubanItem, error)

DoubanItems 是一个来源见过的条目(新的在前)。

func (*Service) DoubanSources

func (s *Service) DoubanSources(ctx context.Context) ([]DoubanSourceView, error)

DoubanSources 列出豆瓣来源。

func (*Service) Explore

func (s *Service) Explore(ctx context.Context, kind, list string, page int, query string) (*ExplorePage, error)

Explore 取 TMDB 的趋势、热门或搜索结果(搜索只有一页),标上已入库(整理记录里有)与已订阅。

func (*Service) FetchDouban

func (s *Service) FetchDouban(ctx context.Context, id uint) (int, error)

FetchDouban 立即拉一次豆瓣来源,返回新建的订阅数。这个来源正在拉取时返回 ErrBusy。

func (*Service) Offer

func (s *Service) Offer(site string, item v2.TorrentItem)

Offer 把 RSS 拉到的种子交给订阅(不阻塞;队列满时丢掉,主动搜索还会找到)。

func (*Service) Profiles

func (s *Service) Profiles(ctx context.Context) ([]Profile, error)

Profiles 列出质量档案。

func (*Service) SaveDoubanSource

func (s *Service) SaveDoubanSource(ctx context.Context, id uint, in DoubanSourceInput) (*models.MediaDoubanSource, error)

SaveDoubanSource 新建(id 为 0)或修改豆瓣来源。新建与重新启用的马上拉一次。

func (*Service) SaveProfile

func (s *Service) SaveProfile(ctx context.Context, id uint, in ProfileInput) (Profile, error)

SaveProfile 新建(id 为 0)或修改质量档案。

func (*Service) SaveSettings

func (s *Service) SaveSettings(ctx context.Context, in Settings) (Settings, error)

SaveSettings 保存订阅设置。

func (*Service) SearchNow

func (s *Service) SearchNow(ctx context.Context, id uint) (string, error)

SearchNow 立即搜索一个订阅,返回结果说明。

func (*Service) SetStatus

func (s *Service) SetStatus(ctx context.Context, id uint, status string) (*models.MediaSubscription, error)

SetStatus 暂停、恢复或确认订阅:status 要是 active 或 paused。

func (*Service) Settings

func (s *Service) Settings(ctx context.Context) (Settings, error)

Settings 读订阅设置(没有保存过时是默认值)。

func (*Service) Start

func (s *Service) Start(ctx context.Context)

Start 启动后台:处理 RSS 交来的种子,每分钟看一次到期的搜索、下载中的种子与豆瓣想看。

func (*Service) Stop

func (s *Service) Stop()

Stop 停掉后台并等它退出。

func (*Service) Subscription

func (s *Service) Subscription(ctx context.Context, id uint) (*SubscriptionDetail, error)

Subscription 是一个订阅的详情。

func (*Service) Subscriptions

func (s *Service) Subscriptions(ctx context.Context, q SubscriptionQuery) ([]SubscriptionView, error)

Subscriptions 列出订阅(新的在前),带进度。

func (*Service) Tick

func (s *Service) Tick(ctx context.Context)

Tick 做一轮后台工作:下载中的种子入库了没有、订阅完成了没有、到期的主动搜索与豆瓣想看。总开关关着时什么都不做。

func (*Service) UpdateSubscription

func (s *Service) UpdateSubscription(ctx context.Context, id uint, in SubscriptionInput) (*models.MediaSubscription, error)

UpdateSubscription 修改订阅(条目与季不能改)。

type Settings

type Settings struct {
	Enabled             bool     `json:"enabled"`
	SearchIntervalHours int      `json:"search_interval_hours"`
	SearchSkipSites     []string `json:"search_skip_sites"`
	DefaultProfileID    uint     `json:"default_profile_id"`
	DefaultDownloaderID uint     `json:"default_downloader_id"`
	NotifyChannels      []uint   `json:"notify_channels"`
	UpgradeOld          string   `json:"upgrade_old"`
}

Settings 是订阅的设置。

type SitesFunc

type SitesFunc func(name string) (v2.Site, bool)

SitesFunc 按站点名取共享的站点实例(下载种子文件用,与搜索、登录探测共用限速)。

type SubscriptionDetail

type SubscriptionDetail struct {
	SubscriptionView
	TorrentList []models.MediaSubscriptionTorrent `json:"torrent_list"`
}

SubscriptionDetail 是订阅详情:订阅、进度与下载过的种子。

type SubscriptionInput

type SubscriptionInput struct {
	MediaType    string   `json:"media_type"`
	TMDBID       int      `json:"tmdb_id"`
	Season       int      `json:"season"`
	ProfileID    uint     `json:"profile_id"`
	Sites        []string `json:"sites"`
	DownloaderID uint     `json:"downloader_id"`
	Category     string   `json:"category"`
	Tags         string   `json:"tags"`
	SavePath     string   `json:"save_path"`
	Upgrade      bool     `json:"upgrade"`
	// Pending 为真时建成待确认
	Pending bool `json:"pending"`
}

SubscriptionInput 是新建或修改订阅的内容。新建时要条目(类型、TMDB 编号,剧集还要季);修改时这几项不能改。

type SubscriptionQuery

type SubscriptionQuery struct {
	Status  string
	Keyword string
}

SubscriptionQuery 是订阅列表的筛选。

type SubscriptionView

type SubscriptionView struct {
	models.MediaSubscription
	Sites    []string  `json:"sites"`
	Progress *Progress `json:"progress,omitempty"`
	Torrents int       `json:"torrents"`
}

SubscriptionView 是订阅加上进度与已下载的种子数。

type Verdict

type Verdict struct {
	Score  int
	Reject string
}

Verdict 是一个候选种子按质量档案的结果:Reject 不为空时不要(写明原因),否则 Score 是分数。

Jump to

Keyboard shortcuts

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