diff --git a/doc/config.full.json b/doc/config.full.json index fa256c7..e6b4d2c 100644 --- a/doc/config.full.json +++ b/doc/config.full.json @@ -5,6 +5,7 @@ "host": "https://api.real-debrid.com/rest/1.0", "api_key": "realdebrid_key", "folder": "/mnt/remote/realdebrid/__all__/", + "download_api_keys": [], "proxy": "", "rate_limit": "250/minute", "download_uncached": false, diff --git a/pkg/debrid/debrid/repair.go b/pkg/debrid/debrid/repair.go index 276a1fd..24e41e2 100644 --- a/pkg/debrid/debrid/repair.go +++ b/pkg/debrid/debrid/repair.go @@ -169,7 +169,6 @@ func (c *Cache) refreshDownloadLink(link string) error { return nil } -func (c *Cache) resetDownloadLinks() { +func (c *Cache) resetInvalidLinks() { c.invalidDownloadLinks = xsync.NewMapOf[string, string]() - c.downloadLinks = xsync.NewMapOf[string, downloadLinkCache]() } diff --git a/pkg/debrid/debrid/worker.go b/pkg/debrid/debrid/worker.go index b4c6c3f..5a63297 100644 --- a/pkg/debrid/debrid/worker.go +++ b/pkg/debrid/debrid/worker.go @@ -6,6 +6,7 @@ func (c *Cache) Refresh() error { // For now, we just want to refresh the listing and download links go c.refreshDownloadLinksWorker() go c.refreshTorrentsWorker() + go c.resetInvalidLinksWorker() return nil } @@ -26,3 +27,49 @@ func (c *Cache) refreshTorrentsWorker() { c.refreshTorrents() } } + +func (c *Cache) resetInvalidLinksWorker() { + // Calculate time until next 12:00 CET + now := time.Now() + loc, err := time.LoadLocation("CET") + if err != nil { + // Fallback if CET timezone can't be loaded + c.logger.Error().Err(err).Msg("Failed to load CET timezone, using local time") + loc = time.Local + } + + nowInCET := now.In(loc) + next := time.Date( + nowInCET.Year(), + nowInCET.Month(), + nowInCET.Day(), + 12, 0, 0, 0, + loc, + ) + + // If it's already past 12:00 CET today, schedule for tomorrow + if nowInCET.After(next) { + next = next.Add(24 * time.Hour) + } + + // Duration until next 12:00 CET + initialWait := next.Sub(nowInCET) + + // Set up initial timer + timer := time.NewTimer(initialWait) + defer timer.Stop() + + c.logger.Debug().Msgf("Scheduled invalid links reset at %s (in %s)", next.Format("2006-01-02 15:04:05 MST"), initialWait) + + // Wait for the first execution + <-timer.C + c.resetInvalidLinks() + + // Now set up the daily ticker + refreshTicker := time.NewTicker(24 * time.Hour) + defer refreshTicker.Stop() + + for range refreshTicker.C { + c.resetInvalidLinks() + } +}