Documentation
¶
Overview ¶
Package internal provides site compatibility types and functions These were moved from the deprecated site package to support existing functionality
Index ¶
- Variables
- func CommonFetchTorrentInfo(ctx context.Context, c *colly.Collector, cfg *SiteMapConfig, url string) (*models.PHPTorrentInfo, error)
- 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 IsSiteGroupSupported(siteGroup models.SiteGroup) bool
- func NewCollectorWithTransport() *colly.Collector
- func ProcessTorrentsWithDBUpdate(ctx context.Context, qbitClient *qbit.QbitClient, ...) error
- func ProcessTorrentsWithDownloaderByRSS(ctx context.Context, rssCfg models.RSSConfig, dirPath, category, tags string, ...) error
- func RegisterTorrentScheduler(f TorrentScheduleFunc)
- func ScheduleTorrentForMonitoring(torrent models.TorrentInfo)
- type DefaultReferer
- type DownloaderInfo
- type HDSkyParser
- func (p *HDSkyParser) ParseDiscount(e *colly.HTMLElement, info *models.PHPTorrentInfo)
- func (p *HDSkyParser) ParseHR(e *colly.HTMLElement, info *models.PHPTorrentInfo)
- func (p *HDSkyParser) ParseTitleAndID(e *colly.HTMLElement, info *models.PHPTorrentInfo)
- func (p *HDSkyParser) ParseTorrentSizeMB(e *colly.HTMLElement, info *models.PHPTorrentInfo)
- type LegacyParserAdapter
- func (a *LegacyParserAdapter) ParseDiscount(e *colly.HTMLElement, info *models.PHPTorrentInfo)
- func (a *LegacyParserAdapter) ParseHR(e *colly.HTMLElement, info *models.PHPTorrentInfo)
- func (a *LegacyParserAdapter) ParseTitleAndID(e *colly.HTMLElement, info *models.PHPTorrentInfo)
- func (a *LegacyParserAdapter) ParseTorrentSizeMB(e *colly.HTMLElement, info *models.PHPTorrentInfo)
- type PTSiteInter
- type ParserConfig
- type ParserOption
- type PushTorrentRequest
- type PushTorrentResult
- type RefererProvider
- type SharedSiteConfig
- type SiteConfig
- type SiteMapConfig
- type SiteParser
- type SpringSundayParser
- func (p *SpringSundayParser) ParseDiscount(e *colly.HTMLElement, info *models.PHPTorrentInfo)
- func (p *SpringSundayParser) ParseHR(e *colly.HTMLElement, info *models.PHPTorrentInfo)
- func (p *SpringSundayParser) ParseTitleAndID(e *colly.HTMLElement, info *models.PHPTorrentInfo)
- func (p *SpringSundayParser) ParseTorrentSizeMB(e *colly.HTMLElement, info *models.PHPTorrentInfo)
- 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) SendTorrentToQbit(ctx context.Context, rssCfg models.RSSConfig) error
- func (u *UnifiedSiteImpl) SiteGroup() models.SiteGroup
Constants ¶
This section is empty.
Variables ¶
var IDToSiteGroup = map[string]models.SiteGroup{ "mteam": models.MTEAM, "hdsky": models.HDSKY, "springsunday": models.SpringSunday, }
IDToSiteGroup 将 site/v2 的 site ID 映射到 models.SiteGroup
var SiteGroupToID = map[models.SiteGroup]string{ models.MTEAM: "mteam", models.HDSKY: "hdsky", models.SpringSunday: "springsunday", }
SiteGroupToID 将 models.SiteGroup 映射到 site/v2 的 site ID
var SiteGroupToKind = map[models.SiteGroup]v2.SiteKind{ models.MTEAM: v2.SiteMTorrent, models.HDSKY: v2.SiteNexusPHP, models.SpringSunday: v2.SiteNexusPHP, }
SiteGroupToKind 将 models.SiteGroup 映射到 v2.SiteKind
Functions ¶
func CommonFetchTorrentInfo ¶ added in v0.2.0
func CommonFetchTorrentInfo(ctx context.Context, c *colly.Collector, cfg *SiteMapConfig, url string) (*models.PHPTorrentInfo, error)
CommonFetchTorrentInfo fetches torrent info from a URL
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
GetAllSupportedSiteGroups 返回所有支持的站点分组
func GetDownloaderForRSS ¶ added in v0.2.0
func GetDownloaderForRSS(rssCfg models.RSSConfig) (downloader.Downloader, error)
GetDownloaderForRSS 根据 RSS 配置获取下载器 优先级:RSS 指定的下载器 > 默认下载器 返回下载器实例和下载器信息
func IsSiteGroupSupported ¶ added in v0.2.0
IsSiteGroupSupported 检查站点分组是否支持
func NewCollectorWithTransport ¶ added in v0.2.0
NewCollectorWithTransport creates a new colly collector with custom transport
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 RegisterTorrentScheduler ¶ added in v0.3.0
func RegisterTorrentScheduler(f TorrentScheduleFunc)
func ScheduleTorrentForMonitoring ¶ added in v0.3.0
func ScheduleTorrentForMonitoring(torrent models.TorrentInfo)
Types ¶
type DefaultReferer ¶ added in v0.2.0
type DefaultReferer struct {
// contains filtered or unexported fields
}
DefaultReferer implements RefererProvider
func NewDefaultReferer ¶ added in v0.2.0
func NewDefaultReferer(name models.SiteGroup) *DefaultReferer
NewDefaultReferer creates a new DefaultReferer based on site group
func (*DefaultReferer) GetReferer ¶ added in v0.2.0
func (d *DefaultReferer) GetReferer() string
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 配置获取下载器及其信息 优先级:RSS 指定的下载器 > 默认下载器 返回下载器实例和下载器信息(用于内部使用)
type HDSkyParser ¶ added in v0.2.0
type HDSkyParser struct {
Config ParserConfig
}
HDSkyParser implements SiteParser for HDSky
func NewHDSkyParser ¶ added in v0.2.0
func NewHDSkyParser(options ...ParserOption) *HDSkyParser
NewHDSkyParser creates a new HDSkyParser
func (*HDSkyParser) ParseDiscount ¶ added in v0.2.0
func (p *HDSkyParser) ParseDiscount(e *colly.HTMLElement, info *models.PHPTorrentInfo)
ParseDiscount parses discount type and end time
func (*HDSkyParser) ParseHR ¶ added in v0.2.0
func (p *HDSkyParser) ParseHR(e *colly.HTMLElement, info *models.PHPTorrentInfo)
ParseHR parses HR status
func (*HDSkyParser) ParseTitleAndID ¶ added in v0.2.0
func (p *HDSkyParser) ParseTitleAndID(e *colly.HTMLElement, info *models.PHPTorrentInfo)
ParseTitleAndID parses title and torrent ID
func (*HDSkyParser) ParseTorrentSizeMB ¶ added in v0.2.0
func (p *HDSkyParser) ParseTorrentSizeMB(e *colly.HTMLElement, info *models.PHPTorrentInfo)
ParseTorrentSizeMB parses torrent size in MB
type LegacyParserAdapter ¶ added in v0.2.0
type LegacyParserAdapter struct {
// contains filtered or unexported fields
}
LegacyParserAdapter adapts v2.NexusPHPDetailParser to the legacy SiteParser interface This allows using the new v2 parsers with the existing colly-based fetching code
func NewLegacyParserAdapter ¶ added in v0.2.0
func NewLegacyParserAdapter(parser v2.NexusPHPDetailParser) *LegacyParserAdapter
NewLegacyParserAdapter creates a new adapter for a v2 parser
func (*LegacyParserAdapter) ParseDiscount ¶ added in v0.2.0
func (a *LegacyParserAdapter) ParseDiscount(e *colly.HTMLElement, info *models.PHPTorrentInfo)
ParseDiscount adapts the v2 parser's ParseDiscount method
func (*LegacyParserAdapter) ParseHR ¶ added in v0.2.0
func (a *LegacyParserAdapter) ParseHR(e *colly.HTMLElement, info *models.PHPTorrentInfo)
ParseHR adapts the v2 parser's ParseHR method
func (*LegacyParserAdapter) ParseTitleAndID ¶ added in v0.2.0
func (a *LegacyParserAdapter) ParseTitleAndID(e *colly.HTMLElement, info *models.PHPTorrentInfo)
ParseTitleAndID adapts the v2 parser's ParseTitleAndID method
func (*LegacyParserAdapter) ParseTorrentSizeMB ¶ added in v0.2.0
func (a *LegacyParserAdapter) ParseTorrentSizeMB(e *colly.HTMLElement, info *models.PHPTorrentInfo)
ParseTorrentSizeMB adapts the v2 parser's ParseSizeMB method
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 SendTorrentToQbit(ctx context.Context, rssCfg models.RSSConfig) error Context() context.Context }
PTSiteInter 旧的泛型接口(已废弃,请使用 UnifiedPTSite) Deprecated: Use UnifiedPTSite instead for new implementations
type ParserConfig ¶ added in v0.2.0
type ParserConfig struct {
TimeLayout string
}
ParserConfig defines parser configuration
type ParserOption ¶ added in v0.2.0
type ParserOption func(*ParserConfig)
ParserOption is a function that modifies ParserConfig
func WithTimeLayout ¶ added in v0.2.0
func WithTimeLayout(layout string) ParserOption
WithTimeLayout sets the time layout
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 RefererProvider ¶ added in v0.2.0
type RefererProvider interface {
GetReferer() string
}
RefererProvider provides referer URL for requests
type SharedSiteConfig ¶ added in v0.2.0
type SharedSiteConfig struct {
}
SharedSiteConfig holds shared configuration across sites
type SiteConfig ¶ added in v0.2.0
type SiteConfig struct {
RefererConf RefererProvider
}
SiteConfig holds site-specific configuration
type SiteMapConfig ¶ added in v0.2.0
type SiteMapConfig struct {
Name string
Config models.SiteConfig
Parser SiteParser
CustomHeaders map[string]string
}
SiteMapConfig holds complete site configuration
func NewSiteMapConfig ¶ added in v0.2.0
func NewSiteMapConfig(name models.SiteGroup, cookie string, conf models.SiteConfig, parser SiteParser) *SiteMapConfig
NewSiteMapConfig creates a new SiteMapConfig
type SiteParser ¶ added in v0.2.0
type SiteParser interface {
ParseTitleAndID(e *colly.HTMLElement, info *models.PHPTorrentInfo)
ParseDiscount(e *colly.HTMLElement, info *models.PHPTorrentInfo)
ParseHR(e *colly.HTMLElement, info *models.PHPTorrentInfo)
ParseTorrentSizeMB(e *colly.HTMLElement, info *models.PHPTorrentInfo)
}
SiteParser interface for parsing torrent pages
type SpringSundayParser ¶ added in v0.2.0
type SpringSundayParser struct {
Config ParserConfig
}
SpringSundayParser implements SiteParser for SpringSunday
func NewSpringSundayParser ¶ added in v0.2.0
func NewSpringSundayParser(options ...ParserOption) *SpringSundayParser
NewSpringSundayParser creates a new SpringSundayParser
func (*SpringSundayParser) ParseDiscount ¶ added in v0.2.0
func (p *SpringSundayParser) ParseDiscount(e *colly.HTMLElement, info *models.PHPTorrentInfo)
ParseDiscount parses discount type and end time for SpringSunday
func (*SpringSundayParser) ParseHR ¶ added in v0.2.0
func (p *SpringSundayParser) ParseHR(e *colly.HTMLElement, info *models.PHPTorrentInfo)
ParseHR parses HR status for SpringSunday
func (*SpringSundayParser) ParseTitleAndID ¶ added in v0.2.0
func (p *SpringSundayParser) ParseTitleAndID(e *colly.HTMLElement, info *models.PHPTorrentInfo)
ParseTitleAndID parses title and torrent ID for SpringSunday
func (*SpringSundayParser) ParseTorrentSizeMB ¶ added in v0.2.0
func (p *SpringSundayParser) ParseTorrentSizeMB(e *colly.HTMLElement, info *models.PHPTorrentInfo)
ParseTorrentSizeMB parses torrent size in MB for SpringSunday
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
// SendTorrentToQbit 发送种子到下载器
SendTorrentToQbit(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
NewUnifiedSiteImpl 创建统一站点实现 根据 SiteGroup 自动选择正确的 Driver 和配置
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) SendTorrentToQbit ¶ added in v0.2.0
SendTorrentToQbit 发送种子到下载器
func (*UnifiedSiteImpl) SiteGroup ¶ added in v0.2.0
func (u *UnifiedSiteImpl) SiteGroup() models.SiteGroup
SiteGroup 返回站点分组标识