import { Music, Download, CheckCircle } from "lucide-react"; import { cn } from "@/utils/cn"; import { SoulseekResult } from "../types"; interface SoulseekSongsListProps { soulseekResults: SoulseekResult[]; downloadingFiles: Set; onDownload: (result: SoulseekResult) => void; } // Helper function to format file size export const formatFileSize = (bytes: number): string => { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; }; // Helper function to get quality badge export const getQualityBadge = (result: SoulseekResult) => { if (result.format === "flac") { return ( FLAC ); } if (result.bitrate >= 320) { return ( 320 kbps ); } if (result.bitrate >= 256) { return ( 256 kbps ); } return ( {result.bitrate} kbps ); }; // Helper function to parse filename export const parseFilename = ( filename: string ): { artist: string; title: string } => { const match = filename.match(/([^/\\]+)\.(?:mp3|flac|m4a|wav)$/i); if (match) { const nameWithoutExt = match[1]; const parts = nameWithoutExt.split(" - "); if (parts.length >= 2) { return { artist: parts[0].trim(), title: parts.slice(1).join(" - ").trim(), }; } return { artist: "Unknown", title: nameWithoutExt }; } return { artist: "Unknown", title: filename }; }; export function SoulseekSongsList({ soulseekResults, downloadingFiles, onDownload, }: SoulseekSongsListProps) { if (soulseekResults.length === 0) { return null; } return (

Songs

{soulseekResults.slice(0, 5).map((result, index) => { const parsed = result.parsedArtist ? { artist: result.parsedArtist, title: result.filename .split("\\") .pop() ?.split(" - ") .slice(1) .join(" - ") || result.filename, } : parseFilename(result.filename); const isDownloading = downloadingFiles.has(result.filename); return (

{parsed.title}

{parsed.artist}

{getQualityBadge(result)}
); })}
); }