jukebox
All repositories: gitoria
1.3 KB
// lib/plays.hl — THE JUKEBOX'S OWN PLAY COUNTS. The file's counter (POPM / PCNT) is the starting value and is never written back; every play the jukebox itself// counts adds 1 here, in the jukebox database (table plays, key = the song id). A song's play count for Favourites and sorting is the file's count + this one.import { playsTable } from './db.hl'import { cache, dropOrderCache } from './state.hl'import { songsTable } from './db.hl'// the map song id → counter, loaded once and kept in step with the tablestatic counts = () => {if (cache.jb != null) { return cache.jb }m = {}for (r of playsTable.range('id', null, null)) { m[r.id] = r.count }cache.jb = mreturn m}static jbCount = (id) => {c = counts()[id]return c == null ? 0 : c}// count one play of a song: answers the new counterstatic addPlay = (id, now) => {m = counts()n = (m[id] == null ? 0 : m[id]) + 1if (playsTable.fetch(id) == null) { playsTable.put({ id = id count = n at = now }) } else { playsTable.update(id, { id = id count = n at = now }) }m[id] = ncache.jb = mreturn n}// the browser says a song was listened to long enough: count it. Answers { id, filePlays, jukeboxPlays } or null for an unknown songstatic countPlay = (id, now) => {s = songsTable.fetch(id)if (s == null) { return null }n = addPlay(s.id, now)dropOrderCache()return { id = s.id filePlays = s.playCount jukeboxPlays = n }}
Branches
Latest commits
- 59c1373ejukebox JB3 (work in progress): albums without folder and with disc markers folded, compilations, duplicate songs, own play counter, server-side shuffle queuemre
- 2a4cfc55jukebox: library screens (songs, artists, albums, artist, album, search, favourites), compact player bar, /stream with Range, thumbnails, virtual list vendored, ui gate and real-library checkmre
- 93a44212jukebox: report, numbers of the full scan, notes on the index key rulemre
- bf5167dajukebox: index keys without commas (mpackdb loses them after a reopen), comma fixture and gate checksmre
- 28a82fa2jukebox: README, STATUS, LOG, DECISIONSmre
- d13987dfjukebox: library scanner, ID3 reader, mpackdb database and JSON API, with fixtures and a gatemre