freewatch

package
v1.0.0-rc.53 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package freewatch 是「等免费再下」(媒体中心 M2b):记下一个现在不免费的种子要推到哪里,后台定时读它现在的优惠, 免费了才推送(照常过免费门禁、磁盘与站点容量闸门,免费结束时暂停),等到期了还没免费就放弃。

Index

Constants

View Source
const (
	// MaxWatching 是同时在等的最多几条
	MaxWatching = 200
	// DefaultDays、MaxDays 是等多久(天)的默认值与上限
	DefaultDays = 7
	MaxDays     = 30
	// PerSiteRound 是每一轮每个站点最多读几个种子(不给站点添负担)
	PerSiteRound = 10
	// NotFreeRetry 是还没免费(或者免费剩得太少、闸门没放行)时隔多久再看
	NotFreeRetry = 30 * time.Minute
	// MaxFailures 是连续读不到几次以后不再等
	MaxFailures = 5

	// ListLimit 是列表最多列几条(新建的在前);各状态的条数照实数
	ListLimit = 500
)
View Source
const (
	KindPushed  = "pushed"
	KindExpired = "expired"
	KindFailed  = "failed"
)

通知的种类(Message.Kind)。

Variables

View Source
var (
	ErrInvalid  = errors.New("参数不对")
	ErrNotFound = errors.New("没有这条记录")
)

Functions

func Notice

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

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

Types

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
	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 天,0 是 7 天)
	Days int `json:"days"`
}

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

type Message

type Message struct {
	Kind  string
	Watch models.FreeWatch
	// Downloader 是推送到的下载器名字(推送了时)
	Downloader string
	// Snapshot 是推送时读到的优惠(推送了时)
	Snapshot *v2.PromotionSnapshot
	// Error 是最近一次读不到的原因(不再等时)
	Error string
}

Message 是要发的一条通知:推送了、到期了、读不到不再等。Event 由 NoticeEvent 生成。

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) Create

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

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

func (*Service) List

func (s *Service) List(ctx context.Context, status string) ([]models.FreeWatch, Counts, error)

List 列出等免费的记录(status 为空时全部),新建的在前,并给出各状态的条数。

func (*Service) RunOnce

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

RunOnce 做一轮检查:先把到期的记成过期,再按下次检查时间取到点的,每个站点最多 PerSiteRound 个。返回读了几个种子。

func (*Service) SetExpiry

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

SetExpiry 改一条在等的到期时间:要晚于现在,最多是现在起 MaxDays 天。

func (*Service) Supports

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

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

Jump to

Keyboard shortcuts

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