iTunes to FLAC v0.12 ==================== Use this package to encode the tracks currently selected in iTunes with FLAC and transfer their tags to FLAC metadata, or to decode selected FLAC files to AIFF or WAVE, add them to iTunes, and tag them. Requirements: Mac OS X v10.3.9 or later, flac, metaflac Please see for the latest version. Contents -------- Package Contents Comments About FLAC Installing Using (Short Version) Using (Long Version) Caveats Utility Scripts Using FLAC Files Metadata Testing Change History Contact Terms and Conditions Package Contents ---------------- The package contains: iTunes to FLAC.app FLAC to iTunes.app CDimage to FLAC.app FLAC to CDimage.app Utility scripts Comments -------- The source code of flac (encoder/decoder) and metaflac (tag editor) is freely available from such sources as Fink Compiled binaries are available either by themselves or as part of a GUI tool, such as Scott Brown's highly recommended xACT No modifications are required prior to using. Preferences files are saved at <~/Library/Preferences/iTunes to Flac Prefs.xml> <~/Library/Preferences/FLAC to iTunes Prefs.xml> and log files at <~/Library/Logs/flac/> Logs created by this applet and by flac can be monitored conveniently using MkConsole, which is freely available from About FLAC ---------- What is FLAC, you ask? Answer: . Wherefore FLAC? I use it for archiving. I prefer it to the Apple Lossless format because it's open source. There is a variety of lossless audio compression formats available; for comparisons and more information see Installing ---------- 1. First, install flac and metaflac. A good place to put them in is . If you're not familiar with Unix programmes and the command-line interface, you can use preferences to set the applet to use the copies of flac and metaflac in the utilities/binaries folder (if they are included in this distribution). 2. Copy the iTunes to FLAC and FLAC to iTunes applets wherever convenient. If you want to access the iTunes to FLAC from iTunes' script menu, (a) place an alias of the applet in <~/Library/Scripts/Applications/iTunes/> (if this folder doesn't exist, create it), then, (b) place the utility script "Convert selection to FLACÉ.scpt" or an alias of it in <~/Library/iTunes/Scripts/> The only function of "Convert selection to FLACÉ.scpt" is to start the iTunes to FLAC applet. 3. You can monitor encoding or decoding progress by watching the log with Console. Alternatively, you can use MkConsole to display it on your desktop. (Set the mk_path parameter in the preferences file to 0 if you don't wish to use MkConsole, or delete/move the application.) 4. You can change the applets' options by editing the preferences files with a text editor, or by deleting them; they will be re-created when the respective applet is re-launched. 5. FLAC to iTunes maps FLAC comments to iTunes tags using the file "tag table.xml" in the utilities folder. This file can be edited with a text editor to add or remove tag mappings. However, when modifying it, make sure not to change the format, and make sure to change the value to reflect the changes you made. Quick Encoding -------------- 1. In iTunes, select some .aiff or .wav tracks from a playlist. Make sure the tracks are properly tagged in iTunes with title, artist, composer, etc. This information will be carried over to the files encoded by flac. 2. Launch iTunes to FLAC, either directly or using the utility script provided, and follow the prompts. The applet launches MkConsole to monitor the log; if it's not available, the log can be monitored with Console.app. 3. To encode a BIN/CUE or BIN/TOC audio CD image (such as produced by cdrdao), drop either of the pair of files on CDimage to FLAC. Quick Decoding -------------- 1. Drag and drop a selection of FLAC files and/or folders containing FLAC files at their top levels onto the FLAC to iTunes applet -- or, alternatively, double-click on the applet and, when prompted, choose one or more folders containing FLAC files at their top levels. 2. To decode a flac-encoded CD image, drop it (or the associated CUE file, if available) on FLAC to CDimage. Detailed Encoding ----------------- Here's what the applet is supposed to do: (1) Read the paths to output folder and to the flac and metaflac binaries, as well as the options to use from the preferences file. If it doesn't find the preferences, it asks for user input. Launch MkConsole (if available) to monitor progress. (2) Create a new folder in the output folder, and name it after the playlist. If a folder by that name already exists, it will append an underscore and a number to the new folder name, to make sure no data is lost. (3) For each selected track, create a small file in UTF-8 format in this folder, comprising the ID3 tag data. (4) Encode each selected track using flac, saving the output to the newly created folder in the output folder. If the corresponding disk file is not found, the track is skipped. (5) Use metaflac to import the data from the tag file as metadata in the FLAC file. (6) Move each track's tag file to Trash. (7) Shrink the log by deleting flac's status messages, and quit MkConsole. Note 1: You can't use flac on files compressed lossy formats, such as MP3 or AAC, and there wouldn't be any point to it. If you wish to convert from ALE (ALAC) or another lossless format, you must first decode the source tracks to AIFF or WAVE, and then use flac. Note 2: Flac cannot handle tracks on an audio CD (which are not really files). To encode an audio CD track with flac, first you have to "rip" it, i.e., extract it to a file on the hard disk, and then encode that file. You can rip audio CD tracks using iTunes or some other tool. One such tool is cdparanoia, whose extraction algorithm is superior to that of iTunes. iTunes to Cdparanoia, a package similar to iTunes to FLAC, can be used to automate extraction with this tool. A BIN/CUE, WAVE/CUE, or BIN/TOC audio CD image (such as created by cdrdao, for instance) is encoded with CDimage to FLAC. This applet takes either a single .bin, .wav, .cue, .toc file (and attempts to locate the other member of the pair); or a .bin/.cue, .bin/.toc, or .wav/.cue pair. First, the TOC file is converted to CUE format using either toc2cue or cueconvert. Then a new folder is created in the target folder, the data file is encoded to it, the cue sheet is imported in the encoded file, and the TOC and/or CUE files are copied to the output folder. Detailed Decoding ----------------- Here's what the applet is supposed to do: (1) Check the selection. "Selection" is either a number of files and/or folders dropped on it, or one or more folders chosen after double-clicking on it. "Check" means remove from the selection any folders which do not have at least one file with the filename extension .flac at their top level, and any files dropped on it which do not have the .flac filename extension. Other files, as well as package folders, are ignored. (2) Read the prefs and start a new log file. (3) Process "loose files", if any, where "loose files" are files dropped on the applet, and which do not necessarily reside in the same folder. (4) A folder is created in the folder specified in the preferences, then for each file in turn, the FLAC comments (tags) are exported to a file in that folder, and the FLAC file is decoded to AIFF or WAVE. (5) If the decoding is successful, the tag files is read and converted to iTunes tags. (6) The applet attempts to determine a name for a new iTunes playlist to which the decoded files will be added. First, it will check if the "album" tag of all decoded "loose files" has the same value; if yes, this will be used as playlist name. If not, it will check if the "loose files" are stored in the same folder; if yes, then the folder's name will be used. If not, it will generate a name from the current date. (7) A new user playlist is created in iTunes with the name determined at the previous step, decoded files are added to it, and tagged. (8) Steps 3, 4, and 6 are repeated for the folders, if any, in selection. The name of the folder is used as playlist name. (9) If processing runs its full course, the log file is pruned to remove normal status messages and thus reduce it in size. Note 1: When creating a new folder or new playlist, the applet does not overwrite any existing data; if a folder or playlist by that name already exists, the applet appends a number (" (1)", " (2)", etc.) to those it creates. A flac-encoded audio CD image is decoded with FLAC to CDimage. This applet takes either a single .flac or .cue file (and attempts to locate the other member of the pair); or a .flac/.cue pair. The CUE file is optional -- it is not required for decoding. The applet creates a new folder in the target folder, and, depending on the user choice, converts the flac-encoded image either to raw PCM audio data (.bin) or to WAVE format. If a CUE and/or TOC file are available, they are copied to the output folder; otherwise, the CUE file is created by exporting the cue sheet with metaflac. The CUE sheet is then converted to TOC format with cue2toc or cueconvert. Caveats ------- (1) Folder names or audio CD names with Unicode characters outside extended Latin may create problems. It's best to avoid them. (2) The applets expect files they create to be in certain locations. That will cause the applets to fail if you don't have writing permission for those folders; or if you change or rename folders or files they use while they are running. (3) Make sure there's enough disk space for encoding or decoding. Flac's compression ratios are nowhere near as impressive as those of MP3 or AAC -- a little over 50% compression is the most you can hope for. The iTunes to Flac applet should warn you if the target disk has less than 0.6GB free space, but the average CD usually requires less than that. The FLAC to iTunes applet warns if there's less than 1.6GB free space (which should be enough for a double CD), but it does not calculate how much space decoding the selection actually requires. (4) Logs created by flac can be quite large. After a successful run, the script will 'clean' the log and reduce it to approx 10K or less. However, it does not do so after a failed run. (5) The flac message "WARNING: skipping unknown chunk 'ID3 '" is normal for AIFF files. (The ID3 chunk is created by iTunes for tag data; flac doesn't know what it is because it's not in the original AIFF/AIFC specification.) (6) FLAC to CDimage requires that the FLAC file name should not contain illegal Unix characters. If it does, remove them. For instance, if the FLAC-encoded CD image is named "Chopin's 4 ƒtudes (Disc 1).flac" rename it to "Chopin_4_Etude_Disc_1.flac" prior to using FLAC to CDimage. Utility Scripts --------------- Delete Flac Logs: After a successful run, iTunes to FLAC shrinks the log file. It does not do so after a failed run. Use this script to shrink the logs, or to delete either all of them, or all except the last one. Kill Flac: If you think flac is stalled, you may use the Kill Flac applet to "kill" (force quit) it. Convert selection to FLACÉ: Use to launch iTunes to FLAC from iTunes' Script menu. Open Flac Log: Tells Console to launch and open the latest log in the <~/Library/Logs/flac/> folder. Binaries: If it exists, this folder contains bundled copies of the pre-compiled flac and metaflac binaries, as well as cue2toc and toc2cue. You may choose to use these copies if you don't have the flac distribution already installed. MkConsole: If it exists, this folder contains a copy of the MkConsole distribution. Using FLAC Files ---------------- * Playing FLAC. As far as I know, iTunes cannot be used to play FLAC files. (I believe there is a plug-in somewhere that should allow QuickTime-aware applications to play FLAC files, but I could not get the version I tested to work on my Mac.) However, there is Vincent Spader's Cog a basic audio player, which can play FLAC as well as other formats. Roxio Toast v7 or later also supports the FLAC format. * Editing FLAC Metadata: In addition to metaflac, FLAC comments can be edited with xACT or with Stephen Booth's Tag or Media Rage Metadata -------- The following table shows how the applet matches FLAC comments to iTunes tags. "GROUP=" is a custom field; as for "ENCODER=", the script fills it by querying flac and the operating system for their versions. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ FLAC iTunes Description ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TITLE= name -- track name ALBUM= album -- the album containing the track ARTIST= artist -- the artist/source of the track DESCRIPTION= comment -- freeform notes about the track COMPILATION= compilation -- is this track from a compilation album? COMPOSER= composer -- the composer of the track DISCTOTAL= disc count -- the total number of discs in the source album DISCNUMBER= disc number -- the index of the disc containing this track on the source album GENRE= genre -- the music/audio genre (category) of the track GROUP= grouping -- the grouping (piece) of the track. Generally used to denote movements within a classical work. TRACKTOTAL= track count -- the total number of tracks on the source album TRACKNUMBER= track number -- the index of the track on the source album DATE= year -- the year the track was recorded/released ENCODER= comment -- freeform notes about the track ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Unlike iTunes tags, FLAC comments may contain any number of custom tags, and repeat instances of the same tag. FLAC to iTunes concatenates all instances of the same tag, using " / " as a separator; comments which cannot be matched using "tag table.xml" are placed, including the label, in the "comment" field, separated by a return. Testing ------- This script has only been tested on Mac OS X v10.3.9 and iTunes v4.7.1. It should work on newer versions as well, but praemoniti, praemuniti. Change History -------------- v0.12 -- Corrected bug in run handler of FLAC to CDimage (prefs file wasn't closed). -- Corrected bug in FLAC to CDimage: WAVE files are now saved in the correct directory. -- Changed FLAC to CDimage so that substitution of the FILE declaration is no longer tied to line 1. -- Fixed bug which failed to set prefs to import cuesheet in CDimage to FLAC. -- Fixed Tiger bug in write_log subroutine. (Thanks to Daniel Cohen for finding it.) v0.11 -- Corrected "newline" bug in CDimage to FLAC and FLAC to CDimage (thanks to Daniel Cohen for pointing it out). v0.10 -- Added a time-out error work-around to some dialogues. -- Added new CDimage to FLAC and FLAC to CDimage applets. v0.9 -- Fixed bug which failed to insert path for MkConsole in new prefs file. -- Added new FLAC to iTunes applet. v0.8 -- Applet now checks disk free space and warns if there are less than 0.6GB free. -- Files which flac failed to convert are skipped. -- More informative message when encoding is completed. -- Changed name of iTunes script. v0.7 -- Fixed bug which inserted nulls in the log. -- Changed MkConsole window handler to monitor only the applet/flac log. -- CR changed to LF while the log is created (simplifies monitoring). Log shrinking commands modified accordingly. -- Changed quit messages to reflect errors better. -- Cosmetic changes to some log messages. -- Changed time string in log name for better sorting. v0.6 -- Missing track files no longer stop the script. -- Added the option of monitoring the log with MkConsole. -- Added the option of using bundled binaries. -- Fixed some bugs in the prefs handler. v0.5 -- Reorganised as an applet. -- Added a basic logging functions. A log is saved in ~/Library/Logs. -- Progress dialogues eliminated (progress can be tracked by monitoring the log with Console.app). v0.4 -- Fixed a bug which caused the script to fail if metadata contained Unicode characters in higher ranges. v0.3 -- Moved all iTunes stuff to a single tell block. v0.2 -- Embarrassing bug: Metadata of each track was copied from the first track in selection, not from the track being encoded. Fixed. -- Added a dialogue box to mark each encoded track, and give user a chance to cancel encoding of subsequent tracks. v0.1 -- First release Contact ------- Comments and suggestions are very welcome. Please address them to . Terms and Conditions -------------------- This script is (c)2006 Lexial, Inc, and it is distributed as free software under the terms of the GNU General Public Licence. Please be aware that NO WARRANTY of any kind and NO SUPPORT of any kind are offered for this script application. The terms of the GNU General Public Licence are available here Flac, metaflac, and the FLAC codec are (c)2004,2005 by Joash Colson and released by the Xiph.org Foundation under the Xiph Licence; parts are released under the GNU General Public Licence. MkConsole and MkConsoleElement are (c)2002-2005 by Mulle kybernetiK.