A node.js wrapper for 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.
Load the metaflac
module
var metaflac = require('metaflac');
preserveModtime
Preserve the original modification time in spite of edits.withFilename
Prefix each output line with the FLAC file name (the default if more than one FLAC file is specified).noFilename
Do not prefix each output line with the FLAC file name (the default if only one FLAC file is specified).noUTF8Convert
Do 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.dontUsePadding
By 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 for list
, remove
and exportPictureTo
operations) 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 for list
and remove
operations) Has a value of either a single block type or an array of block types to be included with this operation.exceptBlockType
(only for list
and remove
operations) Has a value of either a single block type or an array of block types to be excluded with this operation.applicationDataFormat
(only for list
operation) 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 for importCuesheetFrom
operation)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
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-md5sum
Show the MD5 signature from the STREAMINFO block.
metaflac.showMinBlocksize(options, fileName, callback(err, blocksize))
--show-min-blocksize
Show the minimum block size from the STREAMINFO block.
metaflac.showMaxBlocksize(options, fileName, callback(err, blocksize))
--show-max-blocksize
Show the maximum block size from the STREAMINFO block.
metaflac.showMinFramesize(options, fileName, callback(err, framesize))
--show-min-framesize
Show the minimum frame size from the STREAMINFO block.
metaflac.showMaxFramesize(options, fileName, callback(err, framesize))
--show-max-framesize
Show the maximum frame size from the STREAMINFO block.
metaflac.showSampleRate(options, fileName, callback(err, sampeRate))
--show-sample-rate
Show the sample rate from the STREAMINFO block.
metaflac.showChannels(options, fileName, callback(err, channels))
--show-channels
Show the number of channels from the STREAMINFO block.
metaflac.showBps(options, fileName, callback(err, bps))
--show-bps
Show the # of bits per sample from the STREAMINFO block.
metaflac.showTotalSamples(options, fileName, callback(err, totalSamples))
--show-total-samples
Show the total # of samples from the STREAMINFO block.
metaflac.showVendorTag(options, fileName, callback(err, vendorTag))
--show-vendor-tag
Show the vendor string from the VORBIS_COMMENT block.
metaflac.showTag(options, fileName, name, callback(err, value))
--show-tag=name
Show all tags where the the field name matches 'name'.
metaflac.removeTag(options, fileName, name, callback(err))
--remove-tag=name
Remove all tags whose field name is 'name'.
metaflac.removeFirstTag(options, fileName, name, callback(err))
--remove-first-tag=name
Remove first tag whose field name is 'name'.
metaflac.removeAllTags(options, fileName, callback(err))
--remove-all-tags
Remove all tags, leaving only the vendor string.
metaflac.removeAllTags(options, fileName, name, value, callback(err))
--set-tag=field
Add 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=file
Import tags from a file. Each line should be of the form NAME=VALUE. Multi-line comments are currently not supported. Specify noUTF8Convert
option 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. Specify noUTF8Convert
option if necessary.
metaflac.exportTagsTo(options, fileName, file, callback(err))
--export-tags-to=file
Export tags to a file. Each line will be of the form NAME=VALUE. Specify noUTF8Convert
option 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. Specify noUTF8Convert
option if necessary.
metaflac.importCuesheetFrom(options, fileName, cuesheet, callback(err))
--import-cuesheet-from=file
Import a cuesheet from a file. A seekpoint will be added for each index point in the cuesheet to the SEEKTABLE unless the noCuedSeekpoints
option 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 the noCuedSeekpoints
option is specified.
metaflac.exportCuesheetTo(options, fileName, cuesheet, callback(err))
--export-cuesheet-to=file
Export 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=FILENAME
Import 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=SPECIFICATION
Import 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:mimeType
is 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 that file
is actually a URL to an image, though this use is discouraged.description
is optional; the default is an empty string.dimensions
The 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.file
is 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=file
Export PICTURE block to a file. The first PICTURE block will be exported unless the blockNumber
option 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 the blockNumber
option is set to specify the exact metadata block to extract.
metaflac.addReplayGain ... NOT IMPLEMENTED
metaflac.removeReplayGain(options, fileName, callback(err))
--remove-replay-gain
Removes 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=length
Add 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))
--list
Get 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. If keysToUpper
(optional) is true, all tag keys will be converted to upper case
metaflac.remove(options, fileName, callback(err))
--remove
Remove 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 the dontUsePadding
option is specified, the blocks will be replaced with padding. You may not remove the STREAMINFO block.
metaflac.removeAll(options, fileName, callback(err))
--remove-all
Remove all metadata blocks (except the STREAMINFO block) from the metadata. Unless the dontUsePadding
option is specified, the blocks will be replaced with padding.
metaflac.mergePadding(options, fileName, callback(err))
--merge-padding
Merge adjacent PADDING blocks into single blocks.
metaflac.sortPadding(options, fileName, callback(err))
--sort-padding
Move all PADDING blocks to the end of the metadata and merge them into a single block.
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]);
}
});