models

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DBFile  = "torrents.db"
	WorkDir = ".pt-tools"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIResponse

type APIResponse[T ResType] struct {
	Message string `json:"message"`
	Data    T      `json:"data"`
	Code    string `json:"code"`
}

type DiscountType

type DiscountType string

DiscountType 定义优惠类型

const (
	DISCOUNT_NONE        DiscountType = "none"
	DISCOUNT_FREE        DiscountType = "free"
	DISCOUNT_TWO_X       DiscountType = "2x"
	DISCOUNT_TWO_X_FREE  DiscountType = "2xfree"
	DISCOUNT_THIRTY      DiscountType = "30%"
	DISCOUNT_FIFTY       DiscountType = "50%"
	DISCOUNT_TWO_X_FIFTY DiscountType = "2x50%"
	DISCOUNT_CUSTOM      DiscountType = "custom"
)

type FreeDownChecker

type FreeDownChecker interface {
	IsFree() bool
	CanbeFinished(logger *zap.Logger, enabled bool, speedLimit, sizeLimitGB int) bool
	GetFreeEndTime() *time.Time
}

type MTTorrentDetail

type MTTorrentDetail struct {
	ID               string        `json:"id"`
	CreatedDate      string        `json:"createdDate"`
	LastModifiedDate string        `json:"lastModifiedDate"`
	Name             string        `json:"name"`
	SmallDescr       string        `json:"smallDescr"`
	IMDb             string        `json:"imdb"`
	IMDbRating       *string       `json:"imdbRating"`
	Douban           string        `json:"douban"`
	DoubanRating     *string       `json:"doubanRating"`
	DmmCode          string        `json:"dmmCode"`
	Author           interface{}   `json:"author"`
	Category         string        `json:"category"`
	Source           string        `json:"source"`
	Medium           interface{}   `json:"medium"`
	Standard         string        `json:"standard"`
	VideoCodec       string        `json:"videoCodec"`
	AudioCodec       string        `json:"audioCodec"`
	Team             string        `json:"team"`
	Processing       interface{}   `json:"processing"`
	Countries        []string      `json:"countries"`
	NumFiles         string        `json:"numfiles"`
	Size             string        `json:"size"`
	Tags             string        `json:"tags"`
	Labels           string        `json:"labels"`
	MsUp             string        `json:"msUp"`
	Anonymous        bool          `json:"anonymous"`
	InfoHash         interface{}   `json:"infoHash"`
	Status           *Status       `json:"status"`
	EditedBy         interface{}   `json:"editedBy"`
	EditDate         interface{}   `json:"editDate"`
	Collection       bool          `json:"collection"`
	InRss            bool          `json:"inRss"`
	CanVote          bool          `json:"canVote"`
	ImageList        interface{}   `json:"imageList"`
	ResetBox         interface{}   `json:"resetBox"`
	OriginFileName   string        `json:"originFileName"`
	Descr            string        `json:"descr"`
	Nfo              interface{}   `json:"nfo"`
	MediaInfo        string        `json:"mediainfo"`
	CIDs             interface{}   `json:"cids"`
	AIDs             interface{}   `json:"aids"`
	ShowcaseList     []Showcase    `json:"showcaseList"`
	TagList          []interface{} `json:"tagList"`
	Scope            string        `json:"scope"`
	ScopeTeams       []interface{} `json:"scopeTeams"`
	Thanked          bool          `json:"thanked"`
	Rewarded         bool          `json:"rewarded"`
}

func (MTTorrentDetail) CanbeFinished

func (t MTTorrentDetail) CanbeFinished(logger *zap.Logger, enabled bool, speedLimit, sizeLimitGB int) bool

func (MTTorrentDetail) GetFreeEndTime

func (t MTTorrentDetail) GetFreeEndTime() *time.Time

func (MTTorrentDetail) IsFree

func (t MTTorrentDetail) IsFree() bool

type PHPTorrentInfo

type PHPTorrentInfo struct {
	Title     string       // 种子标题
	TorrentID string       // 种子 ID
	Discount  DiscountType // 优惠类型
	EndTime   time.Time    // 优惠结束时间
	SizeMB    float64      // 种子大小,单位为 MB
	Seeders   int          // 做种人数
	Leechers  int          // 下载人数
	Completed float64      // 最大完成百分比
	HR        bool         // 是否为 HR(Hit & Run)
}

PHPTorrentInfo 定义种子信息结构

func (PHPTorrentInfo) CanbeFinished

func (p PHPTorrentInfo) CanbeFinished(logger *zap.Logger, enabled bool, speedLimit, sizeLimitGB int) bool

func (PHPTorrentInfo) GetFreeEndTime

func (p PHPTorrentInfo) GetFreeEndTime() *time.Time

func (PHPTorrentInfo) IsFree

func (p PHPTorrentInfo) IsFree() bool

type PromotionRule

type PromotionRule struct {
	Categories  []string `json:"categories"`
	CreatedDate string   `json:"createdDate"`
	Discount    string   `json:"discount"`
}

type ResType

type ResType interface {
	MTTorrentDetail | PHPTorrentInfo
	FreeDownChecker
}

type Showcase

