Skip to content

Commit

Permalink
refactor: add tracker down check to IsUnregistered
Browse files Browse the repository at this point in the history
  • Loading branch information
s0up4200 committed Jan 15, 2025
1 parent 742cb8e commit b578e1a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 38 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ filters:
- '"permaseed" in Tags && !IsUnregistered()'
remove:
# general
- IsUnregistered() && !IsTrackerDown()
- IsUnregistered()
# imported
- Label in ["sonarr-imported", "radarr-imported", "lidarr-imported"] && (Ratio > 4.0 || SeedingDays >= 15.0)
# ipt
Expand Down Expand Up @@ -205,13 +205,26 @@ Log(n float64) float64 // The natural logarithm function

When using both `IsUnregistered()` and `IsTrackerDown()` in filters:

- `IsUnregistered() && !IsTrackerDown()` - Only matches torrents that are confirmed unregistered while the tracker is responding
- This helps prevent false positives where torrents might appear unregistered simply because their tracker is down
- `IsUnregistered()` has built-in protection against tracker down states - it will return `false` if the tracker is down
- `IsTrackerDown()` checks if the tracker status indicates the tracker is unreachable/down
- The functions are independent but related - a torrent can be:
- Unregistered with tracker up (IsUnregistered: true, IsTrackerDown: false)
- Status unknown with tracker down (IsUnregistered: false, IsTrackerDown: true)
- Registered with tracker up (IsUnregistered: false, IsTrackerDown: false)

Note: While `IsUnregistered()` automatically handles tracker down states, you may still want to explicitly check for `IsTrackerDown()` in your ignore filters to prevent any actions when tracker status is uncertain.

Example:

```yaml
filters:
default:
ignore:
- IsTrackerDown() # Skip any actions when tracker is down
remove:
- IsUnregistered() # Safe to use alone due to built-in protection
```
## BypassIgnoreIfUnregistered
If the top level config option `bypassIgnoreIfUnregistered` is set to `true`, unregistered torrents will not be ignored.
Expand Down
54 changes: 19 additions & 35 deletions config/torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,26 @@ type Torrent struct {
regexPattern *regex.Pattern
}

func (t *Torrent) IsTrackerDown() bool {
if t.TrackerStatus == "" {
return false
}

status := strings.ToLower(t.TrackerStatus)
for _, v := range trackerDownStatuses {
if strings.Contains(status, v) {
return true
}
}

return false
}

func (t *Torrent) IsUnregistered() bool {
if t.IsTrackerDown() {
return false
}

if t.TrackerStatus == "" {
return false
}
Expand Down Expand Up @@ -220,38 +239,3 @@ func (t *Torrent) RegexMatchAll(patternsStr string) bool {
}
return match
}

func (t *Torrent) IsTrackerDown() bool {
if t.TrackerStatus == "" {
return false
}

status := strings.ToLower(t.TrackerStatus)
for _, v := range trackerDownStatuses {
if strings.Contains(status, v) {
return true
}
}

// check tracker api (if available)
if tr := tracker.Get(t.TrackerName); tr != nil {
tt := &tracker.Torrent{
Hash: t.Hash,
Name: t.Name,
TotalBytes: t.TotalBytes,
DownloadedBytes: t.DownloadedBytes,
State: t.State,
Downloaded: t.Downloaded,
Seeding: t.Seeding,
TrackerName: t.TrackerName,
TrackerStatus: t.State,
Comment: t.Comment,
}

if err, down := tr.IsTrackerDown(tt); err == nil {
return down
}
}

return false
}

0 comments on commit b578e1a

Please sign in to comment.