diff --git a/README.md b/README.md index 9d5f45d..e8eff96 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ Control Jellyfin music playback from your Pebble with an iPod-like interface. - ⛔ = unsupported (does not work well or at all with `jellyPod`) ## iOS - ✅ [Finamp Beta/Redesign](https://github.com/finamp-app/finamp/tree/redesign) (last tested release: 1.0.1) +## MacOS +- ✅ [Finamp Beta/Redesign](https://github.com/finamp-app/finamp/tree/redesign) (last tested release: 1.0.1) # Opinionated Design Philosophy I made `jellyPod` to suite my tastes. Everything listed below is non-negotiable and will not be changed. diff --git a/src/pkjs/index.js b/src/pkjs/index.js index 89e7748..00cafe7 100644 --- a/src/pkjs/index.js +++ b/src/pkjs/index.js @@ -25,8 +25,7 @@ Pebble.addEventListener("ready", function () { const libObj = JSON.parse(libResp); // format response for jellyPod - //// build tracks array and lookupMap (currently just binds alpha to artists) - let jpTracksArr = []; + //// build lookupMap const lookupMap = new Map(); let lastAlbumInfo = {AlbumArtist: "", AlbumName: "", AlbumYear: 0}; for (const track of libObj.Items) { @@ -40,23 +39,25 @@ Pebble.addEventListener("ready", function () { } const albumName = track.Album ? track.Album : "unknown album"; - // register album in lookupMap whenever the album changes (new artist OR new album) - if (lastAlbumInfo.AlbumArtist !== albumArtist || lastAlbumInfo.AlbumName !== albumName) { - const firstChar = Array.from(albumArtist)[0].toUpperCase(); - if (!lookupMap.has(firstChar)) { - lookupMap.set(firstChar, new Map()); - } - const artistMap = lookupMap.get(firstChar); - if (!artistMap.has(albumArtist)) { - artistMap.set(albumArtist, []); - } - const albums = artistMap.get(albumArtist); - if (!albums.includes(albumName)) { - albums.push(albumName); - } + // insert every track into lookupMap + const firstChar = Array.from(albumArtist)[0].toUpperCase(); + if (!lookupMap.has(firstChar)) { + lookupMap.set(firstChar, new Map()); } + const artistToAlbumsMap = lookupMap.get(firstChar); + if (!artistToAlbumsMap.has(albumArtist)) { + artistToAlbumsMap.set(albumArtist, new Map()); + } + const albumToTracksMap = artistToAlbumsMap.get(albumArtist); + if (!albumToTracksMap.has(albumName)) { + albumToTracksMap.set(albumName, []); + } + albumToTracksMap.get(albumName).push({ + TrackName: track.Name, + JfId: track.Id + }); - // keep lastAlbumInfo in sync for every album change + // consider the album to have changed if the album name OR artist changed if (lastAlbumInfo.AlbumArtist !== albumArtist || lastAlbumInfo.AlbumName !== albumName) { lastAlbumInfo = { AlbumArtist: albumArtist, @@ -64,17 +65,9 @@ Pebble.addEventListener("ready", function () { AlbumYear: track.ProductionYear ? track.ProductionYear : 1970 }; } - - jpTracksArr.push({ - TrackName: track.Name, - JfId: track.Id, - AlbumInfo: lastAlbumInfo - }); } - //console.log(jpTracksArr); - //console.log("Items:", libObj.Items.length, "Tracks:", jpTracksArr.length); - console.log(JSON.stringify([...lookupMap].map(([ch, m]) => [ch, [...m]]))); + //console.log(JSON.stringify(lookupMap, (k, v) => v instanceof Map ? Object.fromEntries(v) : v)); Pebble.sendAppMessage({ PKJS_READY: 1 }); });