mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-04 03:02:37 -04:00
Mechanical cleanups, no behavior change: - 15 copies of the same id-extraction loop collapse to slice.Map (5 repo mocks, the scanner's track sweep, 4 wantIDs assertions) and slice.ToMap (6 index-by-id loops in the hydration specs). - disc.go built a map[string]bool purely to dedup folder ids and then walked it back into a slice; slice.Unique says that directly. - folders_artist.go's image filter is slice.Filter over model.IsImageFile. - mock_artwork_repo deleted from a map while ranging it; maps.DeleteFunc states the intent. - sort.Slice -> slices.SortFunc + cmp.Or; math.Min/Max -> builtin min/max; make+copy -> bytes.Clone; strings.Split -> SplitSeq on a per-request path; three-clause pixel loops -> for range. - Reuse utils.BaseName where a stem was recomputed by hand. Not at playlist_cover.go:27: that path is a full OS path and utils.BaseName uses path.Base, which does not split backslashes. - Drop a dead nil-guard in agents.go: getAgent returns a bare nil interface, and a type assertion on nil already yields ok == false. cmp.Or was rejected for the gate fallback (func types are not comparable, does not compile) and for ItemArtwork.AttemptedAt (cmp.Or compares time.Time with ==, which includes loc; IsZero does not).
This folder abstracts metadata lookup into "agents". Each agent can be implemented to get as much info as the external source provides, by using a granular set of interfaces (see interfaces).
A new agent must comply with these simple implementation rules:
- Implement the
AgentName()method. It just returns the name of the agent for logging purposes. - Implement one or more of the
*Retriever()interfaces. That's where the agent's logic resides. - Register itself (in its
init()function).
For an agent to be used it needs to be listed in the Agents config option (default is "deezer,lastfm"). The order dictates the priority of the agents
For a simple Agent example, look at the local_agent agent source code.