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
- 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