mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat: improve release parsing and filtering (#257)
* feat(releases): improve parsing * refactor: extend filtering add more tests * feat: improve macro * feat: add and remove fields * feat: add freeleech percent to bonus * feat: filter by origin
This commit is contained in:
parent
bb62e724a1
commit
e6c151a029
26 changed files with 3210 additions and 3201 deletions
|
@ -98,21 +98,21 @@ func (a *announceProcessor) processQueue(queue chan string) {
|
|||
continue
|
||||
}
|
||||
|
||||
newRelease, err := domain.NewRelease(a.indexer.Identifier, "")
|
||||
rls, err := domain.NewRelease(a.indexer.Identifier)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not create new release")
|
||||
continue
|
||||
}
|
||||
|
||||
// on lines matched
|
||||
err = a.onLinesMatched(a.indexer, tmpVars, newRelease)
|
||||
err = a.onLinesMatched(a.indexer, tmpVars, rls)
|
||||
if err != nil {
|
||||
log.Debug().Msgf("error match line: %v", "")
|
||||
continue
|
||||
}
|
||||
|
||||
// process release in a new go routine
|
||||
go a.releaseSvc.Process(newRelease)
|
||||
go a.releaseSvc.Process(rls)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,24 +166,24 @@ func (a *announceProcessor) parseExtract(pattern string, vars []string, tmpVars
|
|||
}
|
||||
|
||||
// onLinesMatched process vars into release
|
||||
func (a *announceProcessor) onLinesMatched(def domain.IndexerDefinition, vars map[string]string, release *domain.Release) error {
|
||||
func (a *announceProcessor) onLinesMatched(def domain.IndexerDefinition, vars map[string]string, rls *domain.Release) error {
|
||||
var err error
|
||||
|
||||
err = release.MapVars(def, vars)
|
||||
err = rls.MapVars(def, vars)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("announce: could not map vars for release")
|
||||
return err
|
||||
}
|
||||
|
||||
// parse fields
|
||||
err = release.Parse()
|
||||
err = rls.ParseString(rls.TorrentName)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("announce: could not parse release")
|
||||
return err
|
||||
}
|
||||
|
||||
// parse torrentUrl
|
||||
err = release.ParseTorrentUrl(def.Parse.Match.TorrentURL, vars, def.SettingsMap, def.Parse.Match.Encode)
|
||||
err = def.Parse.ParseTorrentUrl(vars, def.SettingsMap, rls)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("announce: could not parse torrent url")
|
||||
return err
|
||||
|
@ -235,41 +235,6 @@ func (a *announceProcessor) processTorrentUrl(match string, vars map[string]stri
|
|||
return b.String(), nil
|
||||
}
|
||||
|
||||
func split(r rune) bool {
|
||||
return r == ' ' || r == '.'
|
||||
}
|
||||
|
||||
func Splitter(s string, splits string) []string {
|
||||
m := make(map[rune]int)
|
||||
for _, r := range splits {
|
||||
m[r] = 1
|
||||
}
|
||||
|
||||
splitter := func(r rune) bool {
|
||||
return m[r] == 1
|
||||
}
|
||||
|
||||
return strings.FieldsFunc(s, splitter)
|
||||
}
|
||||
|
||||
func canonicalizeString(s string) []string {
|
||||
//a := strings.FieldsFunc(s, split)
|
||||
a := Splitter(s, " .")
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func cleanReleaseName(input string) string {
|
||||
// Make a Regex to say we only want letters and numbers
|
||||
reg, err := regexp.Compile("[^a-zA-Z0-9]+")
|
||||
if err != nil {
|
||||
//log.Fatal(err)
|
||||
}
|
||||
processedString := reg.ReplaceAllString(input, " ")
|
||||
|
||||
return processedString
|
||||
}
|
||||
|
||||
func removeElement(s []string, i int) ([]string, error) {
|
||||
// s is [1,2,3,4,5,6], i is 2
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue