Files
muse/web/components/bulk-import.tsx
Aryan SinghandClaude Opus 5 171e117f7c Recover blocked searches, fall through to the next peer, rebuild the UI
Measured against a live instance: 47 failed jobs against 33 imported. Three
independent causes, all of which ended the request.

The Soulseek server filters some artist names. "Michael Jackson Billie Jean"
and bare "Michael Jackson" both return zero responses; "Billie Jean" returns
1083 files. The Weeknd, Kanye West and Frank Ocean behave the same way. Since
pick_and_enqueue sent exactly one query of `artist title`, every request for a
filtered artist failed reporting "searched 0 files" -- 28 of 29 occurrences.
search_queries() now walks a ladder, loosest last, ending at the bare title,
and escalates only when a search underdelivers so the common case still costs
one search. Dropping the artist from the query does not mean ignoring it:
match_ratio() looks for it in the folder path, where an organised share puts it.

A rejected transfer ended the request. pick_and_enqueue kept a running maximum
and discarded every runner-up, so "Transfer rejected: File not shared." -- a
per-file condition where candidate two almost always works -- was terminal, as
were timeouts and slskd's 500 on an unreachable peer. The ranked list is now
persisted on the job row, ordered to put a different peer next, and
try_next_candidate() advances through it. A job fails only once the list is
exhausted, and then reports every peer it tried and what each one said.

norm() destroyed every non-ASCII character, so "Beyonce" never matched
Beyonce, nor Bjork Bjork, nor Dont Don't. It now folds accents and drops
apostrophes while leaving & as a separator.

Also: availability outranks format in score(), because a FLAC behind 5000
queued users used to beat an immediately available MP3; transfers that stall or
that slskd forgets are abandoned instead of sitting in `downloading` forever;
searches are deleted only once finished, since deleting one mid-flight makes
slskd throw an optimistic-concurrency error and lose the record; a failed
search POST is retried rather than failing the job on one blip.

The UI moves to a sidebar shell -- rail at tablet, bottom bar on phones -- with
neutral chrome and the sampled artwork colour confined to hero areas rather
than repainting the whole interface. Adds URL routing, a primitive set under
components/ui, and a request sheet showing the attempt ladder. Fixes
hover:bg-glass-hi, which was never a valid class, so track rows and the search
field had no hover or focus state at all; a reduced-motion path that could
strand elements at opacity 0; the login page's hardcoded palette; and the
missing 404 and error boundaries.

tests/test_acquisition.py covers this path against a faked slskd. It had none.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-02 11:29:59 -05:00

127 lines
4.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import * as React from "react";
import { AnimatePresence, motion } from "framer-motion";
import { ArrowRight } from "lucide-react";
import { api } from "@/lib/api";
import { useToast } from "@/components/toast";
import { Button } from "@/components/ui/button";
type Result = Awaited<ReturnType<typeof api.importList>>;
const PLACEHOLDER = `Radiohead - Creep
Juice WRLD – Lucid Dreams
3. Gorillaz - Feel Good Inc
Black Hole Sun by Soundgarden
https://deezer.com/album/14880711`;
export function BulkImport({ onQueued }: { onQueued?: () => void }) {
const toast = useToast();
const [text, setText] = React.useState("");
const [busy, setBusy] = React.useState(false);
const [out, setOut] = React.useState<Result | null>(null);
const run = async () => {
const t = text.trim();
if (!t) {
toast("Paste some songs first", true);
return;
}
setBusy(true);
setOut(null);
try {
const d = await api.importList(t);
setOut(d);
if (d.queued.length) {
setText("");
toast(`Queued ${d.queued.length} tracks`);
onQueued?.();
}
} catch (e) {
toast(`Import failed: ${(e as Error).message}`, true);
}
setBusy(false);
};
return (
<motion.div
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
className="card rounded-panel p-5"
>
<h2 className="mb-1 text-headline font-bold tracking-[-0.3px]">Import a list</h2>
<p className="mb-3.5 max-w-[62ch] text-callout text-dim">
One song per line. Deezer album and playlist URLs are expanded into their tracks. The
top match is taken automatically — every job shows what it resolved to, so a bad pick is
visible rather than silent.
</p>
<textarea
value={text}
onChange={(e) => setText(e.target.value)}
spellCheck={false}
placeholder={PLACEHOLDER}
className="min-h-[170px] w-full resize-y rounded-card border border-edge
bg-black/20 dark:bg-black/20 p-3.5 font-mono text-[13px] leading-[1.7]
text-ink outline-none transition
placeholder:text-dim/65
focus:border-accent-line focus:shadow-[0_0_0_4px_var(--color-accent-soft)]"
/>
<div className="mt-3 flex flex-wrap items-center gap-3">
<Button onClick={run} disabled={busy}>
{busy ? "Queueing…" : "Queue all"}
</Button>
<span className="text-callout text-dim">
Top match taken automatically — check what each line resolved to.
</span>
</div>
<AnimatePresence>
{out && (
<motion.div
initial={{ opacity: 0, height: 0 }}
animate={{ opacity: 1, height: "auto" }}
exit={{ opacity: 0, height: 0 }}
className="mt-3.5 overflow-hidden"
>
{out.queued.length > 0 && (
<>
<div className="mb-1 text-callout text-dim">Queued {out.queued.length}:</div>
{out.queued.map((q, i) => (
<motion.div
key={q.id}
initial={{ opacity: 0, x: -8 }}
animate={{ opacity: 1, x: 0 }}
transition={{ delay: Math.min(i * 0.03, 0.5) }}
className="flex items-center gap-2.5 border-b border-edge py-1.5 text-callout last:border-0"
>
{q.cover && (
/* eslint-disable-next-line @next/next/no-img-element */
<img
src={q.cover}
alt=""
loading="lazy"
className="h-[30px] w-[30px] shrink-0 rounded-md bg-faint object-cover"
/>
)}
<span className="shrink-0 text-dim">{q.line}</span>
<ArrowRight className="h-3 w-3 shrink-0 text-dim opacity-50" />
<span className="clamp1">{q.matched}</span>
</motion.div>
))}
</>
)}
{out.skipped.length > 0 && (
<div className="mt-2.5 text-callout leading-[1.7] text-err">
Skipped {out.skipped.length}:{" "}
{out.skipped.map((s) => `${s.line} (${s.why})`).join("; ")}
</div>
)}
</motion.div>
)}
</AnimatePresence>
</motion.div>
);
}