Created
March 14, 2020 07:47
-
-
Save crutchcorn/3c33a9ced8c0cb6d31fa14bde14e0fbf to your computer and use it in GitHub Desktop.
This is how I remove duplicate tracks in my music library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mm = require('music-metadata'); | |
const fs = require('fs'); | |
const files = fs.readFileSync('../New\ playlist.m3u').toString().split("\r\n"); | |
let songs; | |
songsP = Promise.all(files.map(file =>mm.parseFile(file).then(v => ({...v, fileName: file})).catch(a => null))) | |
songsP.then(val => songs = val) | |
// make sure there are really duplicates in the list | |
songs = songs.filter(song => !!song).filter(song => song && songs.find(sonn => (song.common.title == sonn.common.title) && (song.fileName != sonn.fileName))) | |
lowQSongs = {} // title: {bitrate: number, fileName: string} | |
for (const song of songs) { | |
const title = song.common.title; | |
const bitrate = song.format.bitrate; | |
const fileName = song.fileName; | |
if (lowQSongs[title] && lowQSongs[title].bitrate < bitrate) { | |
continue; | |
} | |
lowQSongs[title] = {bitrate, fileName}; | |
} | |
Object.values(lowQSongs).map(a => a.fileName).forEach(f => fs.unlink(f, e => console.warn(e))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This sure is some 12:30AM code quality if I've ever seen it