mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(filters): implement AnnounceType
(#1837)
* feat(filters): implement AnnounceType * fix: rss tests
This commit is contained in:
parent
ec85d53d8f
commit
f644b3a4d6
12 changed files with 155 additions and 17 deletions
|
@ -53,6 +53,7 @@ type Release struct {
|
|||
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:"-"`
|
||||
|
@ -114,6 +115,56 @@ func (r *Release) Raw(s string) rls.Release {
|
|||
return rls.ParseString(s)
|
||||
}
|
||||
|
||||
type AnnounceType string
|
||||
|
||||
const (
|
||||
// AnnounceTypeNew Default announce type
|
||||
AnnounceTypeNew AnnounceType = "NEW"
|
||||
// AnnounceTypeChecked Checked release
|
||||
AnnounceTypeChecked AnnounceType = "CHECKED"
|
||||
// AnnounceTypePromo Marked as promotion (neutral/half/feeeleech etc.)
|
||||
AnnounceTypePromo AnnounceType = "PROMO"
|
||||
// AnnounceTypePromoGP Marked Golden Popcorn, PTP specific
|
||||
AnnounceTypePromoGP AnnounceType = "PROMO_GP"
|
||||
// AnnounceTypeResurrect Reseeded/revived from dead
|
||||
AnnounceTypeResurrect AnnounceType = "RESURRECTED"
|
||||
)
|
||||
|
||||
func (a AnnounceType) String() string {
|
||||
switch a {
|
||||
case AnnounceTypeNew:
|
||||
return "NEW"
|
||||
case AnnounceTypeChecked:
|
||||
return "CHECKED"
|
||||
case AnnounceTypePromo:
|
||||
return "PROMO"
|
||||
case AnnounceTypePromoGP:
|
||||
return "PROMO_GP"
|
||||
case AnnounceTypeResurrect:
|
||||
return "RESURRECTED"
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// ParseAnnounceType parse AnnounceType from string
|
||||
func ParseAnnounceType(s string) (AnnounceType, error) {
|
||||
switch s {
|
||||
case string(AnnounceTypeNew):
|
||||
return AnnounceTypeNew, nil
|
||||
case string(AnnounceTypeChecked):
|
||||
return AnnounceTypeChecked, nil
|
||||
case string(AnnounceTypePromo):
|
||||
return AnnounceTypePromo, nil
|
||||
case string(AnnounceTypePromoGP):
|
||||
return AnnounceTypePromoGP, nil
|
||||
case string(AnnounceTypeResurrect):
|
||||
return AnnounceTypeResurrect, nil
|
||||
default:
|
||||
return "", fmt.Errorf("invalid AnnounceType: %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
type ReleaseActionStatus struct {
|
||||
ID int64 `json:"id"`
|
||||
Status ReleasePushStatus `json:"status"`
|
||||
|
@ -307,6 +358,7 @@ func NewRelease(indexer IndexerMinimal) *Release {
|
|||
Timestamp: time.Now(),
|
||||
Tags: []string{},
|
||||
Size: 0,
|
||||
AnnounceType: AnnounceTypeNew,
|
||||
}
|
||||
|
||||
return r
|
||||
|
@ -667,7 +719,6 @@ const MagnetURIPrefix = "magnet:?"
|
|||
|
||||
// MapVars map vars from regex captures to fields on release
|
||||
func (r *Release) MapVars(def *IndexerDefinition, varMap map[string]string) error {
|
||||
|
||||
if torrentName, err := getStringMapValue(varMap, "torrentName"); err != nil {
|
||||
return errors.Wrap(err, "failed parsing required field")
|
||||
} else {
|
||||
|
@ -682,6 +733,13 @@ func (r *Release) MapVars(def *IndexerDefinition, varMap map[string]string) erro
|
|||
r.Category = category
|
||||
}
|
||||
|
||||
if announceType, err := getStringMapValue(varMap, "announceTypeEnum"); err == nil {
|
||||
annType, parseErr := ParseAnnounceType(announceType)
|
||||
if parseErr == nil {
|
||||
r.AnnounceType = annType
|
||||
}
|
||||
}
|
||||
|
||||
if freeleech, err := getStringMapValue(varMap, "freeleech"); err == nil {
|
||||
fl := StringEqualFoldMulti(freeleech, "1", "free", "freeleech", "freeleech!", "yes", "VIP", "★")
|
||||
if fl {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue