mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
feat(filters): RED and OPS fetch uploader from API (#1348)
* feat: added uploader when fetching torrent details on RED indexer * revert * tests * refactor(filters): size and uploader api checks * refactor(filters): fix test * refactor(filters): add mutex to rejections --------- Co-authored-by: Kyle Sanderson <kyle.leet@gmail.com> Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
parent
04c4bd482f
commit
acef4ac624
8 changed files with 251 additions and 88 deletions
|
@ -460,12 +460,8 @@ func (f *Filter) CheckFilter(r *Release) (*RejectionReasons, bool) {
|
|||
}
|
||||
}
|
||||
|
||||
if f.MatchUploaders != "" && !contains(r.Uploader, f.MatchUploaders) {
|
||||
f.RejectReasons.Add("match uploaders", r.Uploader, f.MatchUploaders)
|
||||
}
|
||||
|
||||
if f.ExceptUploaders != "" && contains(r.Uploader, f.ExceptUploaders) {
|
||||
f.RejectReasons.Add("except uploaders", r.Uploader, f.ExceptUploaders)
|
||||
if (f.MatchUploaders != "" || f.ExceptUploaders != "") && !f.checkUploader(r) {
|
||||
// f.checkUploader sets the rejections
|
||||
}
|
||||
|
||||
if len(f.MatchLanguage) > 0 && !sliceContainsSlice(r.Language, f.MatchLanguage) {
|
||||
|
@ -731,6 +727,27 @@ func (f *Filter) checkSizeFilter(r *Release) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// checkUploader checks if the uploader is within the given list.
|
||||
// if the haystack is not empty but the uploader is, then a further
|
||||
// investigation is needed
|
||||
func (f *Filter) checkUploader(r *Release) bool {
|
||||
// only support additional uploader check for RED and OPS
|
||||
if r.Uploader == "" && (r.Indexer.Identifier == "redacted" || r.Indexer.Identifier == "ops") {
|
||||
r.AdditionalUploaderCheckRequired = true
|
||||
return true
|
||||
}
|
||||
|
||||
if f.MatchUploaders != "" && !contains(r.Uploader, f.MatchUploaders) {
|
||||
f.RejectReasons.Add("match uploaders", r.Uploader, f.MatchUploaders)
|
||||
}
|
||||
|
||||
if f.ExceptUploaders != "" && contains(r.Uploader, f.ExceptUploaders) {
|
||||
f.RejectReasons.Add("except uploaders", r.Uploader, f.ExceptUploaders)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// IsPerfectFLAC Perfect is "CD FLAC Cue Log 100% Lossless or 24bit Lossless"
|
||||
func (f *Filter) IsPerfectFLAC(r *Release) ([]string, bool) {
|
||||
rejections := []string{}
|
||||
|
@ -1168,6 +1185,20 @@ func (f *Filter) CheckReleaseSize(releaseSize uint64) (bool, error) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
func (f *Filter) CheckUploader(uploader string) (bool, error) {
|
||||
if f.MatchUploaders != "" && !contains(uploader, f.MatchUploaders) {
|
||||
f.RejectReasons.Add("match uploader", uploader, f.MatchUploaders)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if f.ExceptUploaders != "" && contains(uploader, f.ExceptUploaders) {
|
||||
f.RejectReasons.Add("except uploader", uploader, f.ExceptUploaders)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// parsedSizeLimits parses filter bytes limits (expressed as a string) into a
|
||||
// uint64 number of bytes. The bounds are returned as *uint64 number of bytes,
|
||||
// with "nil" representing "no limit". We break out filter size limit parsing
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Rejection struct {
|
||||
|
@ -17,6 +18,7 @@ type Rejection struct {
|
|||
}
|
||||
|
||||
type RejectionReasons struct {
|
||||
m sync.RWMutex
|
||||
data []Rejection
|
||||
}
|
||||
|
||||
|
@ -31,6 +33,9 @@ func NewRejectionReasons() *RejectionReasons {
|
|||
}
|
||||
|
||||
func (r *RejectionReasons) String() string {
|
||||
r.m.RLock()
|
||||
defer r.m.RUnlock()
|
||||
|
||||
if len(r.data) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
@ -53,6 +58,9 @@ func (r *RejectionReasons) String() string {
|
|||
}
|
||||
|
||||
func (r *RejectionReasons) StringTruncated() string {
|
||||
r.m.RLock()
|
||||
defer r.m.RUnlock()
|
||||
|
||||
if len(r.data) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
@ -85,6 +93,9 @@ func (r *RejectionReasons) StringTruncated() string {
|
|||
}
|
||||
|
||||
func (r *RejectionReasons) WriteString() string {
|
||||
r.m.RLock()
|
||||
defer r.m.RUnlock()
|
||||
|
||||
var output []string
|
||||
for _, rejection := range r.data {
|
||||
output = append(output, fmt.Sprintf("[%s] not matching: got %v want: %v", rejection.key, rejection.got, rejection.want))
|
||||
|
@ -94,7 +105,10 @@ func (r *RejectionReasons) WriteString() string {
|
|||
}
|
||||
|
||||
func (r *RejectionReasons) WriteJSON() ([]byte, error) {
|
||||
r.m.RLock()
|
||||
defer r.m.RUnlock()
|
||||
var output map[string]string
|
||||
|
||||
for _, rejection := range r.data {
|
||||
output[rejection.key] = fmt.Sprintf("[%s] not matching: got %v want: %v", rejection.key, rejection.got, rejection.want)
|
||||
}
|
||||
|
@ -103,6 +117,9 @@ func (r *RejectionReasons) WriteJSON() ([]byte, error) {
|
|||
}
|
||||
|
||||
func (r *RejectionReasons) Add(key string, got any, want any) {
|
||||
r.m.Lock()
|
||||
defer r.m.Unlock()
|
||||
|
||||
r.data = append(r.data, Rejection{
|
||||
key: key,
|
||||
got: got,
|
||||
|
@ -111,6 +128,9 @@ func (r *RejectionReasons) Add(key string, got any, want any) {
|
|||
}
|
||||
|
||||
func (r *RejectionReasons) Addf(key string, format string, got any, want any) {
|
||||
r.m.Lock()
|
||||
defer r.m.Unlock()
|
||||
|
||||
r.data = append(r.data, Rejection{
|
||||
key: key,
|
||||
format: format,
|
||||
|
@ -120,6 +140,9 @@ func (r *RejectionReasons) Addf(key string, format string, got any, want any) {
|
|||
}
|
||||
|
||||
func (r *RejectionReasons) AddTruncated(key string, got any, want any) {
|
||||
r.m.Lock()
|
||||
defer r.m.Unlock()
|
||||
|
||||
switch wanted := want.(type) {
|
||||
case string:
|
||||
if len(wanted) > 1024 {
|
||||
|
@ -139,5 +162,7 @@ func (r *RejectionReasons) AddTruncated(key string, got any, want any) {
|
|||
|
||||
// Clear rejections
|
||||
func (r *RejectionReasons) Clear() {
|
||||
r.m.Lock()
|
||||
defer r.m.Unlock()
|
||||
r.data = make([]Rejection, 0)
|
||||
}
|
||||
|
|
|
@ -46,70 +46,71 @@ type ReleaseRepo interface {
|
|||
}
|
||||
|
||||
type Release struct {
|
||||
ID int64 `json:"id"`
|
||||
FilterStatus ReleaseFilterStatus `json:"filter_status"`
|
||||
Rejections []string `json:"rejections"`
|
||||
Indexer IndexerMinimal `json:"indexer"`
|
||||
FilterName string `json:"filter"`
|
||||
Protocol ReleaseProtocol `json:"protocol"`
|
||||
Implementation ReleaseImplementation `json:"implementation"` // irc, rss, api
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
AnnounceType AnnounceType `json:"announce_type"`
|
||||
InfoURL string `json:"info_url"`
|
||||
DownloadURL string `json:"download_url"`
|
||||
MagnetURI string `json:"-"`
|
||||
GroupID string `json:"group_id"`
|
||||
TorrentID string `json:"torrent_id"`
|
||||
TorrentTmpFile string `json:"-"`
|
||||
TorrentDataRawBytes []byte `json:"-"`
|
||||
TorrentHash string `json:"-"`
|
||||
TorrentName string `json:"name"` // full release name
|
||||
Size uint64 `json:"size"`
|
||||
Title string `json:"title"` // Parsed title
|
||||
Description string `json:"-"`
|
||||
Category string `json:"category"`
|
||||
Categories []string `json:"categories,omitempty"`
|
||||
Season int `json:"season"`
|
||||
Episode int `json:"episode"`
|
||||
Year int `json:"year"`
|
||||
Month int `json:"month"`
|
||||
Day int `json:"day"`
|
||||
Resolution string `json:"resolution"`
|
||||
Source string `json:"source"`
|
||||
Codec []string `json:"codec"`
|
||||
Container string `json:"container"`
|
||||
HDR []string `json:"hdr"`
|
||||
Audio []string `json:"-"`
|
||||
AudioChannels string `json:"-"`
|
||||
AudioFormat string `json:"-"`
|
||||
Bitrate string `json:"-"`
|
||||
Group string `json:"group"`
|
||||
Region string `json:"-"`
|
||||
Language []string `json:"-"`
|
||||
Proper bool `json:"proper"`
|
||||
Repack bool `json:"repack"`
|
||||
Website string `json:"website"`
|
||||
Artists string `json:"-"`
|
||||
Type string `json:"type"` // Album,Single,EP
|
||||
LogScore int `json:"-"`
|
||||
HasCue bool `json:"-"`
|
||||
HasLog bool `json:"-"`
|
||||
Origin string `json:"origin"` // P2P, Internal
|
||||
Tags []string `json:"-"`
|
||||
ReleaseTags string `json:"-"`
|
||||
Freeleech bool `json:"-"`
|
||||
FreeleechPercent int `json:"-"`
|
||||
Bonus []string `json:"-"`
|
||||
Uploader string `json:"uploader"`
|
||||
PreTime string `json:"pre_time"`
|
||||
Other []string `json:"-"`
|
||||
RawCookie string `json:"-"`
|
||||
Seeders int `json:"-"`
|
||||
Leechers int `json:"-"`
|
||||
AdditionalSizeCheckRequired bool `json:"-"`
|
||||
FilterID int `json:"-"`
|
||||
Filter *Filter `json:"-"`
|
||||
ActionStatus []ReleaseActionStatus `json:"action_status"`
|
||||
ID int64 `json:"id"`
|
||||
FilterStatus ReleaseFilterStatus `json:"filter_status"`
|
||||
Rejections []string `json:"rejections"`
|
||||
Indexer IndexerMinimal `json:"indexer"`
|
||||
FilterName string `json:"filter"`
|
||||
Protocol ReleaseProtocol `json:"protocol"`
|
||||
Implementation ReleaseImplementation `json:"implementation"` // irc, rss, api
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
AnnounceType AnnounceType `json:"announce_type"`
|
||||
InfoURL string `json:"info_url"`
|
||||
DownloadURL string `json:"download_url"`
|
||||
MagnetURI string `json:"-"`
|
||||
GroupID string `json:"group_id"`
|
||||
TorrentID string `json:"torrent_id"`
|
||||
TorrentTmpFile string `json:"-"`
|
||||
TorrentDataRawBytes []byte `json:"-"`
|
||||
TorrentHash string `json:"-"`
|
||||
TorrentName string `json:"name"` // full release name
|
||||
Size uint64 `json:"size"`
|
||||
Title string `json:"title"` // Parsed title
|
||||
Description string `json:"-"`
|
||||
Category string `json:"category"`
|
||||
Categories []string `json:"categories,omitempty"`
|
||||
Season int `json:"season"`
|
||||
Episode int `json:"episode"`
|
||||
Year int `json:"year"`
|
||||
Month int `json:"month"`
|
||||
Day int `json:"day"`
|
||||
Resolution string `json:"resolution"`
|
||||
Source string `json:"source"`
|
||||
Codec []string `json:"codec"`
|
||||
Container string `json:"container"`
|
||||
HDR []string `json:"hdr"`
|
||||
Audio []string `json:"-"`
|
||||
AudioChannels string `json:"-"`
|
||||
AudioFormat string `json:"-"`
|
||||
Bitrate string `json:"-"`
|
||||
Group string `json:"group"`
|
||||
Region string `json:"-"`
|
||||
Language []string `json:"-"`
|
||||
Proper bool `json:"proper"`
|
||||
Repack bool `json:"repack"`
|
||||
Website string `json:"website"`
|
||||
Artists string `json:"-"`
|
||||
Type string `json:"type"` // Album,Single,EP
|
||||
LogScore int `json:"-"`
|
||||
HasCue bool `json:"-"`
|
||||
HasLog bool `json:"-"`
|
||||
Origin string `json:"origin"` // P2P, Internal
|
||||
Tags []string `json:"-"`
|
||||
ReleaseTags string `json:"-"`
|
||||
Freeleech bool `json:"-"`
|
||||
FreeleechPercent int `json:"-"`
|
||||
Bonus []string `json:"-"`
|
||||
Uploader string `json:"uploader"`
|
||||
PreTime string `json:"pre_time"`
|
||||
Other []string `json:"-"`
|
||||
RawCookie string `json:"-"`
|
||||
Seeders int `json:"-"`
|
||||
Leechers int `json:"-"`
|
||||
AdditionalSizeCheckRequired bool `json:"-"`
|
||||
AdditionalUploaderCheckRequired bool `json:"-"`
|
||||
FilterID int `json:"-"`
|
||||
Filter *Filter `json:"-"`
|
||||
ActionStatus []ReleaseActionStatus `json:"action_status"`
|
||||
}
|
||||
|
||||
func (r *Release) Raw(s string) rls.Release {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue