Fix logging of premium status

This commit is contained in:
Ben Sarmiento
2024-02-05 20:29:25 +01:00
parent 58332a354b
commit 0a0979a8c5

View File

@@ -7,7 +7,10 @@ import (
"github.com/debridmediamanager/zurg/pkg/realdebrid"
)
const PREMIUM_THRESHOLD = 172800
const (
PREMIUM_THRESHOLD = 172800 // 2 days
MINIMUM_SLEEP = 60 // 60 seconds
)
func MonitorPremiumStatus(rd *realdebrid.RealDebrid, zurglog *logutil.Logger) {
go func() {
@@ -18,7 +21,7 @@ func MonitorPremiumStatus(rd *realdebrid.RealDebrid, zurglog *logutil.Logger) {
time.Sleep(5 * time.Minute)
continue
}
if userInfo.Premium <= 0 {
if userInfo.Premium <= MINIMUM_SLEEP {
zurglog.Fatal("Your account is no longer premium, exiting...")
} else {
if userInfo.Premium <= PREMIUM_THRESHOLD {
@@ -28,6 +31,13 @@ func MonitorPremiumStatus(rd *realdebrid.RealDebrid, zurglog *logutil.Logger) {
}
}
remaining := userInfo.Premium - PREMIUM_THRESHOLD
if remaining < MINIMUM_SLEEP {
// Ensure minimum sleep duration is 60 seconds
remaining = MINIMUM_SLEEP
} else {
// Round up to the nearest multiple of 60 seconds
remaining = ((remaining + MINIMUM_SLEEP - 1) / MINIMUM_SLEEP) * MINIMUM_SLEEP
}
sleepDuration := time.Duration(remaining) * time.Second
time.Sleep(sleepDuration)
}