mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
feat(filters): RED and OPS fetch record label from API (#1881)
* feat(filters): RED and OPS fetch record label from API * test: add record label to RED and OPS test data * refactor: record label check --------- Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
parent
221bc35371
commit
d153ac44b8
16 changed files with 380 additions and 154 deletions
|
@ -144,6 +144,8 @@ type Filter struct {
|
|||
ExceptCategories string `json:"except_categories,omitempty"`
|
||||
MatchUploaders string `json:"match_uploaders,omitempty"`
|
||||
ExceptUploaders string `json:"except_uploaders,omitempty"`
|
||||
MatchRecordLabels string `json:"match_record_labels,omitempty"`
|
||||
ExceptRecordLabels string `json:"except_record_labels,omitempty"`
|
||||
MatchLanguage []string `json:"match_language,omitempty"`
|
||||
ExceptLanguage []string `json:"except_language,omitempty"`
|
||||
Tags string `json:"tags,omitempty"`
|
||||
|
@ -274,6 +276,8 @@ type FilterUpdate struct {
|
|||
ExceptCategories *string `json:"except_categories,omitempty"`
|
||||
MatchUploaders *string `json:"match_uploaders,omitempty"`
|
||||
ExceptUploaders *string `json:"except_uploaders,omitempty"`
|
||||
MatchRecordLabels *string `json:"match_record_labels,omitempty"`
|
||||
ExceptRecordLabels *string `json:"except_record_labels,omitempty"`
|
||||
MatchLanguage *[]string `json:"match_language,omitempty"`
|
||||
ExceptLanguage *[]string `json:"except_language,omitempty"`
|
||||
Tags *string `json:"tags,omitempty"`
|
||||
|
@ -364,6 +368,9 @@ func (f *Filter) Sanitize() error {
|
|||
f.Artists = sanitize.FilterString(f.Artists)
|
||||
f.Albums = sanitize.FilterString(f.Albums)
|
||||
|
||||
f.MatchRecordLabels = sanitize.FilterString(f.MatchRecordLabels)
|
||||
f.ExceptRecordLabels = sanitize.FilterString(f.ExceptRecordLabels)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -465,6 +472,10 @@ func (f *Filter) CheckFilter(r *Release) (*RejectionReasons, bool) {
|
|||
// f.checkUploader sets the rejections
|
||||
}
|
||||
|
||||
if (f.MatchRecordLabels != "" || f.ExceptRecordLabels != "") && !f.checkRecordLabel(r) {
|
||||
// f.checkRecordLabel sets the rejections
|
||||
}
|
||||
|
||||
if len(f.MatchLanguage) > 0 && !sliceContainsSlice(r.Language, f.MatchLanguage) {
|
||||
f.RejectReasons.Add("match language", r.Language, f.MatchLanguage)
|
||||
}
|
||||
|
@ -749,6 +760,26 @@ func (f *Filter) checkUploader(r *Release) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// checkRecordLabel checks if the record label is within the given list.
|
||||
// if the haystack is not empty but the record label is, then a further
|
||||
// investigation is needed
|
||||
func (f *Filter) checkRecordLabel(r *Release) bool {
|
||||
if r.RecordLabel == "" && (r.Indexer.Identifier == "redacted" || r.Indexer.Identifier == "ops") {
|
||||
r.AdditionalRecordLabelCheckRequired = true
|
||||
return true
|
||||
}
|
||||
|
||||
if f.MatchRecordLabels != "" && !contains(r.RecordLabel, f.MatchRecordLabels) {
|
||||
f.RejectReasons.Add("match record labels", r.RecordLabel, f.MatchRecordLabels)
|
||||
}
|
||||
|
||||
if f.ExceptRecordLabels != "" && contains(r.RecordLabel, f.ExceptRecordLabels) {
|
||||
f.RejectReasons.Add("except record labels", r.RecordLabel, f.ExceptRecordLabels)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// IsPerfectFLAC Perfect is "CD FLAC Cue Log 100% Lossless or 24bit Lossless"
|
||||
func (f *Filter) IsPerfectFLAC(r *Release) ([]string, bool) {
|
||||
rejections := []string{}
|
||||
|
@ -1200,6 +1231,20 @@ func (f *Filter) CheckUploader(uploader string) (bool, error) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
func (f *Filter) CheckRecordLabel(recordLabel string) (bool, error) {
|
||||
if f.MatchRecordLabels != "" && !contains(recordLabel, f.MatchRecordLabels) {
|
||||
f.RejectReasons.Add("match record label", recordLabel, f.MatchRecordLabels)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if f.ExceptRecordLabels != "" && contains(recordLabel, f.ExceptRecordLabels) {
|
||||
f.RejectReasons.Add("except record label", recordLabel, f.ExceptRecordLabels)
|
||||
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
|
||||
|
|
|
@ -429,11 +429,12 @@ func (p *IndexerIRCParse) Parse(def *IndexerDefinition, vars map[string]string,
|
|||
}
|
||||
|
||||
type TorrentBasic struct {
|
||||
Id string `json:"Id"`
|
||||
TorrentId string `json:"TorrentId,omitempty"`
|
||||
InfoHash string `json:"InfoHash"`
|
||||
Size string `json:"Size"`
|
||||
Uploader string `json:"Uploader"`
|
||||
Id string `json:"Id"`
|
||||
TorrentId string `json:"TorrentId,omitempty"`
|
||||
InfoHash string `json:"InfoHash"`
|
||||
Size string `json:"Size"`
|
||||
Uploader string `json:"Uploader"`
|
||||
RecordLabel string `json:"RecordLabel"`
|
||||
}
|
||||
|
||||
func (t TorrentBasic) ReleaseSizeBytes() uint64 {
|
||||
|
|
|
@ -32,7 +32,7 @@ type Macro struct {
|
|||
CurrentMonth int
|
||||
CurrentSecond int
|
||||
CurrentYear int
|
||||
Description string
|
||||
Description string
|
||||
DownloadUrl string
|
||||
Episode int
|
||||
FilterID int
|
||||
|
@ -78,6 +78,7 @@ type Macro struct {
|
|||
TorrentTmpFile string
|
||||
Type string
|
||||
Uploader string
|
||||
RecordLabel string
|
||||
Website string
|
||||
Year int
|
||||
Month int
|
||||
|
@ -150,6 +151,7 @@ func NewMacro(release Release) Macro {
|
|||
TorrentTmpFile: release.TorrentTmpFile,
|
||||
Type: release.Type,
|
||||
Uploader: release.Uploader,
|
||||
RecordLabel: release.RecordLabel,
|
||||
Website: release.Website,
|
||||
Year: release.Year,
|
||||
Month: release.Month,
|
||||
|
|
|
@ -46,71 +46,73 @@ 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:"-"`
|
||||
AdditionalUploaderCheckRequired 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"`
|
||||
RecordLabel string `json:"record_label"`
|
||||
PreTime string `json:"pre_time"`
|
||||
Other []string `json:"-"`
|
||||
RawCookie string `json:"-"`
|
||||
Seeders int `json:"-"`
|
||||
Leechers int `json:"-"`
|
||||
AdditionalSizeCheckRequired bool `json:"-"`
|
||||
AdditionalUploaderCheckRequired bool `json:"-"`
|
||||
AdditionalRecordLabelCheckRequired bool `json:"-"`
|
||||
FilterID int `json:"-"`
|
||||
Filter *Filter `json:"-"`
|
||||
ActionStatus []ReleaseActionStatus `json:"action_status"`
|
||||
}
|
||||
|
||||
func (r *Release) Raw(s string) rls.Release {
|
||||
|
@ -846,6 +848,10 @@ func (r *Release) MapVars(def *IndexerDefinition, varMap map[string]string) erro
|
|||
r.Uploader = uploader
|
||||
}
|
||||
|
||||
if recordLabel, err := getStringMapValue(varMap, "recordLabel"); err == nil {
|
||||
r.RecordLabel = recordLabel
|
||||
}
|
||||
|
||||
if torrentSize, err := getStringMapValue(varMap, "torrentSize"); err == nil {
|
||||
// Some indexers like BTFiles announces size with comma. Humanize does not handle that well and strips it.
|
||||
torrentSize = strings.Replace(torrentSize, ",", ".", 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue