Add track listings to lookupMap
This commit is contained in:
1 parent
198f18e5a2
commit
ba4edccb15
2 files changed
+16
-21
No files matched your search
@@ -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`)
|
- ⛔ = unsupported (does not work well or at all with `jellyPod`)
|
||||||
## iOS
|
## iOS
|
||||||
- ✅ [Finamp Beta/Redesign](https://github.com/finamp-app/finamp/tree/redesign) (last tested release: 1.0.1)
|
- ✅ [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
|
# Opinionated Design Philosophy
|
||||||
I made `jellyPod` to suite my tastes. Everything listed below is non-negotiable and will not be changed.
|
I made `jellyPod` to suite my tastes. Everything listed below is non-negotiable and will not be changed.
|
||||||
|
|||||||
+14
-21
@@ -25,8 +25,7 @@ Pebble.addEventListener("ready", function () {
|
|||||||
const libObj = JSON.parse(libResp);
|
const libObj = JSON.parse(libResp);
|
||||||
|
|
||||||
// format response for jellyPod
|
// format response for jellyPod
|
||||||
//// build tracks array and lookupMap (currently just binds alpha to artists)
|
//// build lookupMap
|
||||||
let jpTracksArr = [];
|
|
||||||
const lookupMap = new Map();
|
const lookupMap = new Map();
|
||||||
let lastAlbumInfo = {AlbumArtist: "", AlbumName: "", AlbumYear: 0};
|
let lastAlbumInfo = {AlbumArtist: "", AlbumName: "", AlbumYear: 0};
|
||||||
for (const track of libObj.Items) {
|
for (const track of libObj.Items) {
|
||||||
@@ -40,23 +39,25 @@ Pebble.addEventListener("ready", function () {
|
|||||||
}
|
}
|
||||||
const albumName = track.Album ? track.Album : "unknown album";
|
const albumName = track.Album ? track.Album : "unknown album";
|
||||||
|
|
||||||
// register album in lookupMap whenever the album changes (new artist OR new album)
|
// insert every track into lookupMap
|
||||||
if (lastAlbumInfo.AlbumArtist !== albumArtist || lastAlbumInfo.AlbumName !== albumName) {
|
|
||||||
const firstChar = Array.from(albumArtist)[0].toUpperCase();
|
const firstChar = Array.from(albumArtist)[0].toUpperCase();
|
||||||
if (!lookupMap.has(firstChar)) {
|
if (!lookupMap.has(firstChar)) {
|
||||||
lookupMap.set(firstChar, new Map());
|
lookupMap.set(firstChar, new Map());
|
||||||
}
|
}
|
||||||
const artistMap = lookupMap.get(firstChar);
|
const artistToAlbumsMap = lookupMap.get(firstChar);
|
||||||
if (!artistMap.has(albumArtist)) {
|
if (!artistToAlbumsMap.has(albumArtist)) {
|
||||||
artistMap.set(albumArtist, []);
|
artistToAlbumsMap.set(albumArtist, new Map());
|
||||||
}
|
|
||||||
const albums = artistMap.get(albumArtist);
|
|
||||||
if (!albums.includes(albumName)) {
|
|
||||||
albums.push(albumName);
|
|
||||||
}
|
}
|
||||||
|
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) {
|
if (lastAlbumInfo.AlbumArtist !== albumArtist || lastAlbumInfo.AlbumName !== albumName) {
|
||||||
lastAlbumInfo = {
|
lastAlbumInfo = {
|
||||||
AlbumArtist: albumArtist,
|
AlbumArtist: albumArtist,
|
||||||
@@ -64,17 +65,9 @@ Pebble.addEventListener("ready", function () {
|
|||||||
AlbumYear: track.ProductionYear ? track.ProductionYear : 1970
|
AlbumYear: track.ProductionYear ? track.ProductionYear : 1970
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
jpTracksArr.push({
|
|
||||||
TrackName: track.Name,
|
|
||||||
JfId: track.Id,
|
|
||||||
AlbumInfo: lastAlbumInfo
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log(jpTracksArr);
|
//console.log(JSON.stringify(lookupMap, (k, v) => v instanceof Map ? Object.fromEntries(v) : v));
|
||||||
//console.log("Items:", libObj.Items.length, "Tracks:", jpTracksArr.length);
|
|
||||||
console.log(JSON.stringify([...lookupMap].map(([ch, m]) => [ch, [...m]])));
|
|
||||||
|
|
||||||
Pebble.sendAppMessage({ PKJS_READY: 1 });
|
Pebble.sendAppMessage({ PKJS_READY: 1 });
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user