package premium import ( "time" "github.com/debridmediamanager/zurg/pkg/logutil" "github.com/debridmediamanager/zurg/pkg/realdebrid" "github.com/panjf2000/ants/v2" ) const ( PREMIUM_THRESHOLD = 172800 // 2 days MINIMUM_SLEEP = 60 // 60 seconds ) func MonitorPremiumStatus(workerPool *ants.Pool, rd *realdebrid.RealDebrid, zurglog *logutil.Logger) { userInfo, err := rd.GetUserInformation() if err != nil { zurglog.Fatalf("Failed to get user information: %v", err) } workerPool.Submit(func() { for { 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) // fetch user information again userInfo, err = rd.GetUserInformation() if err != nil { zurglog.Errorf("Failed to get user information: %v", err) time.Sleep(5 * time.Minute) continue } } }) }