#!/bin/sh -xv

BASENAME=$1
TAGFILE=$2
PICFILE=/home/kwlug/podcasts/kwlug3.png


# OGG does not support album art? 
vorbiscomment -w -c $TAGFILE $BASENAME.ogg

metaflac --remove-all-tags $BASENAME.flac
metaflac --import-picture-from=$PICFILE --import-tags-from=$TAGFILE $BASENAME.flac

# Grr. eyeD3 cannot read from a file. Fake it using metaflac.

tagtitle=`metaflac --show-tag=title $BASENAME.flac | sed -e 's/^TITLE=//' `
tagartist=`metaflac --show-tag=artist $BASENAME.flac | sed -e 's/^ARTIST=//' `
tagdate=`metaflac --show-tag=date $BASENAME.flac | sed -e 's/^DATE=//' `

tagdesc=`metaflac --show-tag=description $BASENAME.flac | sed -e 's/^DESCRIPTION=//' `
taglicense=`metaflac --show-tag=license $BASENAME.flac | sed -e 's/^LICENSE=//' `
taggenre=`metaflac --show-tag=genre $BASENAME.flac | sed -e 's/^GENRE=//' `
tagyear=`metaflac --show-tag=year $BASENAME.flac | sed -e 's/^YEAR=//' `

id3v2 --delete-all $BASENAME.mp3
id3v2 \
  --artist="$tagartist" \
  --TIT2 "$tagtitle" \
  --TCOP "$taglicense" \
  --genre="$taggenre" \
  --year="$tagyear" \
$BASENAME.mp3
eyeD3 --comment="eng:Date:$tagdate" --comment="eng:Description:$tagdesc" --add-image="$PICFILE:FRONT_COVER" $BASENAME.mp3
