Skip to content

Commit

Permalink
add brushExcludes site option
Browse files Browse the repository at this point in the history
  • Loading branch information
sagan committed Aug 14, 2023
1 parent 42090c7 commit db9f503
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
6 changes: 2 additions & 4 deletions cmd/batchdl/batchdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,8 @@ mainloop:
log.Tracef("Skip torrent %s due to filter %s does NOT match", torrent.Name, filter)
continue
}
if index := slices.IndexFunc(excludesList, func(excludeStr string) bool {
return torrent.MatchFilter(excludeStr)
}); index != -1 {
log.Tracef("Skip torrent %s due to exclude string %s matchs", torrent.Name, excludesList[index])
if torrent.MatchFiltersOr(excludesList) {
log.Tracef("Skip torrent %s due to excludes matches", torrent.Name)
continue
}
if len(includesList) > 0 {
Expand Down
13 changes: 10 additions & 3 deletions cmd/brush/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type BrushOptionStruct struct {
TorrentMinSizeLimit int64
TorrentMaxSizeLimit int64
Now int64
Excludes []string
}

type AlgorithmAddTorrent struct {
Expand Down Expand Up @@ -162,7 +163,7 @@ func Decide(clientStatus *client.Status, clientTorrents []client.Torrent, siteTo
}

for _, siteTorrent := range siteTorrents {
score, predictionUploadSpeed := rateSiteTorrent(&siteTorrent, option)
score, predictionUploadSpeed, _ := rateSiteTorrent(&siteTorrent, option)
if score > 0 {
candidateTorrent := candidateTorrentStruct{
Name: siteTorrent.Name,
Expand Down Expand Up @@ -481,16 +482,17 @@ func Decide(clientStatus *client.Status, clientTorrents []client.Torrent, siteTo
return
}

func rateSiteTorrent(siteTorrent *site.Torrent, brushOption *BrushOptionStruct) (score float64, predictionUploadSpeed int64) {
func rateSiteTorrent(siteTorrent *site.Torrent, brushOption *BrushOptionStruct) (score float64, predictionUploadSpeed int64, note string) {
if log.GetLevel() >= log.TraceLevel {
defer func() {
log.Tracef("rateSiteTorrent score=%0.0f name=%s, free=%t, rtime=%d, seeders=%d, leechers=%d",
log.Tracef("rateSiteTorrent score=%0.0f name=%s, free=%t, rtime=%d, seeders=%d, leechers=%d, note=%s",
score,
siteTorrent.Name,
siteTorrent.DownloadMultiplier == 0,
brushOption.Now-siteTorrent.Time,
siteTorrent.Seeders,
siteTorrent.Leechers,
note,
)
}()
}
Expand All @@ -506,6 +508,11 @@ func rateSiteTorrent(siteTorrent *site.Torrent, brushOption *BrushOptionStruct)
score = 0
return
}
if siteTorrent.MatchFiltersOr(brushOption.Excludes) {
score = 0
note = "brush excludes matches"
return
}
// 部分站点定期将旧种重新置顶免费。这类种子仍然可以获得很好的上传速度。
if brushOption.Now-siteTorrent.Time <= 86400*30 {
if brushOption.Now-siteTorrent.Time >= 86400 {
Expand Down
1 change: 1 addition & 0 deletions cmd/brush/brush.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func brush(cmd *cobra.Command, args []string) error {
AllowPaid: siteInstance.GetSiteConfig().BrushAllowPaid,
AllowHr: siteInstance.GetSiteConfig().BrushAllowHr,
AllowZeroSeeders: siteInstance.GetSiteConfig().BrushAllowZeroSeeders,
Excludes: siteInstance.GetSiteConfig().BrushExcludes,
MinDiskSpace: clientInstance.GetClientConfig().BrushMinDiskSpaceValue,
SlowUploadSpeedTier: clientInstance.GetClientConfig().BrushSlowUploadSpeedTierValue,
MaxDownloadingTorrents: clientInstance.GetClientConfig().BrushMaxDownloadingTorrents,
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type SiteConfigStruct struct {
BrushAllowPaid bool `yaml:"brushAllowPaid"`
BrushAllowHr bool `yaml:"brushAllowHr"`
BrushAllowZeroSeeders bool `yaml:"brushAllowZeroSeeders"`
BrushExcludes []string `yaml:"brushExcludes"`
SelectorTorrentsListHeader string `yaml:"selectorTorrentsListHeader"`
SelectorTorrentsList string `yaml:"selectorTorrentsList"`
SelectorTorrentBlock string `yaml:"selectorTorrentBlock"` // dom block of a torrent in list
Expand Down
8 changes: 8 additions & 0 deletions ptool.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ cookie = "cookie_here"
#brushAllowPaid = false # 是否允许使用"付费"种子刷流(付费种子:第一次下载或汇报时需要扣除积分)
#brushAllowHr = false # 是否允许使用HR种子刷流。程序不会特意保证HR种子的做种时长,所以仅当你的账户无视HR(如VIP)时开启此选项
#brushAllowZeroSeeders = false # 是否允许刷流任务添加当前0做种的种子到客户端
#brushExcludes = [] # 排除种子关键字列表。标题或副标题包含列表中任意项的种子不会被刷流任务选择
#timezone = "Asia/Shanghai" # 网站页面显示时间的时区

# 站点分组功能
# 定义分组后,大部分命令中 <site> 类型的参数可以使用分组名代替以指代多个站点,例如:
# 在 acg 分组的所有站点中搜索 "clannad" 关键词的种子: ptool search acg clannad
[[groups]]
name = "acg"
sites = ["u2", "kamept"]
7 changes: 7 additions & 0 deletions site/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ func (torrent *Torrent) MatchFilter(filter string) bool {
return false
}

// will match if any filter in list matches
func (torrent *Torrent) MatchFiltersOr(filters []string) bool {
return slices.IndexFunc(filters, func(filter string) bool {
return torrent.MatchFilter(filter)
}) != -1
}

func Register(regInfo *RegInfo) {
registryMap[regInfo.Name] = regInfo
for _, alias := range regInfo.Aliases {
Expand Down
1 change: 1 addition & 0 deletions site/tpl/tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ var (
Url: "https://kp.m-team.cc/",
Domains: []string{"m-team.io"},
TorrentsExtraUrls: []string{"adult.php", "music.php"},
BrushExcludes: []string{"[原盤首發]"}, // 馒头原盘首发限速,刷流效果极差
Comment: "馒头",
},
"monikadesign": &config.SiteConfigStruct{
Expand Down

0 comments on commit db9f503

Please sign in to comment.