Documentation
¶
Index ¶
- Constants
- func FetchAndDownloadFreeRSS[T models.ResType](ctx context.Context, siteName models.SiteGroup, m PTSiteInter[T], ...) error
- func FetchAndDownloadFreeRSSUnified(ctx context.Context, m UnifiedPTSite, rssCfg models.RSSConfig) error
- func GetAllSupportedSiteGroups() []models.SiteGroup
- func GetDownloaderForRSS(rssCfg models.RSSConfig) (downloader.Downloader, error)
- func GetGlobalDownloaderManager() *downloader.DownloaderManager
- func IsSiteGroupSupported(siteGroup models.SiteGroup) bool
- func ProcessTorrentsWithDBUpdate(ctx context.Context, qbitClient *qbit.QbitClient, ...) error
- func ProcessTorrentsWithDownloaderByRSS(ctx context.Context, rssCfg models.RSSConfig, dirPath, category, tags string, ...) error
- func PushMutex() *sync.Mutex
- func RegisterTorrentScheduler(f TorrentScheduleFunc)
- func ScheduleTorrentForMonitoring(torrent models.TorrentInfo)
- func SetGlobalDownloaderManager(dm *downloader.DownloaderManager)
- func SetRSSNotifier(n RSSNotifier)
- type DiskBudget
- type DownloaderInfo
- type PTSiteInter
- type PushTorrentRequest
- type PushTorrentResult
- type RSSFilteredNotice
- type RSSItemNotice
- type RSSNotifier
- type TorrentDetailForTest
- type TorrentScheduleFunc
- type UnifiedPTSite
- type UnifiedSiteImpl
- func (u *UnifiedSiteImpl) Context() context.Context
- func (u *UnifiedSiteImpl) DownloadTorrent(url, title, downloadDir string) (string, error)
- func (u *UnifiedSiteImpl) GetTorrentDetails(item *gofeed.Item) (*v2.TorrentItem, error)
- func (u *UnifiedSiteImpl) IsEnabled() bool
- func (u *UnifiedSiteImpl) MaxRetries() int
- func (u *UnifiedSiteImpl) RetryDelay() time.Duration
- func (u *UnifiedSiteImpl) SendTorrentToDownloader(ctx context.Context, rssCfg models.RSSConfig) error
- func (u *UnifiedSiteImpl) SiteGroup() models.SiteGroup
Constants ¶
const SkipRecheckHours = 6
SkipRecheckHours defines how long a skipped non-free torrent should remain skipped before re-checking This allows torrents marked as non-free to be re-checked after becoming free during promotions
Variables ¶
This section is empty.
Functions ¶
func FetchAndDownloadFreeRSS ¶
func FetchAndDownloadFreeRSS[T models.ResType](ctx context.Context, siteName models.SiteGroup, m PTSiteInter[T], rssCfg models.RSSConfig) error
FetchAndDownloadFreeRSS 旧的泛型版本(已废弃,请使用 FetchAndDownloadFreeRSSUnified) Deprecated: Use FetchAndDownloadFreeRSSUnified instead for new implementations
func FetchAndDownloadFreeRSSUnified ¶ added in v0.2.0
func FetchAndDownloadFreeRSSUnified(ctx context.Context, m UnifiedPTSite, rssCfg models.RSSConfig) error
FetchAndDownloadFreeRSSUnified 使用 UnifiedPTSite 接口获取并下载免费 RSS 种子
func GetAllSupportedSiteGroups ¶ added in v0.2.0
func GetDownloaderForRSS ¶ added in v0.2.0
func GetDownloaderForRSS(rssCfg models.RSSConfig) (downloader.Downloader, error)
GetDownloaderForRSS 根据 RSS 配置获取下载器 优先级:RSS 指定的下载器 > 默认下载器 返回下载器实例和下载器信息
func GetGlobalDownloaderManager ¶ added in v0.6.0
func GetGlobalDownloaderManager() *downloader.DownloaderManager
func IsSiteGroupSupported ¶ added in v0.2.0
func ProcessTorrentsWithDownloaderByRSS ¶ added in v0.2.0
func ProcessTorrentsWithDownloaderByRSS( ctx context.Context, rssCfg models.RSSConfig, dirPath, category, tags string, siteName models.SiteGroup, ) error
ProcessTorrentsWithDownloaderByRSS 根据 RSS 配置选择下载器并处理种子
func PushMutex ¶ added in v0.28.1
PushMutex 返回全局推送互斥锁。调用方应在 disk-check 前 Lock, 推送结束后 Unlock。注意:锁的范围是单实例进程级,多实例部署需要外部协调。
func RegisterTorrentScheduler ¶ added in v0.3.0
func RegisterTorrentScheduler(f TorrentScheduleFunc)
func ScheduleTorrentForMonitoring ¶ added in v0.3.0
func ScheduleTorrentForMonitoring(torrent models.TorrentInfo)
func SetGlobalDownloaderManager ¶ added in v0.6.0
func SetGlobalDownloaderManager(dm *downloader.DownloaderManager)
func SetRSSNotifier ¶ added in v0.31.0
func SetRSSNotifier(n RSSNotifier)
Types ¶
type DiskBudget ¶ added in v0.18.0
type DiskBudget struct {
// contains filtered or unexported fields
}
DiskBudget 跟踪已预留但尚未落盘的磁盘空间。
多个并发 RSS worker 推送前先 Reserve,防止它们同时观察到相同的 OS 空闲空间 而并发越界(Issue #299 根因之一)。Reserve/Release 使用原子计数 + 修正循环 保证不会下溢到负数。
典型用法:
budget := internal.GetDiskBudget()
if budget.EffectiveFreeGB(rawFreeBytes)-torrentSizeGB < threshold {
return ErrInsufficientSpace
}
budget.Reserve(torrentSize)
if pushErr != nil {
budget.Release(torrentSize) // 推送失败时归还配额
}
// 推送成功的预留由 cleanup_monitor 周期 Reset,或上层在 qBit 已可见后调
// Release(避免与 GetIncompletePendingBytes 双重计数)。
func (*DiskBudget) EffectiveFreeBytes ¶ added in v0.28.1
func (b *DiskBudget) EffectiveFreeBytes(actualFreeBytes int64) int64
EffectiveFreeBytes 同 EffectiveFreeGB 但返回字节数。供下游做更精细比较。
func (*DiskBudget) EffectiveFreeGB ¶ added in v0.18.0
func (b *DiskBudget) EffectiveFreeGB(actualFreeBytes int64) float64
EffectiveFreeGB 计算"扣除已预留后"的有效可用空间(GB)。 actualFreeBytes 通常来自 downloader.GetClientFreeSpace。下溢钳位为 0。
func (*DiskBudget) Release ¶ added in v0.18.0
func (b *DiskBudget) Release(bytes int64)
Release 释放指定字节数(推送失败 / 已被下游可见时调用)。
实现细节:原始版本用 Add(-bytes) + CAS(newVal, 0),但若并发 Reserve 在 Add 与 CAS 之间发生,CAS 会失败保留负值,污染后续 Reserved() 读取。 此版本用 CompareAndSwap 循环 ——每次基于最新值计算 desired,确保最终 不会下溢到 < 0。
func (*DiskBudget) Reserve ¶ added in v0.18.0
func (b *DiskBudget) Reserve(bytes int64) int64
Reserve 预留指定字节数。bytes <= 0 视为 no-op。返回预留后的总已预留字节数。
func (*DiskBudget) Reserved ¶ added in v0.18.0
func (b *DiskBudget) Reserved() int64
Reserved 返回当前已预留的字节数。下溢的负值会被规范化为 0。
func (*DiskBudget) Reset ¶ added in v0.18.0
func (b *DiskBudget) Reset()
Reset 重置预留计数(清理监控周期开始时调用以重新校准)。
type DownloaderInfo ¶ added in v0.3.0
GetDownloaderForRSS 根据 RSS 配置获取下载器 DownloaderInfo 下载器附加信息,用于记录推送来源
func GetDownloaderForRSSWithInfo ¶ added in v0.3.0
func GetDownloaderForRSSWithInfo(rssCfg models.RSSConfig) (downloader.Downloader, *DownloaderInfo, error)
GetDownloaderForRSSWithInfo 根据 RSS 配置获取下载器及其信息 优先使用全局 DownloaderManager(连接池复用),回退到直接创建实例
type PTSiteInter ¶
type PTSiteInter[T models.ResType] interface { GetTorrentDetails(item *gofeed.Item) (*models.APIResponse[T], error) IsEnabled() bool DownloadTorrent(url, title, downloadDir string) (string, error) MaxRetries() int RetryDelay() time.Duration SendTorrentToDownloader(ctx context.Context, rssCfg models.RSSConfig) error Context() context.Context }
PTSiteInter 旧的泛型接口(已废弃,请使用 UnifiedPTSite) Deprecated: Use UnifiedPTSite instead for new implementations
type PushTorrentRequest ¶ added in v0.2.0
type PushTorrentRequest struct {
SiteID string // 站点ID (如 hdsky, mteam)
TorrentID string // 种子ID
TorrentData []byte // 种子文件数据
Title string // 种子标题
Category string // 分类
Tags string // 标签
SavePath string // 保存路径(可选)
DownloaderID uint // 下载器ID
}
PushTorrentRequest 推送种子请求参数
type PushTorrentResult ¶ added in v0.2.0
type PushTorrentResult struct {
Success bool
Skipped bool // 是否跳过(如已存在)
TorrentHash string
Message string
}
PushTorrentResult 推送种子结果
func PushTorrentToDownloader ¶ added in v0.2.0
func PushTorrentToDownloader(ctx context.Context, req PushTorrentRequest) (*PushTorrentResult, error)
PushTorrentToDownloader 将种子推送到下载器 复用现有的下载和推送逻辑,同时记录到数据库
type RSSFilteredNotice ¶ added in v0.31.0
type RSSFilteredNotice struct {
RSS *models.RSSConfig
Torrent *v2.TorrentItem
Rule *models.FilterRule
SiteName string
TorrentID string
}
RSSFilteredNotice is the payload for the 'filtered' RSS notification path. Mirror of app.RSSFilteredEvent but defined here to avoid the internal → internal/app import cycle. Bridged by rssNotifierAdapter in cmd/web.go.
type RSSItemNotice ¶ added in v0.31.0
type RSSItemNotice struct {
RSS *models.RSSConfig
FeedItem *gofeed.Item
SiteName string
TorrentID string
}
RSSItemNotice is the minimal payload the RSS pipeline needs to fire an "all" notification — purposely dependency-light so internal does not import internal/app (which would create a cycle via scheduler).
type RSSNotifier ¶ added in v0.31.0
type RSSNotifier interface {
NotifyNewItem(ctx context.Context, ev RSSItemNotice) error
NotifyFilteredItem(ctx context.Context, ev RSSFilteredNotice) error
}
RSSNotifier is the structural contract internal/app/rssNotifier satisfies. The concrete adapter lives in cmd/web.go and bridges this minimal type to app.RSSItemEvent before delegating to the real app.RSSNotifier.
type TorrentDetailForTest ¶ added in v0.2.0
type TorrentDetailForTest struct {
Title string // 种子标题(优先使用中文名)
Tag string // 种子标签/副标题
IsFree bool // 是否免费
}
TorrentDetailForTest 用于测试的种子详情
func GetTorrentDetailForTest ¶ added in v0.2.0
func GetTorrentDetailForTest(ctx context.Context, siteName models.SiteGroup, item *gofeed.Item) (*TorrentDetailForTest, error)
GetTorrentDetailForTest 获取种子详情用于过滤规则测试 根据站点类型调用对应的 API 获取完整的种子信息
type TorrentScheduleFunc ¶ added in v0.3.0
type TorrentScheduleFunc func(torrent models.TorrentInfo)
type UnifiedPTSite ¶ added in v0.2.0
type UnifiedPTSite interface {
// GetTorrentDetails 获取种子详情,返回统一的 TorrentItem
GetTorrentDetails(item *gofeed.Item) (*v2.TorrentItem, error)
// IsEnabled 检查站点是否启用
IsEnabled() bool
// DownloadTorrent 下载种子文件,返回 torrent hash
DownloadTorrent(url, title, downloadDir string) (string, error)
// MaxRetries 返回最大重试次数
MaxRetries() int
// RetryDelay 返回重试间隔
RetryDelay() time.Duration
// SendTorrentToDownloader 发送种子到下载器
SendTorrentToDownloader(ctx context.Context, rssCfg models.RSSConfig) error
// Context 返回上下文
Context() context.Context
// SiteGroup 返回站点分组标识
SiteGroup() models.SiteGroup
}
UnifiedPTSite 统一的 PT 站点接口(非泛型) 新增站点应使用此接口,无需创建新的实现类
type UnifiedSiteImpl ¶ added in v0.2.0
type UnifiedSiteImpl struct {
// contains filtered or unexported fields
}
UnifiedSiteImpl 统一站点实现 使用 site/v2 的 Driver 模式,无需为每个站点创建单独的实现
func NewUnifiedSiteImpl ¶ added in v0.2.0
func (*UnifiedSiteImpl) Context ¶ added in v0.2.0
func (u *UnifiedSiteImpl) Context() context.Context
Context 返回上下文
func (*UnifiedSiteImpl) DownloadTorrent ¶ added in v0.2.0
func (u *UnifiedSiteImpl) DownloadTorrent(url, title, downloadDir string) (string, error)
DownloadTorrent 下载种子文件,返回 torrent hash
func (*UnifiedSiteImpl) GetTorrentDetails ¶ added in v0.2.0
func (u *UnifiedSiteImpl) GetTorrentDetails(item *gofeed.Item) (*v2.TorrentItem, error)
GetTorrentDetails 获取种子详情,返回统一的 TorrentItem
func (*UnifiedSiteImpl) IsEnabled ¶ added in v0.2.0
func (u *UnifiedSiteImpl) IsEnabled() bool
IsEnabled 检查站点是否启用
func (*UnifiedSiteImpl) MaxRetries ¶ added in v0.2.0
func (u *UnifiedSiteImpl) MaxRetries() int
MaxRetries 返回最大重试次数
func (*UnifiedSiteImpl) RetryDelay ¶ added in v0.2.0
func (u *UnifiedSiteImpl) RetryDelay() time.Duration
RetryDelay 返回重试间隔
func (*UnifiedSiteImpl) SendTorrentToDownloader ¶ added in v0.6.0
func (u *UnifiedSiteImpl) SendTorrentToDownloader(ctx context.Context, rssCfg models.RSSConfig) error
SendTorrentToDownloader 发送种子到下载器
func (*UnifiedSiteImpl) SiteGroup ¶ added in v0.2.0
func (u *UnifiedSiteImpl) SiteGroup() models.SiteGroup
SiteGroup 返回站点分组标识
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package filter provides pattern matching and filtering functionality for RSS items.
|
Package filter provides pattern matching and filtering functionality for RSS items. |
|
Package mcp documents the future MCP (Model Context Protocol) Server interface contract for pt-tools.
|
Package mcp documents the future MCP (Model Context Protocol) Server interface contract for pt-tools. |
|
adapter/telegram
Package telegram implements the notify.Channel adapter for Telegram bots using mymmrac/telego with long-polling.
|
Package telegram implements the notify.Channel adapter for Telegram bots using mymmrac/telego with long-polling. |