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
- 277a2722README: provenance linemre
- 4169ca6aREADME: sync pinmre
- a01f3aa8ui gate: back to the top before the sort checks (the screen reopens where it was left)mre
- f7936c20Lists keep their scroll position across a reload (jukebox#20): per-list offsets in storage/ui.json, gate jb20mre
- d67906devirtual-list and icons from components.hybriel e5b98ec (centerId, scrollTop, onScroll)mre
- df7920ceRecords: R3 startedmre
- 0549f038Mission 010: jb20 livemre
- 273494e2STATUS rewrittenmre
- 227c9b96Records: jb19 livemre
- 9f365376README: the bar's controls (jb19)mre
- d18851fdjb19: pressed switches look different (whole selector), queue column cannot widen past the panel, gates follow the new bar (jb3, jb11, jb15)mre
- 82b54c0ejb19: bar Shuffle · Previous · Play · Next · Repeat, no 10 s buttons; Shuffle switch (shuffle from the playing song, back to the list), Repeat off/all/one, both remembered in ui.json; Shuffle my favourites an ordinary button; gate tests/jb19.mjsmre
- ba354710jb19: icons pinned to components.hybriel 46fefaa (shuffle, repeat, repeatOne, prevTrack, nextTrack)mre
- d8e8d059jb19 step 2: media-player from components.hybriel c96709c (skip, repeat options; the end of a song only calls onPlay), sync-components.sh and SOURCE point to it, jb11 counts media loads and metadata writes (from jb21 d3a026e)mre
- 7b048c1bRecords: jb19 done, L2 live stepmre
- 665185aeMission 009: jb19 livemre
- 47b2d3beRecords: P1 resumedmre
- 8e326e94Records: resetKey blockedmre
- f72dd7edRecords: icons comingmre
- b264e5deRecords: P1 icons stopmre