jukebox
All repositories: gitoria
3.0 KB
// lib/db.hl — THE DATABASE: the one place that knows hl:mpackdb. Five tables in storage/mpackdb/:// songs one record per file (lib/tags.hl songFrom) — primary key '@id'; path and folder are NOT indexed (the scanner keeps its own path map; an index key may hold no comma, see lib/util.hl safeKey)// albums derived: primary key = a digest of the albumKey (stable across rebuilds); one per albumKey (artist + album name + folder), rebuilt by lib/library.hl after a scan that changed anything// artists derived: primary key = a digest of the artist key; one per artist, rebuilt the same way// covers the cover cache index: primary key = the content hash, the file is storage/covers/<hash>.<ext>// plays the jukebox's OWN play counter per song id: { id, count, at } (the file's POPM count stays the starting value and is never written back)// scans one record per finished scan (the numbers the stats show)// Everything else asks this file; switching the mpackdb version (README "mpackdb version") means looking only here.import { MPackDB } from 'hl:mpackdb'import { storageDir } from './util.hl'static songsTable = new MPackDB(file = storageDir + '/songs.db', primaryKey = '@id', indexes = ['albumKey', 'artistKey', 'sortArtist', 'sortAlbum', 'sortTitle', 'playCount'])static albumsTable = new MPackDB(file = storageDir + '/albums.db', primaryKey = 'id', indexes = ['!key', 'artistKey', 'sortName'])static artistsTable = new MPackDB(file = storageDir + '/artists.db', primaryKey = 'id', indexes = ['!key', 'sortName'])static coversTable = new MPackDB(file = storageDir + '/covers.db', primaryKey = 'hash')static playsTable = new MPackDB(file = storageDir + '/plays.db', primaryKey = 'id')static scansTable = new MPackDB(file = storageDir + '/scans.db', primaryKey = '@id', indexes = ['at'])// ---- songs -------------------------------------------------------------------------------------------------static songById = (id) => { return songsTable.fetch(id) }// the record is built field by field by the caller (hybriel#23: put() keeps an id the object carries)static addSong = (rec) => { return songsTable.put(rec) }static replaceSong = (id, rec) => { return songsTable.update(id, rec) }static removeSong = (id) => { return songsTable.delete(id) }static songCount = () => { return songsTable.count() }static countOfRows = (rows) => {if (rows == null) { return 0 }n = rows.lengthreturn n == null ? 0 : n}// ---- covers ------------------------------------------------------------------------------------------------static coverByHash = (hash) => { return coversTable.fetch(hash) }static addCover = (hash, ext, mime, size) => { return coversTable.put({ hash = hash ext = ext mime = mime size = size }) }static coverCount = () => { return coversTable.count() }// ---- scans -------------------------------------------------------------------------------------------------static addScan = (rec) => { return scansTable.put(rec) }static lastScan = () => {rows = scansTable.range('at', null, null)n = countOfRows(rows)return n > 0 ? rows[n - 1] : null}
Branches
Latest commits
- 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
- 04f5d9d5Merge branch 'day41' into mainJukebox
- 8ed6da45|||PR README: media-player pin df9e7dfmre
- d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre
- 89cdabb1Vendor Hybriel day41 (57054d9e): plugin dirs, set .somre
- 1fecd6a7Merge branch 'records-day39' into mainJukebox
- d6b3e068|||PR Records: day39 live (PR #2), mission 011 PR step, statusmre
- 5fa19e89Merge branch 'day39' into mainJukebox
- cfe95440|||PR day39 re-vendor: Hybriel 51e921d7 (bin 6b481aa7), ids kebab-case since hybriel#256: quoted state rule and tests use jb-shuffle / jb-repeatmre
- f3614c9bRe-vendor to Hybriel day39 (51e921d7, bin 6b481aa7)mre
- 9f5c6532Merge branch 'status-22-pr' into mainJukebox
- 5838d6c7|||PR STATUS: #22 pending decision, PR-only rulemre
- 29d2029cRecords: PR-only rule (Kunibert)mre
- adacb0abRecords: neutral ticket rule, #22 decision recordedmre
- b2d6f121Records: #308 hold liftedmre
- 7ab67533Records: day39 on hold (hybriel#308)mre
- 22f21739Records: note rebase before mergemre
- f7368ea3Records: mission 011 day39, waits for lisbethmre
- 9515d2cdRecords: jb20 livemre
- 019f6601ui gate: comment names the open bug components#27 (workaround, not fixed)mre