iTunes automation scripts
Switch branches/tags
Clone or download
Latest commit 387a5be Aug 26, 2014
Failed to load latest commit information.
src/UTF8to16 Changed license to MIT/X11 Dec 11, 2011
tests Added some tests Jul 14, 2013
AddFLACs.bat Made the script runnable from any folder. Nov 29, 2011
AddFLACs.js Fix a typo in variable name (AddFLACs.js line 62). Fixes #7. Aug 26, 2014
COPYING.MIT Add command-line options to specify iTunes fields, and the ability May 17, 2014
PathnamesToTrackInfo.js With indexes May 6, 2012 Add command-line options to specify iTunes fields, and the ability May 17, 2014
build.bat Fix a typo in variable name (AddFLACs.js line 62). Fixes #7. Aug 26, 2014



AddFLACs - add FLAC files to the iTunes media library


AddFLACs [options] [FOLDER]


The AddFLACs script scans the specified FOLDER and its subfolders for FLAC files, converts them to Apple lossless format and adds to the iTunes library.

To avoid track duplication, AddFLACs first extracts the metadata from each FLAC file it encounters and checks if a track with exactly the same artist, album and title is already present in the iTunes library. Such tracks will be skipped even if they are in a different format.

If FOLDER is not specified, the current folder and its subfolders will be scanned.


  • FLAC command-line utilities, flac.exe and metaflac.exe, and a UTF-8 to UTF-16 conversion helper must be present in the folder containing the script.

  • Unless you specify track, album, and artist names on the command line, all FLAC files must be properly tagged prior to conversion. At a minimum, the tags ARTIST, ALBUM, and TITLE must be present. Also recognized are GENRE, TRACKNUMBER, DATE, and COMPILATION.

  • If the DATE tag is present, it must contain year only.


Regular expression

-r regular-expression
--regex regular-expression

This option has dual purpose. First, the tracks that do not match regular-expression are skipped. This enables you to filter out tracks that you do not want to import in this session. Second, when there is a match, AddFLACs attempts to substitute the values of the regular-expression capture groups into the values of iTunes fields options (see below). This helps when your FLAC files are not tagged but hierarchically organized on disk. (see EXAMPLES.)

regular-expression is a JavaScript regular expression, matched in case-insensitive mode (native Windows filesystems are case-insensitive.)


-itunes-field-name value

Set itunes-field-name for each track to value. You can specify any valid iTunes field. Note that it is preceded by a single dash. In most cases, you would want to specify several fields, combining them with the --regex option, so as to use capture groups in value (see EXAMPLES.)

If the respective value is also present in the FLAC file metadata, AddFLACs will use it by default, ignoring the command-line option. Use --override-metadata or --ignore-metadata to change this behavior.


Ignore (don't even try to extract) any metadata that may be present in FLAC files. Requires that you specify at least -artist, -album, and -name.


Values specifies on the command line will override the respective fields of existing FLAC metadata.

Other options


Do not actually import tracks into iTunes, only show what would be imported.


Be verbose about what's going on.

-d --debug

Print extra debug information. Useful for debugging regular experessions.



Import all FLAC files from the current drectory and its subdirectories (default).

AddFLACs.bat -n -r ".*\\(.*)\\(.*)\\(.*)\.flac$" -artist "$1" -album "$2" -name "$3"

Import all FLAC files from the current drectory and its subdirectories. Assuming their pathnames match the "Artist\Album\Name.flac" pattern, use the respective capture group instead of missing metadata fields, if any. Do not actually import tracks (re-run without -n after verifying that the fields get extracted as intended.)

AddFLACs.bat --override-metadata ^
  -artist "The Doors" ^
  -sortartist "Doors, The" ^

Import all tracks found under c:\Users\Me\Music\FLAC\Doors, forcing Artist and Sort Artist fields to be set irrespective of what FLAC metadata might contain. Album and track names will still be extracted from metadata (and hence must be present.)


The AddFLACs script and the Unicode conversion helper are released under the MIT/X11 license (see COPYING.MIT.)

The FLAC command-line tools are released under the GPLv2 (see COPYING.GPL.) The source code may be obtained from the official FLAC pages on SourceForge.


Vorbis Comments