jukebox
All repositories: gitoria
2.7 KB
// lib/albums.hl — WHAT MAKES ONE ALBUM: album artist (or artist) + album name, with "CD 1", "(Cd2)", "Disc 3" folded into a disc number. The folder is NOT part// of it: the same album sitting in two folders (or one CD per folder) is one album. The scanner (lib/tags.hl), the test database and the key migration// (lib/migrate.hl) all ask here, so a record gets the same keys however it was made.import { fold, safeKey, padNumber, SEP } from './util.hl'static isSep = (c) => {return c == ' ' || c == '-' || c == ',' || c == ':' || c == '(' || c == '[' || c == '_' || c == '–' || c == '—' || c == '/'}static isDigit = (c) => { return c >= '0' && c <= '9' }static isLetter = (c) => { return c.toLowerCase() != c.toUpperCase() }// "BRAVO Hits 19 CD 1" → { name: "BRAVO Hits 19", disc: 1 }; "Best Of (Cd2)" → { name: "Best Of", disc: 2 }; no disc marker → { name: album, disc: null }static splitDisc = (album) => {s = album.trim()let end = s.lengthwhile (end > 0 && (s[end - 1] == ')' || s[end - 1] == ']' || s[end - 1] == ' ')) { end = end - 1 }let d = endwhile (d > 0 && isDigit(s[d - 1])) { d = d - 1 }if (d == end || end - d > 2) { return { name = album disc = null } }n = toNumber(s.slice(d, end))let t = dwhile (t > 0 && (s[t - 1] == ' ' || s[t - 1] == '.' || s[t - 1] == '_' || s[t - 1] == '#')) { t = t - 1 }low = s.slice(0, t).toLowerCase()let cut = -1for (token of ['disc', 'disk', 'cd']) {if (cut < 0 && low.endsWith(token)) { cut = low.length - token.length }}if (cut < 0) { return { name = album disc = null } }if (cut > 0 && isLetter(s[cut - 1])) { return { name = album disc = null } }let nameEnd = cutwhile (nameEnd > 0 && isSep(s[nameEnd - 1])) { nameEnd = nameEnd - 1 }if (nameEnd == 0 || n < 1) { return { name = album disc = null } }return { name = s.slice(0, nameEnd).trim() disc = n }}// the album key of a song: folded album artist and folded album name without the disc markerstatic albumKeyOf = (groupArtist, albumName) => {return safeKey(fold(groupArtist) + '|' + fold(albumName))}// the disc number: the tag when it says more than 1, else the marker in the album name, else 1static discFor = (tagDisc, markerDisc) => {if (tagDisc != null && tagDisc > 1) { return tagDisc }if (markerDisc != null) { return markerDisc }return tagDisc == null ? 1 : tagDisc}// the sort keys of a song (artist order and album order), from its folded partsstatic sortKeys = (groupArtist, album, disc, track, title) => {return {sortArtist = safeKey(fold(groupArtist) + SEP + fold(album) + SEP + padNumber(disc, 2) + SEP + padNumber(track, 3) + SEP + fold(title))sortAlbum = safeKey(fold(album) + SEP + fold(groupArtist) + SEP + padNumber(disc, 2) + SEP + padNumber(track, 3) + SEP + fold(title))}}
Branches
Latest commits
- 7eb2898dRecords: mpackdb second-opener rule until day38mre
- b011f98eRecords: style form live on day35mre
- 60d90cb2Records: L1 woken for the restartmre
- 75ae544fRecords: restart waits for the connection to closemre
- e0b75951Records: L1 merged and pushed, restart waits for an open connectionmre
- f2b5db98styles: format styles with nested rules and bare queriesmre
- f036bab4search: format styles with nested rules and bare queriesmre
- ef9a9d4asongs: format styles with nested rules and bare queriesmre
- f22f9aacmain: format styles with nested rules and bare queriesmre
- f56cd7c7Sync icons from 8176eb1 and verify mixed component sourcesmre
- d56e5054Sync theme and shared tokens from layouts 17e0f03mre
- b1362547Re-vendor to Hybriel set day35mre
- 89e10f08Records: mission 002 rollback wordingmre
- 9485dee7Records: mission 002 brief (live step)mre
- 9ba68fe7Records: S1b reviewedmre
- 193dfff1Records: S1 result, S1b startedmre
- 028ed776Records: mission 001 continuation S1bmre
- 1838d7e8Records: S1 startedmre
- a43fca3fRecords: mission 001 decided pointsmre
- 41773828Records: statusmre