# FLACTAG

Andy Hawkins
`<andy@gently.org.uk>`

Daniel Pocock <daniel@pocock.com.au>

A utility for tagging single album FLAC files with embedded CUE sheets using data from the MusicBrainz service.

Flactag is licensed under the GNU General Public License (GPL) v3.

## 1. Downloading

The latest version of flactag can always be found here.

## 2. Requirements

- libmusicbrainz (Version 5 required)

- libdiscid

- libflac++ (I used version 1.2.1)

- S-Lang (I used version 2.2.2 from Debian)

- libneon (I used version 0.27-gnutls from Debian)

- unac (I used version 1.8.0 from Debian)

- libjpeg (I used version 8b-1 from Debian)

- asciidoc (I used version 8.5.2 from Debian)

## 3. Building and Installing

If you take the source code directly from the repository (not a tarball), you must run

- autoreconf --install

to prepare the autotools environment.

The project is built using autotools. Once you have obtained the source code (either from the repository or a tarball), you run

- ./configure - this will create the Makefile

- make - this will compile

- make install - this will install everything

See the help output from the ./configure command for details about how to change LDFLAGS, CXXFLAGS, installation directories and other settings.

The build process should complete with no errors. You will be left with the following executables:

- flactag - The main application

- discid - A test utility to read the disc ID from a CD

To install the software and associated scripts, simply run `make install`. This step will need to be run as `root` if the install is being done outside of the user’s home directory.

## 4. Developer notes

When releasing a new version, it is necessary to change the version number in configure.ac before making a tag in the version control system.

To build a tarball for public distribution, use the command

- make dist - this will create flactag-$(VERSION).tar.gz

## 5. Ripping CDs to FLAC

IMPORTANT: I think I found a bug in `cueconvert` which means that any FLAC files generated from CDs that used INDEX marks to separate tracks that didn’t have any pre-gap would generate invalid disc IDs. I would urge you to use the `checkflac` script provided to compare any disks you may have ripped with their FLAC files to ensure that the discids match correctly. Included in this release is a SED script which will massage the TOC file of a CD to work around this problem. Unfortunately, the only way to recover from this is to re-rip the CD

