Compare commits

...

1 Commits

Author SHA1 Message Date
Jack Dallas
3ec08b5f4a More file matching improvements 2022-08-12 10:58:39 +01:00
3 changed files with 18 additions and 10 deletions

View File

@@ -5,7 +5,6 @@ import (
"math"
"time"
"github.com/jackdallas/premiumizearr/internal/utils"
"github.com/jackdallas/premiumizearr/pkg/premiumizeme"
log "github.com/sirupsen/logrus"
"golift.io/starr"
@@ -84,14 +83,12 @@ func (arr *RadarrArr) HistoryContains(name string) (int64, bool) {
log.Errorf("Radarr [%s]: Failed to get history: %+v", arr.Name, err)
return -1, false
}
log.Trace("Radarr [%s]: Got History, now Locking History", arr.Name)
log.Tracef("Radarr [%s]: Got History, now Locking History", arr.Name)
arr.HistoryMutex.Lock()
defer arr.HistoryMutex.Unlock()
name = utils.StripDownloadTypesExtention(name)
// name = strings.ReplaceAll(name, ".", " ")
for _, item := range his.Records {
if utils.StripDownloadTypesExtention(item.SourceTitle) == name || item.SourceTitle == name {
if CompareFileNamesFuzzy(item.SourceTitle, name) {
return item.ID, true
}
}

View File

@@ -5,7 +5,6 @@ import (
"math"
"time"
"github.com/jackdallas/premiumizearr/internal/utils"
"github.com/jackdallas/premiumizearr/pkg/premiumizeme"
log "github.com/sirupsen/logrus"
"golift.io/starr"
@@ -82,17 +81,16 @@ func (arr *SonarrArr) HistoryContains(name string) (int64, bool) {
if err != nil {
return 0, false
}
log.Trace("Sonarr [%s]: Got History, now Locking History")
log.Tracef("Sonarr [%s]: Got History, now Locking History", arr.Name)
arr.HistoryMutex.Lock()
defer arr.HistoryMutex.Unlock()
name = utils.StripDownloadTypesExtention(name)
for _, item := range his.Records {
if utils.StripDownloadTypesExtention(item.SourceTitle) == name || item.SourceTitle == name {
if CompareFileNamesFuzzy(item.SourceTitle, name) {
return item.ID, true
}
}
log.Tracef("Sonarr [%s]: %s Not in History", name)
log.Tracef("Sonarr [%s]: %s Not in History", arr.Name, name)
return -1, false
}

View File

@@ -1,14 +1,27 @@
package arr
import (
"strings"
"sync"
"time"
"github.com/jackdallas/premiumizearr/internal/utils"
"github.com/jackdallas/premiumizearr/pkg/premiumizeme"
"golift.io/starr/radarr"
"golift.io/starr/sonarr"
)
func CompareFileNamesFuzzy(a, b string) bool {
//strip file extension
a = utils.StripDownloadTypesExtention(a)
b = utils.StripDownloadTypesExtention(b)
//Replace spaces with periods
a = strings.ReplaceAll(a, " ", ".")
b = strings.ReplaceAll(b, " ", ".")
return a == b
}
type IArr interface {
HistoryContains(string) (int64, bool)
MarkHistoryItemAsFailed(int64) error