Cannot create MP3 with UTF-16LE tags

Ian Pilcher arequipeno at gmail.com
Sat May 26 05:58:49 UTC 2012


On 05/25/2012 11:32 PM, Ian Pilcher wrote:
> My script for creating MP3 files from FLAC files has broken in Fedora
> 17.  Specifically, tags with accented characters are getting truncated
> when I try to write them as UTF-16LE (which seems to be what most
> players expect).  The script, which I am attaching, worked fine when I
> last used it in January back in January (presumably on Fedora 16).

New, working script attached for posterity.

-- 
========================================================================
Ian Pilcher                                         arequipeno at gmail.com
"If you're going to shift my paradigm ... at least buy me dinner first."
========================================================================
-------------- next part --------------
#!/bin/bash

FLAC_FILE="$1"
MP3_FILE="$2"

ABSOLUTE_FLAC_FILE=`readlink -m "$FLAC_FILE"`
ART_FILE="${ABSOLUTE_FLAC_FILE%/*}/front.jpg"

TITLE=`metaflac --show-tag=title "$FLAC_FILE" | sed 's/^title=//'`
ARTIST=`metaflac --show-tag=artist "$FLAC_FILE" | sed 's/^artist=//'`
GENRE=`metaflac --show-tag=genre "$FLAC_FILE" | sed 's/^genre=//'`
ALBUM=`metaflac --show-tag=album "$FLAC_FILE" | sed 's/^album=//'`
TRACKNUMBER=`metaflac --show-tag=tracknumber "$FLAC_FILE" | sed 's/^tracknumber=//'`

# It doesn't seem to be possible to store UTF-16 strings in Bash variables, and LAME doesn't seem
# to be able to handle UTF-16 tags at all anymore.  :-(

if [ -f "$ART_FILE" ]; then
    flac -dc "$FLAC_FILE" | lame -V0 --ti "$ART_FILE" - "$MP3_FILE"
else
    flac -dc "$FLAC_FILE" | lame -V0 - "$MP3_FILE"
fi

id3v2 -t "`echo $TITLE | iconv -f UTF-8 -t UTF-16LE`" \
	-a "`echo $ARTIST | iconv -f UTF-8 -t UTF-16LE`" \
	-g "`echo $GENRE | iconv -f UTF-8 -t UTF-16LE`" \
	-A "`echo $ALBUM | iconv -f UTF-8 -t UTF-16LE`" \
	-T "$TRACKNUMBER" "$MP3_FILE"
id3v2 -s "$MP3_FILE"


More information about the users mailing list