To rip a CD to flac, simply enter `ripflac <basename>` (where basename is used as the base name of the FLAC file you will be creating. The CD in the drive will be ripped, and a FLAC file created containing an embedded CUE sheet. ripflac takes an optional final parameter for the path to the CD drive, which defaults to /dev/cdrom.

If the original CD contains data tracks, then the FLAC conversion will fail. Should this happen, enter `ripdataflac <basename> <range>` (where basename is the same one specified in the first rip attempt, and range is the range of tracks to rip (e.g. if the CD has 13 tracks, where track 13 is the data track, then the range would be 1-12). ripdataflac takes an optional final parameter for the path to the CD drive, which defaults to /dev/cdrom.

During the ripping of the data CD, you will be provided with the CUE sheet in an editor. You should delete the data track from this CUE sheet file and save it (I will try to automate this process at some point).

Both these scripts will compare the calculated discid of the FLAC file with the discid of the CD in the drive. If they do not match, a warning will be issued.

## 6. Using flactag

### 6.1. Interactive mode

If flactac is executed without any options, it will interactively process all FLAC files given as arguments.

If the flactag utility does not find information for your CD, a URL will be provided to submit information for it. Often the MusicBrainz server will have information about the tracks and artist, but cannot match this up to your CD. In these circumstances, it is simply a matter of 'associating' your CD’s DiskID with the correct album data on the MusicBrainz server. In other instances, you may be required to enter the track and album information into the MusicBrainz service. Once you have entered this information, you can re-run flactag, and the data should be downloaded from the MusicBrainz server.

If the flactag utility finds information for your CD at the musicbrainz server, the application’s main window will be shown.

This contains three main areas:

- The 'Albums' window. This will contain a list of albums that match the DiskID for your FLAC file.

- The 'Tracks' window. This contains a list of all the tracks on the currently selected album.

- The 'Tags' window. At startup, this will contain a list of the tags currently found in your FLAC file. If there are no tags present, then an empty set appropriate for the album will be displayed. If you make changes to these tags, an asterisk ('*') will be displayed to indicate that this information has been changed.

The currently active window will be highlighted by the border and window title changing colour. To switch between the three windows, press the TAB key. To scroll around the active window, use the cursor UP and cursor DOWN keys (to scroll one line at a time) or the PAGE UP and PAGE DOWN keys (to scroll half a page at a time). Scrolling in the 'Albums' window will update the information in the 'Tracks' window appropriately.

Once the appropriate album has been selected, pressing c will copy the tags for that album into the 'Tags' window. These tags can then be saved to the FLAC file by pressing the w key.

Pressing r will rename the file based on the settings in the configuration file (~/.flactag - this file is created automatically the first time you run flactag). Note that this facility uses the tags that are actually written to the file, so should generally be performed after the new tags have been written. This option will be unavailable if the filename and location are already correct.

Pressing q will move to the next file specified on the command line. If all files have been processed, the application will exit.

### 6.2. Batch mode

Alternatively, flactag can be used in batch mode to automatically check tags, write them and rename the file. Care should be taken when using these options.

The following command line options are understood:

- --discid (-d) - Display the calculated disc ID for the specified FLAC file and exit.

- --submit-url (-s) - Display the URL used to submit information for this file to the MusicBrainz service. Use this to submit data for your CD if the data returned does not match.

- --check (-c) - This option will compare the file’s tags against those returned from the MusicBrainz service. A message will be displayed indicating where the tags match or not.

- --write (-w) - This option implies --check. If the files tags differ from those returned from the MusicBrainz service, the tags will be written to the file.

- --force-write (-f) - If --write is specified then tags will be written even if they appear to match those already in the file.

- --rename (-r) - The filename will be compared with that specified by the rename rules, and if it doesn’t match, the file will be renamed.

- --overwrite-existing (-o) - If --rename is specified then flactag will overwrite existing files when renaming.

- --override-discid (-O) - Instead of calculating disc ID from the cuesheet, flactag will use the provided disc ID to query MusicBrainz. Only one FLAC file can be processed when this option is used. This is useful if you do not want to add the disc ID to the real MusicBrainz database, for example: because the original disc has not been sighted, the FLAC was made by ripping a disc that was only a copy of the original and the copy was not made in disc-at-once mode.

Example uses of these options could be as follows (note the use of the find option '-print0' and the xargs option '-0' to handle filenames containing spaces):

#### 6.2.1. Report on the tags of all FLAC files

`find /var/spool/music -name "*.flac" -print0 | xargs -0 flactag --check`

#### 6.2.2. Tag and rename all flac files

`find /var/spool/music -name "*.flac" -print0 | xargs -0 flactag --write --rename`

## 7. File Renaming Details

The following configuration file (~/.flactag) entries affect file renaming:

- BasePath - This is the root directory of where your music files should be stored. (e.g. /var/spool/music)

- SingleDiskFileName - This template is used to rename disks that are not part of a multi-disk set.

- MultiDiskFileName - This template is used to rename disks that are part of a multi-disk set.

- DirectoryCreatePermissions - The permissions to be set on any directory that is created (e.g. 0755).

- CreateCuesheetAfterRename - If set to true, flactag will generate a cuesheet file to accompany the renamed FLAC file.

The FileName templates can accept the following parameters:

- %A - This will be replaced with the artist name

- %S - This will be replaced with the artist sort name

- %T - This will be replaced with the album title

- %D - This will be replaced with the disk number

- %Y - This will be replaced with the year

- %G - This will be replaced with the genre

- %1 - This will be replaced with the first character of the artist sort name

- %E - This will be replaced by the appropriate filename extension (flac or cue)

If any item is used but does not have a value, then it will be stored as (for example) NOGENRE (if the genre tag is empty).

## 8. Using A Different Musicbrainz Server

To use a different MusicBrainz server (for example if you have a local mirror) you can set the Server and Port parameters in the configuration file.

e.g.

Server=mbserver.localdomain

Port=5000

## 9. Bugs / Limitations / Future Enhancements

- Once changes are written to the FLAC file, there is no way of reverting back to the original tags.

## 10. Problems / Suggestions

If you have any problems with the software, or suggestions for improvements or new features, then please report them here.

There are two mailing lists for discussion and announcements, which would be a good place to start for any questions. These lists are gated via GMane as gmane.comp.audio.flactag.announce and gmane.comp.audio.flactag.discuss respectively.

## 11. Version History

### 11.1. v2.0.4 - 19th June 2012

- Fix Debian bug #677296 - Don’t write negative times in CUE sheets

- Resolve realpath related compilation issues on Hurd

### 11.2. v2.0.3 - 7th June 2012

- Have iconv transliterate characters wherever possible

- Correctly initialise UTF-8 in slang

- Fix memory issues when writing picture blocks

- Fix crash under debian unstable 64 due to incorrect buffer size passed to realpath

- Correctly check return value from realpath

- Allow user to pass path to cdrom drive in ripflac and ripdataflac

### 11.3. v2.0.2 - 18th May 2012

- Build system updates

- Fix bug passing incorrect buffer size to realpath

- Update to use libmusicbrainz5

### 11.4. v2.0.1 - 18th April 2012

- Change license to GPL v3

- Documentation updates

### 11.5. v2.0.0 - 17th April 2012

- Build system updated to use autotools (submitted by Daniel Pocock)

- Updated to work with MusicBrainz NGS using libmusicbrainz4

- Add ability to generate CUE file containing appropriate tag information (submitted by Daniel Pocock)

- Add ability to specify disk id rather than using the one derived from the CUE sheet (submitted by Daniel Pocock)

- More work on packaging for Debian

- Add ability to specify both server and port to query

### 11.6. v1.1 - 16th December 2008

- Scripts no longer have .sh extension

- Initial work on packaging for Debian

- More consistent mechanism for delaying requests to MusicBrainz

- Fix file name building issues if base path is .

- Handle presence and absence of trailing / in base path

- New option --overwrite-existing when renaming files

- Fix compilation problems caused by newer gcc

- Switch to neon for downloading image files

### 11.7. v1.1RC1 - 17th July 2008

- Use new version of MusicBrainz library

- Correctly handle exceptions generated

- Limit rate of requests to MusicBrainz server

- Append (Single) to end of names of singles

- Removed --force-multi option from command line. Now compare stored MUSICBRAINZ_ALBUMID if multiple releases are returned.

- Store embedded cover art

### 11.8. v1.0 - 27th September 2007

- Handle PICTURE block if library supports it

### 11.9. v1.0RC2 - 10th January 2007

- Add install target to install application and associated scripts

- Documentation now generated using asciidoc

- Scripts for ripping now included (including modification of TOC files where necessary)

- PAGE UP and PAGE DOWN can now be used for scrolling in windows

- Always use index number 1 when calculating TOC for FLAC file

- Convert accented characters to standard characters in filenames

- Add --discid option to report calculated discid for FLAC file

- Fix various compilation errors on some systems

- Report differences in tags when using --check option

- Compare real path of file (not path used in command line which could be relative) to see if renaming should be allowed

- Don’t write ALBUMARTIST tag (causes problems with artist sorting in current SlimServer software)

- Add --force-write option

- Correctly write UTF8 values for tags

### 11.10. v1.0-RC1 - 12th October 2006

- Add command line options and ability to handle more than one FLAC file

- Store cover art embedded into file tags

- Handle console screen size changes

- Retrieve more tags from MusicBrainz

### 11.11. v0.04 - 23rd September 2006

- Software released under the GPL

- Add ability to rename file after tagging

- Add logging capability (all log messages are queued and display on exit)

- Add facility to download album cover art from Amazon

- Store more Musicbrainz related information in tags

### 11.12. v0.03 - 18th September 2006

- Fix serious bug in generating submission URLs

### 11.13. v0.02 - 18th September 2006

- Correctly handle multi-album disc sets

- Include ARTISTSORT tag

- Retrieve Amazon ASIN in preparation for downloading cover art

### 11.14. v0.01 - 16th September 2006

- Initial version