feat(library): surface possible duplicate albums
GET /api/library/duplicates groups library items that look like the same release held more than once — sharing a MusicBrainz release-group, or the same artist + edition-normalized title (stripEditionQualifiers), unioned so transitive matches collapse into one group. The (artist,album) unique constraint rules out exact dupes, so these near-dupes are what's worth flagging. /library shows a "Possible duplicates" section; each entry opens the album modal to edit or delete. web 175 tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -32,10 +32,12 @@ const SORTS: { key: SortKey; label: string; cmp: (a: Album, b: Album) => number
|
||||
];
|
||||
|
||||
type Unmatched = { id: string; artist: string; album: string; path: string; reason: string };
|
||||
type DupItem = { id: string; artist: string; album: string; format: string; qualityClass: number; year: string | null };
|
||||
|
||||
export function LibraryClient() {
|
||||
const [albums, setAlbums] = useState<Album[]>([]);
|
||||
const [unmatched, setUnmatched] = useState<Unmatched[]>([]);
|
||||
const [duplicates, setDuplicates] = useState<DupItem[][]>([]);
|
||||
const [q, setQ] = useState("");
|
||||
const [sort, setSort] = useState<SortKey>("added");
|
||||
const [open, setOpen] = useState<Album | null>(null);
|
||||
@@ -102,6 +104,9 @@ export function LibraryClient() {
|
||||
fetch("/api/library/unmatched")
|
||||
.then((r) => r.json())
|
||||
.then((d) => setUnmatched(d.unmatched ?? []));
|
||||
fetch("/api/library/duplicates")
|
||||
.then((r) => r.json())
|
||||
.then((d) => setDuplicates(d.duplicates ?? []));
|
||||
}
|
||||
useEffect(() => {
|
||||
refresh();
|
||||
@@ -170,6 +175,43 @@ export function LibraryClient() {
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{duplicates.length > 0 ? (
|
||||
<>
|
||||
<SectionHeader title="Possible duplicates" note={`${duplicates.length}`} />
|
||||
<p className="muted-note">
|
||||
Albums that look like the same release held more than once (same MusicBrainz release,
|
||||
or the same title ignoring edition wording). Open one to edit or delete it.
|
||||
</p>
|
||||
{duplicates.map((group, gi) => (
|
||||
<ul className="list" key={gi} style={{ marginBottom: 10 }}>
|
||||
{group.map((d) => {
|
||||
const album = albums.find((a) => a.id === d.id);
|
||||
return (
|
||||
<li key={d.id} className="list-row">
|
||||
<div className="main">
|
||||
{album ? (
|
||||
<button className="linkish rtitle" onClick={() => show(album)}>
|
||||
{d.artist} — {d.album}
|
||||
</button>
|
||||
) : (
|
||||
<div className="rtitle">{d.artist} — {d.album}</div>
|
||||
)}
|
||||
<div className="rmeta">
|
||||
<span className="score">
|
||||
{d.format}
|
||||
{d.qualityClass >= 3 ? " · hi-res" : ""}
|
||||
{d.year ? ` · ${d.year}` : ""}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
))}
|
||||
</>
|
||||
) : null}
|
||||
|
||||
{unmatched.length > 0 ? (
|
||||
<>
|
||||
<SectionHeader title="Couldn’t match" note={`${unmatched.length}`} />
|
||||
|
||||
Reference in New Issue
Block a user