mirror of
https://github.com/JackDallas/Premiumizearr.git
synced 2026-02-03 13:36:04 +01:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ec08b5f4a | ||
|
|
b4cf1e0a4f |
@@ -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"
|
||||
@@ -18,7 +17,7 @@ import (
|
||||
|
||||
//Data Access
|
||||
|
||||
//GetHistory: Updates the history if it's been more than 15 seconds since last update
|
||||
// GetHistory: Updates the history if it's been more than 15 seconds since last update
|
||||
func (arr *RadarrArr) GetHistory() (radarr.History, error) {
|
||||
arr.LastUpdateMutex.Lock()
|
||||
defer arr.LastUpdateMutex.Unlock()
|
||||
@@ -78,20 +77,18 @@ func (arr *RadarrArr) GetArrName() string {
|
||||
//Functions
|
||||
|
||||
func (arr *RadarrArr) HistoryContains(name string) (int64, bool) {
|
||||
log.Tracef("Radarr.HistoryContains(): Checking history for %s", name)
|
||||
log.Tracef("Radarr [%s]: Checking history for %s", arr.Name, name)
|
||||
his, err := arr.GetHistory()
|
||||
if err != nil {
|
||||
log.Errorf("Radarr.HistoryContains(): Failed to get history: %+v", err)
|
||||
log.Errorf("Radarr [%s]: Failed to get history: %+v", arr.Name, err)
|
||||
return -1, false
|
||||
}
|
||||
log.Trace("Radarr.HistoryContains(): Got History, now Locking History")
|
||||
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 item.SourceTitle == name {
|
||||
if CompareFileNamesFuzzy(item.SourceTitle, name) {
|
||||
return item.ID, true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
@@ -18,7 +17,7 @@ import (
|
||||
|
||||
//Data Access
|
||||
|
||||
//GetHistory: Updates the history if it's been more than 15 seconds since last update
|
||||
// GetHistory: Updates the history if it's been more than 15 seconds since last update
|
||||
func (arr *SonarrArr) GetHistory() (sonarr.History, error) {
|
||||
arr.LastUpdateMutex.Lock()
|
||||
defer arr.LastUpdateMutex.Unlock()
|
||||
@@ -77,22 +76,21 @@ func (arr *SonarrArr) GetArrName() string {
|
||||
// Functions
|
||||
|
||||
func (arr *SonarrArr) HistoryContains(name string) (int64, bool) {
|
||||
log.Tracef("Sonarr.HistoryContains(): Checking history for %s", name)
|
||||
log.Tracef("Sonarr [%s]: Checking history for %s", arr.Name, name)
|
||||
his, err := arr.GetHistory()
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
log.Trace("Sonarr.HistoryContains(): 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 {
|
||||
if CompareFileNamesFuzzy(item.SourceTitle, name) {
|
||||
return item.ID, true
|
||||
}
|
||||
}
|
||||
log.Tracef("Sonarr.HistoryContains(): %s Not in History", name)
|
||||
log.Tracef("Sonarr [%s]: %s Not in History", arr.Name, name)
|
||||
|
||||
return -1, false
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user