metaflac v0.1.0
Metaflac
This module aims to be a more or less complete wrapper for the metaflac command line utility.
Most documentation ist shamelessly stolen from the metaflac(1) man page.
Limitations
- Can only run one operation at a time
- Can only process one FLAC at a time
API
Load the metaflac module
var metaflac = require('metaflac');Options
preserveModtimePreserve the original modification time in spite of edits.withFilenamePrefix each output line with the FLAC file name (the default if more than one FLAC file is specified).noFilenameDo not prefix each output line with the FLAC file name (the default if only one FLAC file is specified).noUTF8ConvertDo not convert tags from UTF-8 to local charset, or vice versa. This is useful for scripts, and setting tags in situations where the locale is wrong.dontUsePaddingBy default metaflac tries to use padding where possible to avoid rewriting the entire file if the metadata size changes. Use this option to tell metaflac to not take advantage of padding this way.blockNumber(only forlist,removeandexportPictureTooperations) Has a value of either a single block number or an array of block numbers to display. The first block, the STREAMINFO block, is block 0.blockType(only forlistandremoveoperations) Has a value of either a single block type or an array of block types to be included with this operation.exceptBlockType(only forlistandremoveoperations) Has a value of either a single block type or an array of block types to be excluded with this operation.applicationDataFormat(only forlistoperation) If the application block you are displaying contains binary data but your --data-format=text, you can display a hex dump of the application data contents instead using --application-data-format=hexdump.noCuedSeekpoints(only forimportCuesheetFromoperation)
The valid block types are: STREAMINFO, PADDING, APPLICATION, SEEKTABLE, VORBIS_COMMENT. You may narrow down the types of APPLICATION blocks displayed as follows:
APPLICATION:abcd The APPLICATION block(s) whose textual representation of the 4-byte ID is "abcd"APPLICATION:0xXXXXXXXX The APPLICATION block(s) whose hexadecimal big-endian representation of the 4-byte ID is "0xXXXXXXXX". For the example "abcd" above the hexadecimal equivalalent is 0x61626364
Functions
The options argument is an array containing none or more of the above options. Options with a value are represented as an array. Multiple values ara again represented as an array.
fileName is the path to the FLAC file.
callback is a function that gets an error as boolean and sometimes a return value.
Options Example:
var options = [
'noUTF8Convert',
[ 'blockType', 'VORBIS_COMMENT' ],
[ 'blockNumber', [2,3,5] ]
];metaflac.showMD5sum(options, fileName, callback(err, md5sum))
--show-md5sumShow the MD5 signature from the STREAMINFO block.metaflac.showMinBlocksize(options, fileName, callback(err, blocksize))
--show-min-blocksizeShow the minimum block size from the STREAMINFO block.metaflac.showMaxBlocksize(options, fileName, callback(err, blocksize))
--show-max-blocksizeShow the maximum block size from the STREAMINFO block.metaflac.showMinFramesize(options, fileName, callback(err, framesize))
--show-min-framesizeShow the minimum frame size from the STREAMINFO block.metaflac.showMaxFramesize(options, fileName, callback(err, framesize))
--show-max-framesizeShow the maximum frame size from the STREAMINFO block.metaflac.showSampleRate(options, fileName, callback(err, sampeRate))
--show-sample-rateShow the sample rate from the STREAMINFO block.metaflac.showChannels(options, fileName, callback(err, channels))
--show-channelsShow the number of channels from the STREAMINFO block.metaflac.showBps(options, fileName, callback(err, bps))
--show-bpsShow the # of bits per sample from the STREAMINFO block.metaflac.showTotalSamples(options, fileName, callback(err, totalSamples))
--show-total-samplesShow the total # of samples from the STREAMINFO block.metaflac.showVendorTag(options, fileName, callback(err, vendorTag))
--show-vendor-tagShow the vendor string from the VORBIS_COMMENT block.metaflac.showTag(options, fileName, name, callback(err, value))
--show-tag=nameShow all tags where the the field name matches 'name'.metaflac.removeTag(options, fileName, name, callback(err))
--remove-tag=nameRemove all tags whose field name is 'name'.metaflac.removeFirstTag(options, fileName, name, callback(err))
--remove-first-tag=nameRemove first tag whose field name is 'name'.metaflac.removeAllTags(options, fileName, callback(err))
--remove-all-tagsRemove all tags, leaving only the vendor string.metaflac.removeAllTags(options, fileName, name, value, callback(err))
--set-tag=fieldAdd a tag. If there is currently no tag block, one will be created.metaflac.setTagFromFile ... NOT IMPLEMENTED
metaflac.importTagsFrom(options, fileName, file, callback(err))
--import-tags-from=fileImport tags from a file. Each line should be of the form NAME=VALUE. Multi-line comments are currently not supported. SpecifynoUTF8Convertoption if necessary.metaflac.importTagsFromStream(options, fileName, stream, callback(err))
--import-tags-from=-Import tags from a Readable Stream. Each line should be of the form NAME=VALUE. Multi-line comments are currently not supported. SpecifynoUTF8Convertoption if necessary.metaflac.exportTagsTo(options, fileName, file, callback(err))
--export-tags-to=fileExport tags to a file. Each line will be of the form NAME=VALUE. SpecifynoUTF8Convertoption if necessary.metaflac.exportTagsToStream(options, fileName, stream, callback(err))
--export-tags-to=-Export tags to a Writable Stream. Each line will be of the form NAME=VALUE. SpecifynoUTF8Convertoption if necessary.metaflac.importCuesheetFrom(options, fileName, cuesheet, callback(err))
--import-cuesheet-from=fileImport a cuesheet from a file. A seekpoint will be added for each index point in the cuesheet to the SEEKTABLE unless thenoCuedSeekpointsoption is specified.metaflac.importCuesheetFrom(options, fileName, stream, callback(err))
--import-cuesheet-from=-Import a cuesheet from a Readable Stream. A seekpoint will be added for each index point in the cuesheet to the SEEKTABLE unless thenoCuedSeekpointsoption is specified.metaflac.exportCuesheetTo(options, fileName, cuesheet, callback(err))
--export-cuesheet-to=fileExport CUESHEET block to a cuesheet file, suitable for use by CD authoring software.metaflac.exportCuesheetToStream(options, fileName, stream, callback(err))
--export-cuesheet-to=-Export CUESHEET block to a Writable Stream, suitable for use by CD authoring software.metaflac.importPictureFrom(options, fileName, picture, callback(err))
--import-picture-from=FILENAMEImport a picture and store it in a PICTURE metadata block. Read below for more info.metaflac.importPictureFrom(options, fileName, specifiction, callback(err))
--import-picture-from=SPECIFICATIONImport a picture and store it in a PICTURE metadata block.
The specification is a object with the following properties:type,mimeType,description,dimensions,file.type(optional) is one of:
0: Other
1: 32x32 pixels 'file icon' (PNG only)
2: Other file icon
3: Cover (front) (DEFAULT)
4: Cover (back)
5: Leaflet page
6: Media (e.g. label side of CD)
7: Lead artist/lead performer/soloist
8: Artist/performer
9: Conductor
10: Band/Orchestra
11: Composer
12: Lyricist/text writer
13: Recording Location
14: During recording
15: During performance
16: Movie/video screen capture
17: A bright coloured fish
18: Illustration
19: Band/artist logotype
20: Publisher/StudiomimeTypeis optional; if left blank, it will be detected from the file. For best compatibility with players, use pictures with MIME type image/jpeg or image/png. The MIME type can also be --> to mean thatfileis actually a URL to an image, though this use is discouraged.descriptionis optional; the default is an empty string.dimensionsThe next part specfies the resolution and color information. If the MIME-TYPE is image/jpeg, image/png, or image/gif, you can usually leave this empty and they can be detected from the file. Otherwise, you must specify the width in pixels, height in pixels, and color depth in bits-per-pixel. If the image has indexed colors you should also specify the number of colors used. When manually specified, it is not checked against the file for accuracy.fileis the path to the picture file to be imported, or the URL if MIME type is -->
metaflac.exportPictureTo(options, fileName, picture, callback(err))
--export-picture-to=fileExport PICTURE block to a file. The first PICTURE block will be exported unless theblockNumberoption is set to specify the exact metadata block to extract.metaflac.exportPictureToStream(options, fileName, stream, callback(err))
--export-picture-to=-Export PICTURE block to a Writable Stream. The first PICTURE block will be exported unless theblockNumberoption is set to specify the exact metadata block to extract.metaflac.addReplayGain ... NOT IMPLEMENTED
metaflac.removeReplayGain(options, fileName, callback(err))
--remove-replay-gainRemoves the ReplayGain tags.metaflac.addSeekpoint(options, fileName, pattern, callback(err))
--add-seekpoint={#|X|#x|#s}Add seek points to a SEEKTABLE block. Using #, a seek point at that sample number is added. Using X, a placeholder point is added at the end of a the table. Using #x, # evenly spaced seek points will be added, the first being at sample 0. Using #s, a seekpoint will be added every # seconds (# does not have to be a whole number; it can be, for example, 9.5, meaning a seekpoint every 9.5 seconds). If no SEEKTABLE block exists, one will be created. If one already exists, points will be added to the existing table, and any duplicates will be turned into placeholder points.metaflac.addPadding(options, fileName, length, callback(err))
--add-padding=lengthAdd a padding block of the given length (in bytes). The overall length of the new block will be 4 + length; the extra 4 bytes is for the metadata block header.metaflac.list(options, fileName, callback(err, metadataBlocks))
--listGet one or more metadata blocks. By default, all metadata blocks are provided as JavaScript objects. Use the following options to change this behavior:blockType,blockNumber,exceptBlockType.metaflac.vorbisComment(options, fileName, keysToUpper, callback(err, comments))
Returns a JavaScript object containing all VORBIS_COMMENT tags. IfkeysToUpper(optional) is true, all tag keys will be converted to upper casemetaflac.remove(options, fileName, callback(err))
--removeRemove one or more metadata blocks. By default, all metadata blocks will be removed. Use the following options to change this behavior:blockType,blockNumber,exceptBlockType. Unless thedontUsePaddingoption is specified, the blocks will be replaced with padding. You may not remove the STREAMINFO block.metaflac.removeAll(options, fileName, callback(err))
--remove-allRemove all metadata blocks (except the STREAMINFO block) from the metadata. Unless thedontUsePaddingoption is specified, the blocks will be replaced with padding.metaflac.mergePadding(options, fileName, callback(err))
--merge-paddingMerge adjacent PADDING blocks into single blocks.metaflac.sortPadding(options, fileName, callback(err))
--sort-paddingMove all PADDING blocks to the end of the metadata and merge them into a single block.
Examples
Print all VorbisComment tags
metaflac.vorbisComment([], './songAboutButterflies.flac', function (err, comments) {
if (err) { console.log('we have a problem'); return; }
for (var name in comments) {
console.log(name, '=', comments[name]);
}
});14 years ago