mirror of
https://git.wetfence.xyz/RandyTheSilly/jellyPod.git
synced 2026-10-26 23:39:56 -04:00
Add track listings to lookupMap
This commit is contained in:
1 parent
198f18e5a2
commit
ba4edccb15
2 files changed
+21
-26
No files matched your search
+19
-26
@@ -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 });
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user