freewatch

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 26 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 freewatch 是「等免费再下」(媒体中心 M2b):记下一个现在不免费的种子要推到哪里,后台定时读它现在的优惠, 免费了才推送(照常过免费门禁、磁盘与站点容量闸门,免费结束时暂停),等到期了还没免费就放弃。

Index

Constants

View Source
const (
	SourceManual = "manual"
	SourceBatch  = "batch"
	SourceApp    = "app"
)

登记来源(FreeWatch.Source)。

View Source
const (
	ResultCreated     = "created"
	ResultWouldCreate = "would_create"
	ResultSkipped     = "skipped"
)

批量登记的结果(BatchItemResult.Result)。

View Source
const (
	// SkipInvalid 是站点或编号写得不对
	SkipInvalid = "invalid"
	// SkipDuplicate 是同一批里前面出现过
	SkipDuplicate = "duplicate"
	// SkipSiteUnsupported 是站点没有启用或读不了种子详情
	SkipSiteUnsupported = "site_unsupported"
	// SkipExists 是同站同编号已经有一条等免费的记录(不论状态:到期、取消的要重新等,单个点「等免费」)
	SkipExists = "exists"
	// SkipPushed 是种子记录里推送过(含已归档的)
	SkipPushed = "pushed"
	// SkipBlocked 是拉黑了(对所有条目生效的拉黑)
	SkipBlocked = "blocked"
	// SkipLimit 是在等的满了
	SkipLimit = "limit"
	// SkipRunLimit 是搜索订阅这一次登记的条数到了上限(#935 P3)
	SkipRunLimit = "run_limit"
	// SkipWorkChanged 是要替换的旧记录这期间被取消或已经结束了(#935 P3)
	SkipWorkChanged = "work_changed"
)

跳过的原因(BatchItemResult.Reason,脚本按它判断,写法固定)。

View Source
const (
	// MaxWatching 是最多同时在等几条的默认值(设置里可以改,见 Settings)
	MaxWatching = 200
	// DefaultDays 是默认等待天数的默认值;MaxDays 是最长天数的默认值(设置里都可以改,最长一年)
	DefaultDays = 7
	MaxDays     = 30
	// PerSiteRound 是默认设置下每一轮每个站点最多读几个种子:每小时 120 次摊到每 5 分钟一轮(见 Settings.RoundSlice)
	PerSiteRound = 10
	// NotFreeRetry 是还没免费(或者免费剩得太少、闸门没放行)时隔多久再看的默认值(设置里可以改,实际在 80%–120% 之间随机)
	NotFreeRetry = 30 * time.Minute
	// MaxFailures 是连续读不到几次以后不再等
	MaxFailures = 5
)
View Source
const (
	KindPushed  = "pushed"
	KindExpired = "expired"
	KindFailed  = "failed"
	// KindRound 是一轮里批量、接口登记的到期与不再等合成的一条(#935 P2)
	KindRound = "round"
)

通知的种类(Message.Kind)。

View Source
const (
	// MaxSearches 是最多几条搜索订阅
	MaxSearches = 50
	// DefaultMaxPerRun、MaxMaxPerRun 是每次最多登记几条的默认值与上限
	DefaultMaxPerRun = 20
	MaxMaxPerRun     = 200
	// DefaultSearchInterval、MinSearchInterval、MaxSearchInterval 是多久搜一次(分钟)
	DefaultSearchInterval = 120
	MinSearchInterval     = 60
	MaxSearchInterval     = 1440
	// MaxWithinDays 是「只看最近 N 天发布的」最多几天
	MaxWithinDays = 365
)

搜索订阅的上限与默认值。

View Source
const (
	KeepNewest  = "newest"
	KeepLargest = "largest"
	KeepFirst   = "first"
)

保留策略(同一作品留哪个)。

View Source
const (
	RunCreate   = "create"
	RunReplace  = "replace"
	RunSkip     = "skip"
	RunFiltered = "filtered"

	// 本地筛掉的
	RunTooOld   = "too_old"
	RunNoMatch  = "no_match"
	RunExcluded = "excluded"
	// 按作品去重跳过的
	RunNotChosen    = "not_chosen"
	RunWorkPushed   = "work_pushed"
	RunWorkCanceled = "work_canceled"
	RunWorkWatching = "work_watching"
	RunNotBetter    = "not_better"
)