type Showcase struct {
	CreatedDate      string     `json:"createdDate"`
	LastModifiedDate string     `json:"lastModifiedDate"`
	ID               string     `json:"id"`
	Collection       bool       `json:"collection"`
	UserID           string     `json:"userid"`
	Username         string     `json:"username"`
	CnTitle          string     `json:"cntitle"`
	EnTitle          string     `json:"entitle"`
	Note             string     `json:"note"`
	Pic              string     `json:"pic"`
	Pic1             string     `json:"pic1"`
	Pic2             string     `json:"pic2"`
	Count            string     `json:"count"`
	Size             string     `json:"size"`
	View             string     `json:"view"`
	Statistics       Statistics `json:"statistics"`
}

type SiteGroup

type SiteGroup string
const (
	CMCT  SiteGroup = "cmct"
	HDSKY SiteGroup = "hdsky"
	MTEAM SiteGroup = "mteam"
)

允许的值

func ValidateSiteName

func ValidateSiteName(value string) (SiteGroup, error)

type Statistics

type Statistics struct {
	CreatedDate      string `json:"createdDate"`
	LastModifiedDate string `json:"lastModifiedDate"`
	ID               string `json:"id"`
	Day              string `json:"day"`
	Week             string `json:"week"`
	Month            string `json:"month"`
	Year             string `json:"year"`
	DayClick         string `json:"dayClick"`
	WeekClick        string `json:"weekClick"`
	MonthClick       string `json:"monthClick"`
	YearClick        string `json:"yearClick"`
}

type Status

type Status struct {
	ID               string         `json:"id"`
	CreatedDate      string         `json:"createdDate"`
	LastModifiedDate string         `json:"lastModifiedDate"`
	PickType         string         `json:"pickType"`
	ToppingLevel     string         `json:"toppingLevel"`
	ToppingEndTime   string         `json:"toppingEndTime"`
	Discount         string         `json:"discount"`
	DiscountEndTime  string         `json:"discountEndTime"`
	TimesCompleted   string         `json:"timesCompleted"`
	Comments         string         `json:"comments"`
	LastAction       string         `json:"lastAction"`
	LastSeederAction string         `json:"lastSeederAction"`
	Views            string         `json:"views"`
	Hits             string         `json:"hits"`
	Support          string         `json:"support"`
	Oppose           string         `json:"oppose"`
	Status           string         `json:"status"`
	Seeders          string         `json:"seeders"`
	Leechers         string         `json:"leechers"`
	Banned           bool           `json:"banned"`
	Visible          bool           `json:"visible"`
	PromotionRule    *PromotionRule `json:"promotionRule"`
	MallSingleFree   interface{}    `json:"mallSingleFree"`
}

type TorrentDB

type TorrentDB struct {
	DB *gorm.DB
}

TorrentDB 封装数据库操作

func NewDB

func NewDB(gormLg zapgorm2.Logger) (*TorrentDB, error)

NewDB 初始化并返回 TorrentDB

func (*TorrentDB) DeleteTorrent

func (t *TorrentDB) DeleteTorrent(torrentHash string) error

DeleteTorrent 删除种子信息

func (*TorrentDB) GetAllTorrents

func (t *TorrentDB) GetAllTorrents() ([]TorrentInfo, error)

GetAllTorrents 查询所有种子信息

func (*TorrentDB) GetTorrentBySiteAndHash

func (t *TorrentDB) GetTorrentBySiteAndHash(siteName, torrentHash string) (*TorrentInfo, error)

GetTorrentBySiteAndHash 根据 SiteName 和 TorrentHash 查询种子信息

func (*TorrentDB) GetTorrentBySiteAndID

func (t *TorrentDB) GetTorrentBySiteAndID(siteName, torrentID string) (*TorrentInfo, error)

GetTorrentBySiteAndID 根据 SiteName 和 TorrentID 查询种子信息

func (*TorrentDB) UpdateTorrentStatus

func (t *TorrentDB) UpdateTorrentStatus(torrentHash string, isDownloaded, isPushed bool, pushTime *time.Time) error

UpdateTorrentStatus 更新种子状态

func (*TorrentDB) UpsertTorrent

func (t *TorrentDB) UpsertTorrent(torrent *TorrentInfo) error

UpsertTorrent 插入或更新种子信息

func (*TorrentDB) WithTransaction

func (t *TorrentDB) WithTransaction(fn func(tx *gorm.DB) error) error

WithTransaction 使用事务

type TorrentInfo

type TorrentInfo struct {
	ID           uint       `gorm:"primaryKey"`                   // 主键
	SiteName     string     `gorm:"uniqueIndex:idx_site_torrent"` // 与 TorrentID 组合唯一约束
	TorrentID    string     `gorm:"uniqueIndex:idx_site_torrent"` // 与 SiteName 组合唯一约束
	TorrentHash  *string    `gorm:"index"`                        // 允许为 NULL 且添加普通索引
	IsDownloaded bool       `gorm:"default:false"`                // 默认值
	IsPushed     *bool      `gorm:"default:null"`                 // 默认值
	IsSkipped    bool       `gorm:"default:false"`                // 默认值
	FreeLevel    string     `gorm:"default:'normal'"`             // 默认值
	FreeEndTime  *time.Time `gorm:"default:null"`                 // 允许为空
	PushTime     *time.Time `gorm:"default:null"`                 // 允许为空
	CreatedAt    time.Time  // GORM 自动管理
	UpdatedAt    time.Time  // GORM 自动管理
}

TorrentInfo 表示种子信息

Jump to

Keyboard shortcuts

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