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
- 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
- 33072bb5|||PR Record day72 gates and Chrome proofmre
- 95f2cd73|||PR Use typed parent methods for screen playback and local server facesmre
- 6422a020Sync media-player at 51c3818mre
- b582ba1cVendor complete Hybriel day72 plugin setmre
- 02dccbc9Merge branch 'records-1119' into mainJukebox
- a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
- fc7db075Merge branch 'reconnect-retry' into mainJukebox
- ac6f4c6fL2: plain declaration for a in pickedNextmre
- 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
- 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
- 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
- 1f0cd77bMerge branch 'records-day41' into mainJukebox
- 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
- 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