Created
March 18, 2023 19:13
-
-
Save jhubble/04b1418d95c5d0e91ca798e20cfa1d92 to your computer and use it in GitHub Desktop.
Get one line for each entry in a mediainfo output
This file contains hidden or 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
// Output 1 line mediainfo for files | |
// TYPICAL USAGE: | |
// mediainfo sourceDir --Output=JSON > source.json | |
// node outputMusicList.js source.json | |
const fs = require("fs"); | |
var args = process.argv; | |
if (args.length < 3) { | |
console.error("Usage: node outputMusicList.js fileWithSource.json"); | |
process.exit(); | |
} | |
// mediainfo . --Output=JSON >allMediaFiles.json | |
const getMeta = (file => { | |
const meta = file.media.track.find((track) => track["@type"] === "General"); | |
const filename = file.media["@ref"]; | |
meta.filename = filename; | |
return meta; | |
}); | |
const indexFiles = (filename) => { | |
const mediacontents = JSON.parse(fs.readFileSync(filename, "utf8")); | |
console.log('FILENAME\tARTIST\tALBUM\tTITLE\tTRACK\tGENRE\tBIT_RATE\tDURATION\tENCODED_APP\tENCODED_DATE\n'); | |
mediacontents.forEach((file) => { | |
try { | |
const item = getMeta(file); | |
console.log(`${item.filename}\t${item.Performer}\t${item.Album}\t${item.Title}\t${item.Track}\t${item.Genre}\t${item.OverallBitRate}\t${item.Duration}\t${item.Format}\t${item.Encoded_application}\t${item.Encoded_Date}`); | |
} catch (e) { | |
console.error(e, file); | |
} | |
}); | |
}; | |
indexFiles(args[2]); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment