parser

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigurableParser

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

ConfigurableParser 可配置的站点解析器 通过配置文件定义解析规则,支持动态站点

func NewConfigurableParser

func NewConfigurableParser(config *ParserConfig) (*ConfigurableParser, error)

NewConfigurableParser 创建可配置解析器

func (*ConfigurableParser) GetName

func (p *ConfigurableParser) GetName() string

GetName 获取解析器名称

func (*ConfigurableParser) ParseRSSItem

func (p *ConfigurableParser) ParseRSSItem(title, link, description string) (*ParsedTorrentInfo, error)

ParseRSSItem 解析RSS条目

func (*ConfigurableParser) ParseTorrentPage

func (p *ConfigurableParser) ParseTorrentPage(e *colly.HTMLElement) (*ParsedTorrentInfo, error)

ParseTorrentPage 解析种子详情页面

type ParsedTorrentInfo

type ParsedTorrentInfo struct {
	ID           string
	Title        string
	Size         int64 // 字节
	IsFree       bool
	FreeEndTime  time.Time
	HasHR        bool
	DownloadURL  string
	DiscountType string
}

ParsedTorrentInfo 解析后的种子信息

type ParserConfig

type ParserConfig struct {
	// Name 解析器名称
	Name string `json:"name"`

	// TimeLayout 时间格式
	TimeLayout string `json:"time_layout"`

	// Selectors CSS选择器配置
	Selectors SelectorConfig `json:"selectors"`

	// Patterns 正则表达式配置
	Patterns PatternConfig `json:"patterns"`

	// DiscountMapping 优惠类型映射
	DiscountMapping map[string]string `json:"discount_mapping"`
}

ParserConfig 可配置解析器的配置

func DefaultParserConfig

func DefaultParserConfig() *ParserConfig

DefaultParserConfig 返回默认解析器配置

func (*ParserConfig) Validate

func (c *ParserConfig) Validate() error

Validate 验证解析器配置

type PatternConfig

type PatternConfig struct {
	// SizePattern 大小提取正则
	// 应包含两个捕获组:数值和单位
	// 例如: `([\d.]+)\s*(GB|MB|KB|TB)`
	SizePattern string `json:"size_pattern"`

	// IDPattern 种子ID提取正则
	IDPattern string `json:"id_pattern"`

	// HRKeywords HR关键词列表
	HRKeywords []string `json:"hr_keywords"`
}

PatternConfig 正则表达式配置

type SelectorConfig

type SelectorConfig struct {
	// TitleSelector 标题选择器
	TitleSelector string `json:"title_selector"`

	// IDSelector 种子ID选择器
	IDSelector string `json:"id_selector"`

	// SizeSelector 大小选择器
	SizeSelector string `json:"size_selector"`

	// DiscountSelector 优惠类型选择器
	DiscountSelector string `json:"discount_selector"`

	// FreeEndTimeSelector 免费结束时间选择器
	FreeEndTimeSelector string `json:"free_end_time_selector"`

	// HRSelector HR标记选择器
	HRSelector string `json:"hr_selector"`

	// DownloadURLSelector 下载链接选择器
	DownloadURLSelector string `json:"download_url_selector"`
}

SelectorConfig CSS选择器配置

type SiteParser

type SiteParser interface {
	// ParseTorrentPage 解析种子详情页面
	// e: colly HTML元素
	// 返回解析后的种子信息
	ParseTorrentPage(e *colly.HTMLElement) (*ParsedTorrentInfo, error)

	// ParseRSSItem 解析RSS条目中的额外信息
	// 某些站点的RSS包含额外的种子信息
	ParseRSSItem(title, link, description string) (*ParsedTorrentInfo, error)

	// GetName 获取解析器名称
	GetName() string
}

SiteParser 站点解析器接口 定义从HTML页面解析种子信息的方法

Jump to

Keyboard shortcuts

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