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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user