46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package premium
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/debridmediamanager/zurg/pkg/logutil"
|
|
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
|
)
|
|
|
|
const (
|
|
PREMIUM_THRESHOLD = 172800 // 2 days
|
|
MINIMUM_SLEEP = 60 // 60 seconds
|
|
)
|
|
|
|
func MonitorPremiumStatus(rd *realdebrid.RealDebrid, zurglog *logutil.Logger) {
|
|
go func() {
|
|
for {
|
|
userInfo, err := rd.GetUserInformation()
|
|
if err != nil {
|
|
zurglog.Errorf("Failed to get user information: %v", err)
|
|
time.Sleep(5 * time.Minute)
|
|
continue
|
|
}
|
|
if userInfo.Premium <= MINIMUM_SLEEP {
|
|
zurglog.Fatal("Your account is no longer premium, exiting...")
|
|
} else {
|
|
if userInfo.Premium <= PREMIUM_THRESHOLD {
|
|
zurglog.Warnf("Your account will expire in %d hours", userInfo.Premium/3600)
|
|
} else {
|
|
zurglog.Infof("Your account will expire in %d days", userInfo.Premium/86400)
|
|
}
|
|
}
|
|
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)
|
|
}
|
|
}()
|
|
}
|