diff --git a/src/App.tsx b/src/App.tsx index fb12c79..49f346b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -26,6 +26,34 @@ interface Song { id: string; title: string; artist: string; + composer?: string; + album?: string; + grouping?: string; + genre?: string; + kind?: string; + size?: string; + totalTime?: string; + discNumber?: string; + trackNumber?: string; + year?: string; + averageBpm?: string; + dateAdded?: string; + bitRate?: string; + sampleRate?: string; + comments?: string; + playCount?: string; + rating?: string; + location?: string; + remixer?: string; + tonality?: string; + label?: string; + mix?: string; + tempo?: { + inizio?: string; + bpm?: string; + metro?: string; + battito?: string; + }; } interface Playlist { @@ -51,16 +79,44 @@ export default function RekordboxReader() { const result = await parseStringPromise(xmlText); console.log("Parsed XML:", result); - const tracks: Song[] = result.DJ_PLAYLISTS?.COLLECTION?.[0]?.TRACK?.map((track: any) => ({ + const tracks: Song[] = result.DJ_PLAYLISTS.COLLECTION[0].TRACK.map((track: any) => ({ id: track.$.TrackID, title: track.$.Name, artist: track.$.Artist, - })) || []; + composer: track.$.Composer, + album: track.$.Album, + grouping: track.$.Grouping, + genre: track.$.Genre, + kind: track.$.Kind, + size: track.$.Size, + totalTime: track.$.TotalTime, + discNumber: track.$.DiscNumber, + trackNumber: track.$.TrackNumber, + year: track.$.Year, + averageBpm: track.$.AverageBpm, + dateAdded: track.$.DateAdded, + bitRate: track.$.BitRate, + sampleRate: track.$.SampleRate, + comments: track.$.Comments, + playCount: track.$.PlayCount, + rating: track.$.Rating, + location: track.$.Location, + remixer: track.$.Remixer, + tonality: track.$.Tonality, + label: track.$.Label, + mix: track.$.Mix, + tempo: track.TEMPO ? { + inizio: track.TEMPO[0].$.Inizio, + bpm: track.TEMPO[0].$.Bpm, + metro: track.TEMPO[0].$.Metro, + battito: track.TEMPO[0].$.Battito, + } : undefined, + })); - const lists: Playlist[] = result.DJ_PLAYLISTS?.PLAYLISTS?.[0]?.NODE?.[0]?.NODE?.map((playlist: any) => ({ + const lists: Playlist[] = result.DJ_PLAYLISTS.PLAYLISTS[0].NODE[0].NODE.map((playlist: any) => ({ name: playlist.$.Name, tracks: playlist.TRACK ? playlist.TRACK.map((t: any) => t.$.Key) : [], - })) || []; + })); console.log("Tracks:", tracks); console.log("Playlists:", lists); @@ -100,16 +156,48 @@ export default function RekordboxReader() { const collection = doc.ele("COLLECTION", { Entries: songs.length.toString(), }); - - // Add tracks to the collection + + // Add tracks to the collection with all metadata songs.forEach((song) => { - collection.ele("TRACK", { + const trackElement = collection.ele("TRACK", { TrackID: song.id, Name: song.title, Artist: song.artist, + Composer: song.composer || "", + Album: song.album || "", + Grouping: song.grouping || "", + Genre: song.genre || "", + Kind: song.kind || "", + Size: song.size || "", + TotalTime: song.totalTime || "", + DiscNumber: song.discNumber || "", + TrackNumber: song.trackNumber || "", + Year: song.year || "", + AverageBpm: song.averageBpm || "", + DateAdded: song.dateAdded || "", + BitRate: song.bitRate || "", + SampleRate: song.sampleRate || "", + Comments: song.comments || "", + PlayCount: song.playCount || "", + Rating: song.rating || "", + Location: song.location || "", + Remixer: song.remixer || "", + Tonality: song.tonality || "", + Label: song.label || "", + Mix: song.mix || "", }); + + // Add the TEMPO nested element if available + if (song.tempo) { + trackElement.ele("TEMPO", { + Inizio: song.tempo.inizio || "", + Bpm: song.tempo.bpm || "", + Metro: song.tempo.metro || "", + Battito: song.tempo.battito || "", + }); + } }); - + // Create the playlists structure const playlistsNode = doc.ele("PLAYLISTS"); const playlistsFolder = playlistsNode.ele("NODE", { @@ -117,7 +205,7 @@ export default function RekordboxReader() { Type: "0", Count: playlists.length.toString(), }); - + // Add each playlist and its tracks playlists.forEach((playlist) => { const playlistNode = playlistsFolder.ele("NODE", { @@ -130,14 +218,14 @@ export default function RekordboxReader() { playlistNode.ele("TRACK", { Key: trackId }); }); }); - + // Generate the XML content as a string const xmlContent = doc.end({ prettyPrint: true }); - + // Create a Blob from the XML content const blob = new Blob([xmlContent], { type: "application/xml" }); const url = URL.createObjectURL(blob); - + // Create a download link and trigger the download const a = document.createElement("a"); a.href = url; @@ -145,8 +233,7 @@ export default function RekordboxReader() { document.body.appendChild(a); a.click(); document.body.removeChild(a); - }; - + }; const renderContent = () => { if (selectedItem === "All Songs") {