jukebox
All repositories: gitoria
6.6 KB
// tests/make-fixtures.mjs — builds the tiny test mp3s of tests/fixtures: ffmpeg makes one second of audio, the ID3 tags are// built by hand here, byte by byte, so every case of the reader is covered (v2.2, v2.3, v2.4, extended header,// unsynchronisation, several POPM owners, PCNT, APIC, ID3v1 only, no tags). Run: node tests/make-fixtures.mjsimport { execFileSync } from 'node:child_process'import { mkdirSync, writeFileSync, readFileSync, rmSync } from 'node:fs'import { dirname, join } from 'node:path'import { fileURLToPath } from 'node:url'const here = dirname(fileURLToPath(import.meta.url))const out = join(here, 'fixtures')rmSync(out, { recursive: true, force: true })mkdirSync(join(out, 'withcover'), { recursive: true })const tmp = join(out, '.tmp')mkdirSync(tmp, { recursive: true })const ff = (...a) => execFileSync('ffmpeg', ['-v', 'error', '-y', ...a])ff('-f', 'lavfi', '-i', 'sine=frequency=440:duration=1', '-c:a', 'libmp3lame', '-b:a', '64k', '-write_xing', '0', '-id3v2_version', '0', '-write_id3v1', '0', join(tmp, 'audio.mp3'))ff('-f', 'lavfi', '-i', 'color=c=red:s=16x16:d=1', '-frames:v', '1', join(tmp, 'cover.png'))ff('-f', 'lavfi', '-i', 'color=c=blue:s=16x16:d=1', '-frames:v', '1', join(tmp, 'folder.jpg'))const audio = readFileSync(join(tmp, 'audio.mp3'))const png = readFileSync(join(tmp, 'cover.png'))const folderJpg = readFileSync(join(tmp, 'folder.jpg'))const u32 = (n) => Buffer.from([(n >>> 24) & 255, (n >>> 16) & 255, (n >>> 8) & 255, n & 255])const synch = (n) => Buffer.from([(n >>> 21) & 127, (n >>> 14) & 127, (n >>> 7) & 127, n & 127])const latin = (s) => Buffer.from(s, 'latin1')const utf16 = (s) => Buffer.concat([Buffer.from([0xff, 0xfe]), Buffer.from(s, 'utf16le')])const unsync = (b) => { const o = []; for (let i = 0; i < b.length; i++) { o.push(b[i]); if (b[i] === 0xff && (i + 1 === b.length || b[i + 1] === 0 || (b[i + 1] & 0xe0) === 0xe0)) o.push(0) } return Buffer.from(o) }// a frame of version 2 (3-letter id, 3-byte size), 3 or 4const frame = (v, id, body, flags = 0) => {if (v === 2) return Buffer.concat([latin(id), Buffer.from([(body.length >> 16) & 255, (body.length >> 8) & 255, body.length & 255]), body])const size = v === 4 ? synch(body.length) : u32(body.length)return Buffer.concat([latin(id), size, Buffer.from([0, flags]), body])}const text = (v, id, s, enc = 0) => {const data = enc === 0 ? latin(s) : enc === 1 ? utf16(s) : Buffer.from(s, 'utf8')return frame(v, id, Buffer.concat([Buffer.from([enc]), data]))}const popm = (v, id, owner, rating, count) => frame(v, id, Buffer.concat([latin(owner), Buffer.from([0, rating]), count === null ? Buffer.alloc(0) : u32(count)]))const tag = (v, frames, { flags = 0, ext = null, unsyncAll = false, pad = 40 } = {}) => {let body = Buffer.concat([...(ext ? [ext] : []), ...frames])if (unsyncAll) body = unsync(body)body = Buffer.concat([body, Buffer.alloc(pad)])return Buffer.concat([latin('ID3'), Buffer.from([v, 0, flags]), synch(body.length), body])}const put = (path, ...parts) => writeFileSync(join(out, path), Buffer.concat(parts))// 1. v2.3, Latin-1 and UTF-16 texts, genre "(13)", track "3/12", disc "1/2", two POPM owners (7 and 12) and a PCNT of 9put('v23-two-owners.mp3', tag(3, [text(3, 'TIT2', 'Über Song', 1), text(3, 'TPE1', 'Die Ärzte'), text(3, 'TALB', 'Album Eins CD 1'), text(3, 'TRCK', '3/12'),text(3, 'TPOS', '1/2'), text(3, 'TYER', '1999'), text(3, 'TCON', '(13)'),popm(3, 'POPM', 'Banshee', 192, 7), popm(3, 'POPM', 'Guayadeque', 128, 12), frame(3, 'PCNT', u32(9)),]), audio)// 2. v2.4, UTF-8, two artists in one frame (zero separated), TDRC with a full date, album artist, a front cover (PNG), Windows Media Player ratingput('v24-cover.mp3', tag(4, [text(4, 'TIT2', 'Größe Ängste', 3), frame(4, 'TPE1', Buffer.concat([Buffer.from([3]), Buffer.from('Erste Band', 'utf8'), Buffer.from([0]), Buffer.from('Zweite Band', 'utf8')])),text(4, 'TPE2', 'Sammler', 3), text(4, 'TALB', 'Vierer', 3), text(4, 'TDRC', '2005-06-01', 3), text(4, 'TRCK', '11/21', 3), text(4, 'TCON', '49', 0),frame(4, 'APIC', Buffer.concat([Buffer.from([0]), latin('image/png'), Buffer.from([0, 3]), latin('front'), Buffer.from([0]), png])),popm(4, 'POPM', 'Windows Media Player 9 Series', 255, 4),]), audio)// 3. v2.4 with an extended header (flag 0x40, synchsafe size 6, 1 flag byte count, no flags)put('v24-extheader.mp3', tag(4, [text(4, 'TIT2', 'Mit Erweiterung', 3), text(4, 'TPE1', 'Extender', 3), popm(4, 'POPM', 'Banshee', 0, 3)],{ flags: 0x40, ext: Buffer.concat([synch(6), Buffer.from([1, 0])]) }), audio)// 4. v2.3 with unsynchronisation on the whole tag: a POPM counter with 0xFF bytes (255) and a UTF-16 title (byte order mark FF FE)put('v23-unsync.mp3', tag(3, [text(3, 'TIT2', 'Unsynced', 1), text(3, 'TPE1', 'Sync Band', 1), text(3, 'TALB', 'Sync Album'),popm(3, 'POPM', 'Banshee', 255, 255), popm(3, 'POPM', 'Guayadeque', 255, 0x00ff00ff),], { flags: 0x80, unsyncAll: true }), audio)// 5. v2.2 frames (TT2 TP1 TAL TRK TYE TCO POP)put('v22.mp3', tag(2, [text(2, 'TT2', 'Alt'), text(2, 'TP1', 'Old Timer'), text(2, 'TAL', 'Retro'), text(2, 'TRK', '5/9'), text(2, 'TYE', '1994'), text(2, 'TCO', '(17)'),popm(2, 'POP', 'old', 64, 21),]), audio)// 6. PCNT only (no POPM)put('pcnt-only.mp3', tag(3, [text(3, 'TIT2', 'Nur Zähler'), text(3, 'TPE1', 'Counter'), frame(3, 'PCNT', u32(5))]), audio)// 7. ID3v1 only: title, artist, album, year, comment with a track number, genre 17 (Rock)const v1 = Buffer.alloc(128); latin('TAG').copy(v1, 0)latin('Alt Lied').copy(v1, 3); latin('Alte Band').copy(v1, 33); latin('Altes Album').copy(v1, 63); latin('1987').copy(v1, 93); v1[125] = 0; v1[126] = 4; v1[127] = 17put('v1-only.mp3', audio, v1)// 8. no tags at allput('notags.mp3', audio)// 9. no embedded cover, but a folder.jpg next to itput('withcover/song-without-picture.mp3', tag(3, [text(3, 'TIT2', 'Ohne Bild'), text(3, 'TPE1', 'Folder Band'), text(3, 'TALB', 'Folder Album')]), audio)writeFileSync(join(out, 'withcover', 'folder.jpg'), folderJpg)// 9b. commas in title, artist and album (mpackdb loses an indexed value with a comma after a reopen: the sort keys and album keys must not hold one)put('comma.mp3', tag(3, [text(3, 'TIT2', 'Eins, zwei'), text(3, 'TPE1', 'Band, The'), text(3, 'TALB', 'Album, mit Komma'), popm(3, 'POPM', 'Banshee', 128, 2)]), audio)// 10. an ogg file (read with ffprobe) with tagsff('-f', 'lavfi', '-i', 'sine=frequency=330:duration=1', '-c:a', 'libvorbis', '-metadata', 'title=Vogel', '-metadata', 'artist=Ogg Band', '-metadata', 'album=Ogg Album','-metadata', 'date=2011', '-metadata', 'track=2/8', '-metadata', 'genre=Rock', join(out, 'tagged.ogg'))rmSync(tmp, { recursive: true, force: true })console.log('fixtures written to ' + out)
Branches
Latest commits
- a43fca3fRecords: mission 001 decided pointsmre
- 41773828Records: statusmre
- a82c0805Records: mission 001 brief (Style form)mre
- a4bce6d1Records: ticket push subscriptionmre
- 14abde3bjukebox: records: Atlas's records moved to worldapi-conductor/archivemre
- 0433e9a8jukebox: records: gitoria remote added and pushedmre
- 1722d707jukebox: records: repo creation handed to Gitoriamre
- b42e7dfbjukebox: conductor records (CONDUCTOR.md, STATUS.md), old STATUS archivedmre
- 1b0d0bc1jukebox: a startup error prints its message before exit 1 (hybriel#247)mre
- b19c478bjukebox JB18 (jukebox#17): onto Hybriel set-day31 (b287cd82, contains the SIGPIPE fix 6d2ca454): plugins/core and plugins/web re-vendored, bin/ from the set; a client that closes /stream while it is written no longer kills the server (90 aborted streams survived, the old bin died with exit 141 on the first)mre
- 73867a2ejukebox#2: Style blocks in the language's nested form (rules named after the View's own elements, pseudo-classes nested, merged duplicates); the same CSS rules, the pages look the samemre
- 06c548d6jukebox JB15: report, log linemre
- 980859cbjukebox JB15 (jukebox#15): the now-playing overlay on a short screen (tablet or phone on its side) gave the queue 12 to 100 px because the big cover took the room; the cover now shrinks with the screen height and goes away under 41rem, the queue keeps 3+ rows; gate tests/jb15.mjs at 8 sizesmre
- 9efc40ffjukebox#12 #14: Grok session 1793246574527-181160mre
- 7d58b36ejukebox JB13 (jukebox#13): Next and Previous ask for the songs after / before the current song's id in the current order, not for place + 1; gate tests/jb13.mjs checks Next with the queue down to one song after the order changedmre
- 51358794jukebox JB14 (jukebox#14): the Songs screen opens sorted the way it was left (kept on the server in storage/ui.json), the sort control shows the sort the rows really have (selected options, autocomplete off); gate tests/jb14.mjsmre
- cc68a063jukebox JB13 (jukebox#13): a tapped song plays the song that was tapped, found by its id in the list as it is now (not by its row number, which counted plays move); the queue goes on from its place there, the rows refresh on the tap; gate tests/jb13.mjs (songs by plays, favourites)mre
- 88d3d5c1jukebox JB12b (jukebox#12): the scroll handle is big (2.75rem x 4rem, accent colour, grip) and drawn on every device, no media query; native bar hidden; gate tests/touch.mjs checks the drawn width with and without touchmre
- b58e4495jukebox JB11 (jukebox#11): the next song starts in the ended event on the same audio element, so it also starts with the screen locked; gate tests/jb11.mjs (hidden tab, no frames)mre
- 12a26233jukebox JB12 (jukebox#12): the long lists get a scroll handle a finger can use on touch screens (44 px tap area, slim look, drag through all rows), gate tests/touch.mjsmre