jukebox
All repositories: gitoria
1.7 KB
// lib/migrate.hl — KEYS FROM AN EARLIER VERSION. Until JB3 an album key held the folder and "CD 1" stayed in the album name, so one album sat in the database twice. `fixKeys` goes// through the songs of a database made before, folds the disc marker out of the album name, gives the song its disc number and rewrites the album key and the two sort keys// (from the stored fields, no file is read). The state is a one-line file `keys-version` in storage/: the work runs once, and is checked again after every change of the rule.import { readFile, writeFile, exists } from 'hl:fs'import { songsTable, replaceSong } from './db.hl'import { storageRoot } from './util.hl'import { splitDisc, albumKeyOf, discFor, sortKeys } from './albums.hl'static version = '3'static marker = storageRoot + '/keys-version'static needsFix = () => {if (!exists(marker)) { return true }return readFile(marker).trim() != version}// answers how many songs changedstatic fixKeys = () => {let changed = 0rows = []for (s of songsTable.iterate(null, null)) { rows.push(s) }for (s of rows) {parts = splitDisc(s.album)disc = discFor(s.disc == 1 && parts.disc == null ? null : s.disc, parts.disc)key = albumKeyOf(s.albumArtist, parts.name)keys = sortKeys(s.albumArtist, parts.name, disc, s.track == null ? 0 : s.track, s.title)if (key == s.albumKey && parts.name == s.album && disc == s.disc && keys.sortArtist == s.sortArtist && keys.sortAlbum == s.sortAlbum) { continue }rec = {}for (k in s) {if (k != 'id') { rec[k] = s[k] }}rec.album = parts.namerec.albumKey = keyrec.disc = discrec.sortArtist = keys.sortArtistrec.sortAlbum = keys.sortAlbumreplaceSong(s.id, rec)changed = changed + 1}writeFile(marker, version, 420)return changed}
Branches
Latest commits
- 10f8a8c8Merge branch 'code-order' into mainJukebox
- 204fc828Merge branch 'day72' into mainJukebox
- 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