一次运行里一条结果的去向(SearchRunItem.Result)与原因(Reason,除了下面这些还有批量登记的 Skip*)。

View Source
const (
	// DefaultSiteHourlyRequests 是每个站点每小时最多读几次详情的默认值:等于以前的每 5 分钟每站 10 个
	DefaultSiteHourlyRequests = 120
	// DefaultTick 是后台多久跑一轮
	DefaultTick = 5 * time.Minute
)

设置的默认值与范围(#935 P2)。MaxWatching、MaxDays、DefaultDays、NotFreeRetry 是默认值,实际按 Settings 算。

View Source
const MaxBatchItems = 200

MaxBatchItems 是一次批量登记最多几条。

View Source
const SourceSearch = "search"

SourceSearch 是搜索订阅登记的等免费。

Variables

View Source
var (
	ErrInvalid  = errors.New("参数不对")
	ErrNotFound = errors.New("没有这条记录")
)
View Source
var ErrNotWatching = fmt.Errorf("%w: 这一条已经不在等了", ErrInvalid)

ErrNotWatching 是「这一条已经不在等了」。包着 ErrInvalid:网页仍回 400,App 回 409。

View Source
var SettingLimits = struct {
	MaxWatching        Range `json:"max_watching"`
	MaxDays            Range `json:"max_days"`
	DefaultDays        Range `json:"default_days"`
	SiteHourlyRequests Range `json:"site_hourly_requests"`
	RecheckMinutes     Range `json:"recheck_minutes"`
}{

	MaxWatching: Range{1, 2000}, MaxDays: Range{1, 365}, DefaultDays: Range{1, 365}, SiteHourlyRequests: Range{10, 600},
	RecheckMinutes: Range{10, 1440},
}

SettingLimits 是各项设置的范围。

View Source
var StatsDays = []int{7, 30, 90}

StatsDays 是转化统计能选的天数。

Functions

func EndReasonOf added in v1.3.0

func EndReasonOf(w models.FreeWatch) string

EndReasonOf 是一条记录不再等的原因:以前的记录没有写,按状态推断(推送了算等到免费,取消算用户取消);在等的为空。

func Notice

func Notice(m Message, now time.Time) (title, text string, ev *notify.Event)

Notice 是一条通知的内置标题、正文与事件(消息模板用)。now 是发出的时间。

func SearchFiltersOf added in v1.3.0

func SearchFiltersOf(row models.FreeWatchSearch) v2.SearchFilters

SearchFiltersOf 是一条搜索订阅存的分类筛选(读不出来时为空)。

func SourceOf added in v1.3.0

func SourceOf(w models.FreeWatch) string

SourceOf 是记录的来源:以前的记录是空串,按 manual 算。

Types

type BatchInput added in v1.3.0

type BatchInput struct {
	BatchTarget
	Items  []BatchItem `json:"items"`
	DryRun bool        `json:"dry_run"`
	Source string      `json:"-"`
	// contains filtered or unexported fields
}

BatchInput 是一次批量登记。DryRun 为真时只算不写;Source 由接口层填,用户填不了。

type BatchItem added in v1.3.0

type BatchItem struct {
	Site        string `json:"site"`
	TorrentID   string `json:"torrent_id"`
	Title       string `json:"title"`
	Subtitle    string `json:"subtitle"`
	SizeBytes   int64  `json:"size_bytes"`
	HasHR       bool   `json:"has_hr"`
	HRSeedTimeH int    `json:"hr_seed_time_h"`
	InfoHash    string `json:"info_hash"`
	// Free 是搜索结果里看到它免费:只决定先查谁(记成 free_hint_at),推送前照样重读详情
	Free bool `json:"free"`
	// contains filtered or unexported fields
}

BatchItem 是一批里的一个种子。标题、体积、H&R、哈希都是可选的(搜索结果里有就带上)。

type BatchItemResult added in v1.3.0

type BatchItemResult struct {
	Site      string `json:"site"`
	TorrentID string `json:"torrent_id"`
	Title     string `json:"title"`
	SizeBytes int64  `json:"size_bytes"`
	Result    string `json:"result"`
	Reason    string `json:"reason,omitempty"`
	Message   string `json:"message,omitempty"`
	// ID 是新记录的编号;exists 时是已有的那条
	ID uint `json:"id,omitempty"`
	// Replaces 是这一条要换掉的旧记录(只有搜索订阅会有,#935 P3)
	Replaces uint `json:"replaces,omitempty"`
}

BatchItemResult 是一条的结果:created(登记了)、would_create(试算:会登记)或 skipped(跳过,Reason 写原因)。

type BatchResult added in v1.3.0

type BatchResult struct {
	DryRun bool `json:"dry_run"`
	Total  int  `json:"total"`
	// Created 是登记了几条(试算时是会登记几条)
	Created int            `json:"created"`
	Skipped map[string]int `json:"skipped"`
	// TotalSizeBytes 是登记(或会登记)的合计体积;UnknownSize 是其中体积不明的个数
	TotalSizeBytes int64 `json:"total_size_bytes"`
	UnknownSize    int   `json:"unknown_size"`
	// Watching 是登记以后在等的条数(试算时是登记以前);Limit 是最多同时在等几条
	Watching int64             `json:"watching"`
	Limit    int               `json:"limit"`
	Items    []BatchItemResult `json:"items"`
}

BatchResult 是一次批量登记的汇总。试算与正式登记用同一段判断:没有并发改动时两次的汇总相同。

type BatchTarget added in v1.3.0

type BatchTarget struct {
	DownloaderID uint   `json:"downloader_id"`
	SavePath     string `json:"save_path"`
	Category     string `json:"category"`
	Tags         string `json:"tags"`
	// Days 是等多久(1 到设置里的最长天数,默认 30;0 是 7 天,最长天数小于 7 时是最长天数)
	Days int `json:"days"`
}

BatchTarget 是一批种子推到哪里、等多久(同单条登记)。

type Config

type Config struct {
	DB *gorm.DB
	// Site 是注册了、启用着的站点;没有时为 nil
	Site func(name string) v2.Site
	// Fresh 读种子现在的优惠(生产是 internal.FreshPromotion),读不到时返回 nil
	Fresh func(ctx context.Context, site v2.Site, siteName, torrentID string, attemptStart time.Time) *v2.PromotionSnapshot
	// Push 推送(生产是 internal.PushTorrentToDownloader)
	Push func(ctx context.Context, req ptinternal.PushTorrentRequest) (*ptinternal.PushTorrentResult, error)
	// Notify 发通知;为空时不发
	Notify func(ctx context.Context, m Message)
	// SafetyMargin 是免费剩余时间至少要有多少(为空时用 internal.DefaultSafetyMargin)
	SafetyMargin func() time.Duration
	// HR 是批量登记时站点级的 H&R(为空时按站点定义与站点设置算,同 App 推送)
	HR HRFunc
	// Tick 是后台多久跑一轮(为空时是 DefaultTick),每轮每站的读取配额按它摊开每小时上限
	Tick time.Duration
	// Jitter 返回 [0, limit) 里的一个时长,复查间隔加抖动用(为空时随机)
	Jitter func(limit time.Duration) time.Duration
	// Present 报告这些哈希(小写)里哪些已经在下载器里(检查前的本地判断用,为空时不查)
	Present func(ctx context.Context, downloaderID uint, hashes []string) (map[string]bool, error)
	// Search 是搜索订阅用的多站点搜索(生产是带缓存的搜索编排器,#935 P3);为空时搜索订阅报错不跑
	Search func(ctx context.Context, q v2.MultiSiteSearchQuery) (*v2.MultiSiteSearchResult, error)
	// ReseedState 是推送改为辅种以后辅种现在的情况(#933,生产是 internal.PushReseedStateOf)
	ReseedState func(ctx context.Context, k ptinternal.PushReseedKey) ptinternal.PushReseedState
	Now         func() time.Time
	Logger      *zap.SugaredLogger
}

Config 是等免费的依赖,测试里都换成假的。

type Counts

type Counts map[string]int64

Counts 是各状态的条数。

type CreateInput

type CreateInput struct {
	Site         string `json:"site"`
	TorrentID    string `json:"torrent_id"`
	Title        string `json:"title"`
	Subtitle     string `json:"subtitle"`
	SizeBytes    int64  `json:"size_bytes"`
	HasHR        bool   `json:"has_hr"`
	HRSeedTimeH  int    `json:"hr_seed_time_h"`
	DownloaderID uint   `json:"downloader_id"`
	SavePath     string `json:"save_path"`
	Category     string `json:"category"`
	Tags         string `json:"tags"`
	// MediaType、TMDBID、Season 是按条目搜索里带上的条目(可选)
	MediaType string `json:"media_type"`
	TMDBID    int    `json:"tmdb_id"`
	Season    int    `json:"season"`
	// Days 是等多久(1 到设置里的最长天数,默认 30、最多 365;0 是设置里的默认等待天数,默认 7)
	Days int `json:"days"`
}

CreateInput 是新建一条等免费:要推的种子、推到哪里(同推送弹窗)、等多久。

type FunnelCounts added in v1.3.0

type FunnelCounts struct {
	Registered int `json:"registered"`
	// BecameFree 是登记以后读到过免费的(P2 以前的记录没有记,统计从升级以后才完整)
	BecameFree int `json:"became_free"`
	Pushed     int `json:"pushed"`
	Duplicate  int `json:"duplicate"`
	Elsewhere  int `json:"elsewhere"`
	Expired    int `json:"expired"`
	Canceled   int `json:"canceled"`
	Blocked    int `json:"blocked"`
	Failed     int `json:"failed"`
	// Replaced 是被搜索订阅换成新版本的(#935 P3)
	Replaced int `json:"replaced"`
	Watching int `json:"watching"`
}

FunnelCounts 是一组记录后来怎样了(#935 P2)。

type HRFunc added in v1.3.0

type HRFunc func(site string, sizeBytes int64) (siteHR bool, hours int)

HRFunc 给出站点级的 H&R:站点定义开了 H&R 时为真,hours 是这个体积的做种要求(未知时为 0)。

type Message

type Message struct {
	Kind  string
	Watch models.FreeWatch
	// Downloader 是推送到的下载器名字(推送了时)
	Downloader string
	// Snapshot 是推送时读到的优惠(推送了时)
	Snapshot *v2.PromotionSnapshot
	// PushError 是推送时下载器报了错、种子其实加进去了(推送了时,见 ownPushPending):种子可能还暂停着
	PushError bool
	// Error 是最近一次读不到的原因(不再等时)
	Error string
	// Round 是一轮的汇总(KindRound 时)
	Round *Round
}

Message 是要发的一条通知:推送了、到期了、读不到不再等,或者一轮的汇总。Event 由 Notice 生成。

type PageResult added in v1.3.0

type PageResult struct {
	Items  []models.FreeWatch
	Total  int64
	Counts Counts
}

PageResult 是一页记录、合计条数与各状态的条数(各状态的条数不受筛选影响)。

type Query added in v1.3.0

type Query struct {
	Status, Source, Site, TorrentID, Keyword string
	// SearchID 不为 0 时只列这条搜索订阅登记的(#935 P3)
	SearchID      uint
	Limit, Offset int
}

Query 是分页列出等免费的条件。Status、Source 为空时不筛;Source 是 manual 时也认以前空串的记录; Site 不分大小写;Keyword 在标题里找(最多 100 个字)。

type Range added in v1.3.0

type Range [2]int

Range 是一项设置能填的范围(含两端)。

type Round added in v1.3.0

type Round struct {
	// Start 是这一轮开始的时间(通知去重用,同一秒里可能有两轮)
	Start   time.Time
	Expired []models.FreeWatch
	Failed  []RoundFailure
}

Round 是一轮里批量、接口登记的种子的到期与不再等(手动登记的仍然逐条通知)。

type RoundFailure added in v1.3.0

type RoundFailure struct {
	Watch models.FreeWatch
	Error string
}

RoundFailure 是一轮里不再等的一条与最近一次的原因。

type SearchInput added in v1.3.0

type SearchInput struct {
	Name            string           `json:"name"`
	Enabled         bool             `json:"enabled"`
	SiteName        string           `json:"site_name"`
	Keyword         string           `json:"keyword"`
	Section         string           `json:"section"`
	SiteFilters     v2.SearchFilters `json:"-"`
	MinSizeBytes    int64            `json:"min_size_bytes"`
	MaxSizeBytes    int64            `json:"max_size_bytes"`
	WithinDays      int              `json:"within_days"`
	MatchType       string           `json:"match_type"`
	MatchPattern    string           `json:"match_pattern"`
	MatchField      string           `json:"match_field"`
	ExcludePattern  string           `json:"exclude_pattern"`
	WorkKeyPattern  string           `json:"work_key_pattern"`
	KeepPolicy      string           `json:"keep_policy"`
	MaxPerRun       int              `json:"max_per_run"`
	IntervalMinutes int              `json:"interval_minutes"`
	DownloaderID    uint             `json:"downloader_id"`
	SavePath        string           `json:"save_path"`
	Category        string           `json:"category"`
	Tags            string           `json:"tags"`
	Days            int              `json:"days"`
}

SearchInput 是新建或整份保存一条搜索订阅。SiteFilters 由接口层按站点的分类配置校验、规整,只属于这个站点。

type SearchRow added in v1.3.0

type SearchRow struct {
	models.FreeWatchSearch
	SiteFilters v2.SearchFilters `json:"site_filters"`
	Watching    int64            `json:"watching"`
	Pushed      int64            `json:"pushed"`
}

SearchRow 是列表里的一条搜索订阅:表里的字段、这个站点的分类筛选与它登记的在等、已推送的条数。

type SearchRun added in v1.3.0

type SearchRun struct {
	DryRun bool `json:"dry_run"`
	// Found 是搜到几条(这个站点的);Matched 是本地对上几条;Groups 是分成几个作品(没有作品键的各算一个)
	Found   int `json:"found"`
	Matched int `json:"matched"`
	Groups  int `json:"groups"`
	// Created、Replaced 是新登记、替换了几条(试运行时是会);Hinted 是在等的里提前检查的
	Created  int             `json:"created"`
	Replaced int             `json:"replaced"`
	Hinted   int             `json:"hinted"`
	Skipped  map[string]int  `json:"skipped"`
	Items    []SearchRunItem `json:"items"`
	Error    string          `json:"error,omitempty"`
}

SearchRun 是一次搜索订阅的运行结果(试运行时返回,正式运行只存 last_result)。

func (*SearchRun) Summary added in v1.3.0

func (r *SearchRun) Summary() string

Summary 是写进 last_result 的一句话:「跳过」只数对上了、没登记的,本地没对上的另写。按总数算(Items 最多列 200 条): 每条结果不是本地没对上,就是对上了;对上的最后是新登记、替换或者跳过。

type SearchRunItem added in v1.3.0

type SearchRunItem struct {
	TorrentID   string `json:"torrent_id"`
	Title       string `json:"title"`
	SizeBytes   int64  `json:"size_bytes"`
	Discount    string `json:"discount"`
	Free        bool   `json:"free"`
	PublishedAt int64  `json:"published_at,omitempty"`
	WorkKey     string `json:"work_key,omitempty"`
	Result      string `json:"result"`
	Reason      string `json:"reason,omitempty"`
	Message     string `json:"message,omitempty"`
	ReplacesID  uint   `json:"replaces_id,omitempty"`
	// ID 是登记的新记录(正式运行时)
	ID uint `json:"id,omitempty"`
}

SearchRunItem 是一条搜索结果的去向。

type Service

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

Service 管理等免费的记录并做定时检查。

func New

func New(cfg Config) *Service

New 建服务。

func (*Service) Cancel

func (s *Service) Cancel(ctx context.Context, id uint) (*models.FreeWatch, error)

Cancel 取消一条在等的。

func (*Service) CancelWithReason added in v1.3.0

func (s *Service) CancelWithReason(ctx context.Context, id uint, reason string) (*models.FreeWatch, error)

CancelWithReason 取消一条在等的;reason 最多 100 个字,写进说明(「取消了:已入库」)。没有这条返回 ErrNotFound, 已经不在等了返回 ErrNotWatching。

func (*Service) Create

func (s *Service) Create(ctx context.Context, in CreateInput) (*models.FreeWatch, error)

Create 新建一条等免费,建好以后马上可以检查(NextCheckAt 是现在)。站点要能读种子详情,下载器要存在并启用; 同一个种子已经在等时报错;在等的最多是设置里的条数(见 Settings)。

func (*Service) CreateBatch added in v1.3.0

func (s *Service) CreateBatch(ctx context.Context, in BatchInput) (*BatchResult, error)

CreateBatch 批量登记等免费:逐条判断能不能登记(见 Skip* 的顺序),试算时只给结果,正式登记在一个事务里写入 (出错整批都不写)。整个请求不对(没有条目、超过 MaxBatchItems 条、下载器不对、天数越界)时返回 ErrInvalid。

func (*Service) CreateSearch added in v1.3.0

func (s *Service) CreateSearch(ctx context.Context, in SearchInput) (*models.FreeWatchSearch, error)

CreateSearch 新建一条搜索订阅;启用着的下一轮就跑。最多 MaxSearches 条。

func (*Service) DeleteSearch added in v1.3.0

func (s *Service) DeleteSearch(ctx context.Context, id uint, cancelWatching bool) (int64, error)

DeleteSearch 删除一条搜索订阅;cancelWatching 为真时一起取消它登记、还在等的记录(原因写「搜索订阅删掉了」),返回取消了几条。 它登记的记录都留着(来源仍是 search),以后再搜到同一个种子也不重新登记。

func (*Service) GetSearch added in v1.3.0

func (s *Service) GetSearch(ctx context.Context, id uint) (*models.FreeWatchSearch, error)

GetSearch 读一条搜索订阅。

func (*Service) ListSearches added in v1.3.0

func (s *Service) ListSearches(ctx context.Context) ([]SearchRow, error)

ListSearches 列出全部搜索订阅(新建的在前),带每条登记的在等、已推送的条数。

func (*Service) Page added in v1.3.0

func (s *Service) Page(ctx context.Context, q Query) (*PageResult, error)

Page 分页列出等免费的记录,新建的在前。

func (*Service) PreviewSearch added in v1.3.0

func (s *Service) PreviewSearch(ctx context.Context, in SearchInput, id uint) (*SearchRun, error)

PreviewSearch 按还没保存的表单试运行一次(不写库、不提前检查)。id 是编辑的那条(新建时为 0):带上才能算出「替换」。 这次搜索计入用量,但不受每小时上限限制(同网页搜索)。

func (*Service) RunOnce

func (s *Service) RunOnce(ctx context.Context) int

RunOnce 做一轮(#935 P2):先把到期的记成过期,再按站点取到点的记录,各站点轮流检查,每个站点读详情的次数不超过 这一轮的配额:每小时上限按轮次摊开的切片(默认每轮 10 次),和这一整点还剩的取小。站点里先查搜索结果看到免费的, 再查 24 小时内到期的(到期早的先),其余按下次检查时间。读详情以前先用本地记录判断(拉黑、推送过、下载器里已有), 这些不花配额。批量、接口登记的到期与不再等这一轮合成一条通知。返回读了几次详情。

func (*Service) RunSearchNow added in v1.3.0

func (s *Service) RunSearchNow(ctx context.Context, id uint) (time.Time, error)

RunSearchNow 让一条启用着的搜索订阅在下一轮就跑(调用方随后让后台马上跑一轮),返回排上的时间。

func (*Service) SaveSettings added in v1.3.0

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

SaveSettings 改等免费的设置,返回改好以后的样子。越界时返回 ErrInvalid。改小在等的条数、最长天数不影响已有的记录。 默认等待天数不能超过最长等待天数:一起带了、比它大时报错;只把最长天数改小时,默认天数跟着改成最长天数。

func (*Service) SetExpiry

func (s *Service) SetExpiry(ctx context.Context, id uint, at time.Time) (*models.FreeWatch, error)

SetExpiry 改一条在等的到期时间:要晚于现在,最多是现在起设置里的最长天数。

func (*Service) Settings added in v1.3.0

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

Settings 读等免费的设置:没有设置、某一项是 0 时用默认值;读不出来时也用默认值(记日志),不挡登记与检查。

func (*Service) Stats added in v1.3.0

func (s *Service) Stats(ctx context.Context, days int) (*Stats, error)

Stats 算最近 days 天(按登记时间)登记的记录的转化,以及最近 24 小时的请求用量。days 只能是 7、30、90。

func (*Service) StatusCounts added in v1.3.0

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

StatusCounts 是各状态的条数。

func (*Service) Supports

func (s *Service) Supports(name string) bool

Supports 报告这个站点能不能等免费:注册了、启用着,而且能读种子详情(读优惠要用)。

func (*Service) Tick added in v1.3.0

func (s *Service) Tick() time.Duration

Tick 是后台多久跑一轮。

func (*Service) UpdateSearch added in v1.3.0

func (s *Service) UpdateSearch(ctx context.Context, id uint, in SearchInput) (*models.FreeWatchSearch, error)

UpdateSearch 整份保存一条搜索订阅。从关到开时下一轮就跑;关掉时不再排下次运行。运行状态(上次结果、失败次数)保留。

type Settings added in v1.3.0

type Settings struct {
	MaxWatching int `json:"max_watching"`
	MaxDays     int `json:"max_days"`
	// DefaultWaitDays 是登记时不填天数用几天(不超过 MaxDays,见 DefaultDays)
	DefaultWaitDays    int `json:"default_days"`
	SiteHourlyRequests int `json:"site_hourly_requests"`
	RecheckMinutes     int `json:"recheck_minutes"`
}

Settings 是等免费现在的设置(没有改过的项是默认值)。

func DefaultSettings added in v1.3.0

func DefaultSettings() Settings

DefaultSettings 是没有改过时的设置。

func (Settings) DefaultDays added in v1.3.0

func (st Settings) DefaultDays() int

DefaultDays 是新建时不填天数用几天:设置里的默认等待天数(没设时 7 天),不超过最长天数。

func (Settings) Recheck added in v1.3.0

func (st Settings) Recheck() time.Duration

Recheck 是还没免费时隔多久再看(抖动以前)。

func (Settings) RoundSlice added in v1.3.0

func (st Settings) RoundSlice(tick time.Duration) int

RoundSlice 是每一轮每个站点最多读几次详情:每小时上限按轮次摊开(向上取整),tick 是一轮的间隔。

type SettingsUpdate added in v1.3.0

type SettingsUpdate struct {
	MaxWatching        *int `json:"max_watching"`
	MaxDays            *int `json:"max_days"`
	DefaultDays        *int `json:"default_days"`
	SiteHourlyRequests *int `json:"site_hourly_requests"`
	RecheckMinutes     *int `json:"recheck_minutes"`
}

SettingsUpdate 是改设置:只改带了的项。

type SiteStats added in v1.3.0

type SiteStats struct {
	Site             string `json:"site"`
	Registered       int    `json:"registered"`
	BecameFree       int    `json:"became_free"`
	Pushed           int    `json:"pushed"`
	RequestsThisHour int    `json:"requests_this_hour"`
	Requests24h      int    `json:"requests_24h"`
}

SiteStats 是一个站点的转化与请求:RequestsThisHour 是这一小时(从整点起)读详情与搜索的次数(受每小时上限限制), Requests24h 是最近 24 小时的全部请求(含下种子)。

type SourceStats added in v1.3.0

type SourceStats struct {
	Source     string `json:"source"`
	Registered int    `json:"registered"`
	BecameFree int    `json:"became_free"`
	Pushed     int    `json:"pushed"`
}

SourceStats 是一种登记来源的转化。

type Stats added in v1.3.0

type Stats struct {
	Days    int           `json:"days"`
	Total   FunnelCounts  `json:"total"`
	Sources []SourceStats `json:"sources"`
	Sites   []SiteStats   `json:"sites"`
	// WaitHoursMedian 是从登记到第一次读到免费的小时数的中位数(没有变免费的时为 0)
	WaitHoursMedian    float64    `json:"wait_hours_median"`
	SiteHourlyRequests int        `json:"site_hourly_requests"`
	Usage              []UsageRow `json:"usage"`
}

Stats 是最近几天登记的等免费后来怎样了,以及各站点的请求用量。

type UsageRow added in v1.3.0

type UsageRow struct {
	Site      string `json:"site"`
	Hour      int64  `json:"hour"`
	Reads     int    `json:"reads"`
	Downloads int    `json:"downloads"`
	Searches  int    `json:"searches"`
}

UsageRow 是用量表的一行。

Jump to

Keyboard shortcuts

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