Trakt lists: keep the Radarr/Sonarr lookups of their titles on disk

Library membership is asked every time via movie?tmdbId= / series?tvdbId=;
only the lookups of titles not in the library are stored (3 days).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 20:48:20 +02:00
co-authored by Claude Opus 5.5
parent a70daaa0a3
commit f0bc284e82
10 changed files with 281 additions and 15 deletions
+36
View File
@@ -169,6 +169,42 @@ func (d *diskCache) savePeople(all map[string]savedPeople) error {
return writeAtomic(d.peoplePath(), data)
}
func (d *diskCache) lookupsPath() string { return filepath.Join(d.dir, "lookups.json") }
// loadLookups reads the stored Radarr/Sonarr lookups that are not too old.
func (d *diskCache) loadLookups() map[string]savedLookup {
out := map[string]savedLookup{}
if d.dir == "" {
return out
}
data, err := os.ReadFile(d.lookupsPath())
if err != nil {
return out
}
var all map[string]savedLookup
if json.Unmarshal(data, &all) != nil {
return out // unreadable: start afresh, it is only a cache
}
for k, l := range all {
if time.Since(l.Saved) <= lookupTTL {
out[k] = l
}
}
return out
}
// saveLookups writes the lookups.
func (d *diskCache) saveLookups(all map[string]savedLookup) error {
if d.dir == "" {
return nil
}
data, err := json.Marshal(all)
if err != nil {
return err
}
return writeAtomic(d.lookupsPath(), data)
}
// writeAtomic writes a file through a temporary file and a rename, creating
// the directory (private) if needed.
func writeAtomic(path string, data []byte) error {