gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit59c1373e59c1373ejukebox JB3 (work in progress): albums without folder and with disc markers folded, compilations, duplicate songs, own play counter, server-side shuffle queuemre59c1373e/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

  • 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