Documentation
¶
Overview ¶
Package freewatch 是「等免费再下」(媒体中心 M2b):记下一个现在不免费的种子要推到哪里,后台定时读它现在的优惠, 免费了才推送(照常过免费门禁、磁盘与站点容量闸门,免费结束时暂停),等到期了还没免费就放弃。
Index ¶
- Constants
- Variables
- func Notice(m Message, now time.Time) (title, text string, ev *notify.Event)
- type Config
- type Counts
- type CreateInput
- type Message
- type Service
- func (s *Service) Cancel(ctx context.Context, id uint) (*models.FreeWatch, error)
- func (s *Service) Create(ctx context.Context, in CreateInput) (*models.FreeWatch, error)
- func (s *Service) List(ctx context.Context, status string) ([]models.FreeWatch, Counts, error)
- func (s *Service) RunOnce(ctx context.Context) int
- func (s *Service) SetExpiry(ctx context.Context, id uint, at time.Time) (*models.FreeWatch, error)
- func (s *Service) Supports(name string) bool
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 ¶
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 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 (*Service) Create ¶
Create 新建一条等免费,建好以后马上可以检查(NextCheckAt 是现在)。站点要能读种子详情,下载器要存在并启用; 同一个种子已经在等时报错;在等的最多 MaxWatching 条。
Click to show internal directories.
Click to hide internal directories.