gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchday418ed6da45|||PR README: media-player pin df9e7dfmreday41/lib/plays.hl

1.3 KB

  1. // 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
  2. // 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.
  3. import { playsTable } from './db.hl'
  4. import { cache, dropOrderCache } from './state.hl'
  5. import { songsTable } from './db.hl'
  6. // the map song id → counter, loaded once and kept in step with the table
  7. static counts = () => {
  8. if (cache.jb != null) { return cache.jb }
  9. m = {}
  10. for (r of playsTable.range('id', null, null)) { m[r.id] = r.count }
  11. cache.jb = m
  12. return m
  13. }
  14. static jbCount = (id) => {
  15. c = counts()[id]
  16. return c == null ? 0 : c
  17. }
  18. // count one play of a song: answers the new counter
  19. static addPlay = (id, now) => {
  20. m = counts()
  21. n = (m[id] == null ? 0 : m[id]) + 1
  22. if (playsTable.fetch(id) == null) { playsTable.put({ id = id count = n at = now }) } else { playsTable.update(id, { id = id count = n at = now }) }
  23. m[id] = n
  24. cache.jb = m
  25. return n
  26. }
  27. // the browser says a song was listened to long enough: count it. Answers { id, filePlays, jukeboxPlays } or null for an unknown song
  28. static countPlay = (id, now) => {
  29. s = songsTable.fetch(id)
  30. if (s == null) { return null }
  31. n = addPlay(s.id, now)
  32. dropOrderCache()
  33. return { id = s.id filePlays = s.playCount jukeboxPlays = n }
  34. }

Branches

Latest commits

  • 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
  • 277a2722README: provenance linemre
  • 4169ca6aREADME: sync pinmre