-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathpatch-taglib-sharp.js
More file actions
31 lines (24 loc) · 1.27 KB
/
Copy pathpatch-taglib-sharp.js
File metadata and controls
31 lines (24 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const filePath = path.join(__dirname, 'node_modules/@digimezzo/node-taglib-sharp/dist/id3v2/frames/textInformationFrame.js');
try {
let content = fs.readFileSync(filePath, 'utf8');
if (content.includes('f.description !== undefined && f.description !== null')) {
console.log('[node-taglib-sharp patch] Already patched, skipping');
process.exit(0);
}
const oldSnippet = ` return frames.find((f) => comparison(f.description, description));`;
// Malformed TXXX frames parse to an undefined description, which makes the case-insensitive comparison throw.
const newSnippet = ` return frames.find((f) => f.description !== undefined && f.description !== null && comparison(f.description, description));`;
if (!content.includes(oldSnippet)) {
console.error('[node-taglib-sharp patch] Expected snippet not found');
process.exit(1);
}
content = content.replace(oldSnippet, newSnippet);
fs.writeFileSync(filePath, content, 'utf8');
console.log('[node-taglib-sharp patch] Patch applied');
} catch (error) {
console.error('[node-taglib-sharp patch] Failed:', error instanceof Error ? error.message : String(error));
process.exit(1);
}