* Cleans a filename by removing extensions and normalizing spacers.
(str)
| 42 | * Cleans a filename by removing extensions and normalizing spacers. |
| 43 | */ |
| 44 | static cleanString(str) { |
| 45 | if (!str) return ''; |
| 46 | // Strip .mp3 extension if present |
| 47 | let cleaned = str.replace(/\.mp3$/i, ''); |
| 48 | // Replace underscores with spaces |
| 49 | cleaned = cleaned.replace(/_/g, ' '); |
| 50 | |
| 51 | // Strip leading numeric track index if followed by spacer punctuation (dot/dash/spaces) |
| 52 | // e.g. "01. Linkin Park" -> "Linkin Park", "02-Pink Floyd" -> "Pink Floyd" |
| 53 | cleaned = cleaned.replace(/^\s*\d+[\s.-]*[.-]+\s*(?=[a-zA-Z0-9])/, ''); |
| 54 | |
| 55 | // Remove typical enclosing characters like brackets/quotes |
| 56 | cleaned = cleaned.replace(/[\[\]\(\)"']/g, ' '); |
| 57 | // Normalize spaces |
| 58 | return cleaned.replace(/\s+/g, ' ').trim(); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Checks if a specific string part is generic or uninformative. |