'use client'; import React, { useState, useEffect } from 'react'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Switch } from '@/components/ui/switch'; import { Button } from '@/components/ui/button'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Input } from '@/components/ui/input'; import { FaTags } from 'react-icons/fa'; import { useToast } from '@/hooks/use-toast'; import { AutoTaggingDialog } from './AutoTaggingDialog'; export const AutoTaggingSettings = () => { const { toast } = useToast(); const [isClient, setIsClient] = useState(false); const [autoTaggingEnabled, setAutoTaggingEnabled] = useState(false); const [autoTagDialogOpen, setAutoTagDialogOpen] = useState(false); const [selectedItem, setSelectedItem] = useState({ id: '', name: 'Library', mode: 'artist' as 'track' | 'album' | 'artist' }); const [autoTagOptions, setAutoTagOptions] = useState({ rateLimit: 1000, // milliseconds between requests autoProcess: false, preferLocalMetadata: true, tagsToUpdate: ['title', 'artist', 'album', 'year', 'genre'], }); useEffect(() => { setIsClient(true); // Load saved preferences from localStorage const savedAutoTagging = localStorage.getItem('auto-tagging-enabled'); if (savedAutoTagging !== null) { setAutoTaggingEnabled(savedAutoTagging === 'true'); } // Load saved auto-tag options const savedOptions = localStorage.getItem('auto-tagging-options'); if (savedOptions !== null) { try { setAutoTagOptions(JSON.parse(savedOptions)); } catch (error) { console.error('Failed to parse stored auto-tagging options:', error); } } }, []); const handleAutoTaggingToggle = (enabled: boolean) => { setAutoTaggingEnabled(enabled); if (isClient) { localStorage.setItem('auto-tagging-enabled', enabled.toString()); } toast({ title: enabled ? 'Auto-Tagging Enabled' : 'Auto-Tagging Disabled', description: enabled ? 'Music will be automatically tagged with metadata from MusicBrainz' : 'Auto-tagging has been disabled', }); }; const handleOptionsChange = (key: string, value: unknown) => { setAutoTagOptions(prev => { const newOptions = { ...prev, [key]: value }; if (isClient) { localStorage.setItem('auto-tagging-options', JSON.stringify(newOptions)); } return newOptions; }); }; const handleTagSelectionChange = (tag: string, isSelected: boolean) => { setAutoTagOptions(prev => { const currentTags = [...prev.tagsToUpdate]; const newTags = isSelected ? [...currentTags, tag] : currentTags.filter(t => t !== tag); const newOptions = { ...prev, tagsToUpdate: newTags }; if (isClient) { localStorage.setItem('auto-tagging-options', JSON.stringify(newOptions)); } return newOptions; }); }; const isTagSelected = (tag: string) => { return autoTagOptions.tagsToUpdate.includes(tag); }; return ( <> Auto-Tagging Configure metadata auto-tagging with MusicBrainz

Enable Auto-Tagging

Automatically fetch and apply metadata from MusicBrainz

{autoTaggingEnabled && ( <>
handleOptionsChange('rateLimit', Number(e.target.value))} />

Time between API requests in milliseconds (min: 500ms)

Auto Process Results

Automatically apply best matches without confirmation

handleOptionsChange('autoProcess', checked)} />

Prefer Local Metadata

Keep existing metadata when confidence is low

handleOptionsChange('preferLocalMetadata', checked)} />
{['title', 'artist', 'album', 'year', 'genre', 'albumArtist', 'trackNumber', 'discNumber'].map(tag => (
handleTagSelectionChange(tag, checked)} />
))}
)}

How it works:

  • Metadata is fetched from MusicBrainz when you play tracks
  • Tags can be applied automatically or manually reviewed
  • Right-click on tracks or albums to tag them manually
  • MusicBrainz API has rate limits, so don't set too fast
setAutoTagDialogOpen(false)} mode={selectedItem.mode} itemId={selectedItem.id} itemName={selectedItem.name} /> ); };