#!/bin/bash # # podcoder - A simple way to produce consistently named and # tagged audio files. # # Version: 0.14.0 # Status: Moderately Undevelopmental # # Author: Tony Whitmore # With contributions from: # Ben "mrben" Thorp # Alan "popey" Pope # # Homepage: The latest version of this script can be found at http://tonywhitmore.co.uk/ # License: You may freely use, modify and redistribute this script as long as you allow others to do the same. # This script is provided without warranty or even fitness for purpose. Use at own risk. # # Description: Converts a WAV file (although other files may well work) # to specified compressed formats, as well as setting tag data. # This script assumes the following additional programs are in the user's path: # lame oggenc flac speexenc metaflac vorbiscomment base64 eyeD3 tr sha1sum # In Debian/Ubuntu, these are the following packages: # lame vorbis-tools flac speex mkvtoolnix eyed3 coreutils # # Bugs/TODO: You will notice that there's very little error checking. # FLAC apparently supports album art in the PICTURE block. Haven't implemented this yet. :) # Need to resolve issues with file metadata when season information not present. # i18n? # Example: podcoder input.wav # Include config file defaults or create config file if non-existant if [ -f podcoder.ini ]; then . podcoder.ini else echo "Creating new podcoder.ini. Edit the settings if necessary." echo "# Settings for podcoder # Enable low mono MP3 LOW_MP3=yes # Enable high stereo MP3 HIGH_MP3=yes # Enable low mono OGG LOW_OGG=yes # Enable high stereo OGG HIGH_OGG=yes # Enable CBR MP3 (compatible with Last.FM) HIGH_CBR_MP3=yes # Enable FLAC FLAC=no # Enable Speex SPEEX=no # Embed image IMAGE=no # Generate SHA1 checksums SHA1=yes # Use seasons. \"no\" means no season info in filename. # Album information in metadata will not be populated. USE_SEASONS=yes # Change these default settings for tags to suit your project # Leave commented out options and you will be prompted for them # when you run the script # Name (Artist) # NAME=\"Fabulous Podcast\" # Season (Album), number only # SEASON=\"01\" # Episode Number, number only # NUMBER=\"01\" # Episode Name # EP_NAME=\"My First Podcast\" # Image filename. This should probably only be 150x150 pixels and probably JPEG. # IMAGE_FILE=\"logo.jpg\" # Genre Tag # GENRE=\"Podcast\" # Basename (used to build the output filenames) # BASENAME=\"fabpod\" # These settings are optional. If you leave them commented out you will # NOT be prompted for them when you run the script. # Track number # TRACK=\"1\" # Comment # COMMENT=\"\" # Uncommenting these variables over-rides the defaults. # Comment language. Default=eng # COMMENT_LANG=\"eng\" # Comment description. # COMMENT_DESC=\"Contents\" # Season prefix (used in filename) # SEASON_PREFIX=\"s\" # Episode prefix (used in filename) # EPISODE_PREFIX=\"e\" " > podcoder.ini exit fi # Check for input file if [ -z "$1" ]; then echo "No input file specified!" exit 1; fi # Collect tag data if [ -z "$NAME" ]; then echo -n "Podcast name? " read NAME fi # Do some season related logic if [ -z "$USE_SEASONS" ]; then echo "Use seasons? (yes/no) " read USE_SEASONS fi if [ "$USE_SEASONS" == "yes" ]; then if [ -z "$SEASON_PREFIX" ]; then SEASON_PREFIX="s" fi if [ -z "$SEASON" ]; then echo -n "Season number? " read SEASON fi else unset SEASON_PREFIX unset SEASON fi if [ -n "$EPISODE_PREFIX" ]; then EPISODE_PREFIX="e" fi if [ -z "$NUMBER" ]; then echo -n "Episode number? " read NUMBER fi if [ -z "$EP_NAME" ]; then echo -n "Episode name? " read EP_NAME fi if [ -z "$IMAGE" ]; then echo -n "Enable embedded image? (yes/no) " read IMAGE if [ "$IMAGE" == "yes" ]; then if [ -z "$IMAGE_FILE" ]; then echo -n "Image file? " read IMAGE_FILE fi fi fi if [ -z "$GENRE" ]; then echo -n "Genre? " read GENRE fi if [ -z "$BASENAME" ]; then echo -n "Filename base? " read BASENAME fi # If there is a comment set but description and language are not # then provide defaults if [ -n "$COMMENT" ]; then if [ -z "$COMMENT_DESC" ]; then COMMENT_DESC="Contents" COMMENT_LANG="eng" fi fi # Set the year to a variable YEAR=`date +%Y` # Encode image if needed if [ "$IMAGE" == "yes" ]; then echo -n "Encoding image file... " # Trying a new method required by removal of base64tool package from Karmic base64 $IMAGE_FILE | tr -d '\n' > podcoder.temp # base64tool encode $IMAGE_FILE podcoder.temp.2 EXIT=$? if [ "$EXIT" != "0" ]; then echo "Something went wrong whilst encoding image file to base64." exit 1 fi # The following deprecated - not needed in jaunty and newer # cat podcoder.temp.2 | tr -d '\n' > podcoder.temp # rm podcoder.temp.2 # EXIT=$? # if [ $EXIT != 0 ]; then # echo "Something went wrong whilst deleting temporary image file." # exit 1 # fi fi # Encode low quality mono MP3 if [ "$LOW_MP3" == "yes" ]; then TARGET="$BASENAME"_"$SEASON_PREFIX""$SEASON""$EPISODE_PREFIX""$NUMBER"_low.mp3 lame --quiet -a -q 0 --vbr-new -B 32\ --ta "$NAME" --tl "Season $SEASON" --tt "Episode $NUMBER - $EP_NAME"\ --ty "$YEAR" $1 $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst encoding to low quality MP3." exit 1 fi # Set genre tag ("Podcast" is not in the specification so you need to use eyeD3 # here, which doesn't complain whereas lame does.) eyeD3 --to-v2.4 -G "$GENRE" $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding genre to low quality MP3." exit 1 fi # Add a track number, if set if [ -n "$TRACK" ]; then eyeD3 --track=$TRACK $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding track number to low quality MP3." exit 1 fi fi # Add a comment, if set if [ -n "$COMMENT" ]; then eyeD3 --lyrics=$COMMENT_LANG:$COMMENT_DESC:"$COMMENT" $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding the lyric comment to low quality MP3." exit 1 fi eyeD3 --comment=$COMMENT_LANG:$COMMENT_DESC:"$COMMENT" $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding the comment to low quality MP3." exit 1 fi fi # Embed image if [ "$IMAGE" == "yes" ]; then eyeD3 --add-image="$IMAGE_FILE":FRONT_COVER $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding image to low quality MP3." exit 1 fi fi # Generate SHA1 checksum if [ "$SHA1" == "yes" ]; then sha1sum $TARGET >> SHA1SUMS fi fi # Encode high quality stereo MP3 if [ "$HIGH_MP3" == "yes" ]; then if [ "$LOW_MP3" == "yes" ]; then TARGET="$BASENAME"_"$SEASON_PREFIX""$SEASON""$EPISODE_PREFIX""$NUMBER"_high.mp3 else TARGET="$BASENAME"_"$SEASON_PREFIX""$SEASON""$EPISODE_PREFIX""$NUMBER".mp3 fi lame --quiet -m s -q 0 --vbr-new -B 128\ --ta "$NAME" --tl "Season $SEASON" --tt "Episode $NUMBER - $EP_NAME"\ --ty "$YEAR" $1 $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst encoding to high quality MP3." exit 1 fi # Set genre tag ("Podcast" is not in the specification so you need to use eyeD3 # here, which doesn't complain whereas lame does.) eyeD3 --to-v2.4 -G "$GENRE" $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding genre to high quality MP3." exit 1 fi # Add a track number, if set if [ -n "$TRACK" ]; then eyeD3 --track=$TRACK $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding track number to high quality MP3." exit 1 fi fi # Add a comment, if set if [ -n "$COMMENT" ]; then eyeD3 --lyrics=$COMMENT_LANG:$COMMENT_DESC:"$COMMENT" $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding the lyric comment to high quality MP3." exit 1 fi eyeD3 --comment=$COMMENT_LANG:$COMMENT_DESC:"$COMMENT" $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding the comment to high quality MP3." exit 1 fi fi # Embed image if [ "$IMAGE" == "yes" ]; then eyeD3 --add-image="$IMAGE_FILE":FRONT_COVER $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding the image to high quality MP3." exit 1 fi fi # Generate SHA1 checksum if [ "$SHA1" == "yes" ]; then sha1sum $TARGET >> SHA1SUMS fi fi # Encode high quality constant bit-rate (CBR) MP3 # Last.fm requires 128kbps CBR file at 44.1Khz if [ "$HIGH_CBR_MP3" == "yes" ]; then TARGET="$BASENAME"_"$SEASON_PREFIX""$SEASON""$EPISODE_PREFIX""$NUMBER"_cbr.mp3 lame --quiet -m s -q 0 --cbr -B 128 --resample 44.1\ --ta "$NAME" --tl "Season $SEASON" --tt "Episode $NUMBER - $EP_NAME"\ --ty "$YEAR" $1 $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst encoding to high quality CBR MP3." exit 1 fi # Set genre tag ("Podcast" is not in the specification so you need to use eyeD3 # here, which doesn't complain whereas lame does.) eyeD3 --to-v2.4 -G "$GENRE" $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding genre to high quality CBR MP3." exit 1 fi # Add a track number, if set if [ -n "$TRACK" ]; then eyeD3 --track=$TRACK $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding track number to high quality CBR MP3." exit 1 fi fi # Add a comment, if set if [ -n "$COMMENT" ]; then eyeD3 --lyrics=$COMMENT_LANG:$COMMENT_DESC:"$COMMENT" $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding the lyric comment to high quality CBR MP3." exit 1 fi eyeD3 --comment=$COMMENT_LANG:$COMMENT_DESC:"$COMMENT" $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding the comment to high quality CBR MP3." exit 1 fi fi # Embed image if [ "$IMAGE" == "yes" ]; then eyeD3 --add-image="$IMAGE_FILE":FRONT_COVER $TARGET EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding the image to high quality CBR MP3." exit 1 fi fi # Generate SHA1 checksum if [ "$SHA1" == "yes" ]; then sha1sum $TARGET >> SHA1SUMS fi fi # Encode low quality mono OGG if [ "$LOW_OGG" == "yes" ]; then TARGET="$BASENAME"_"$SEASON_PREFIX""$SEASON""$EPISODE_PREFIX""$NUMBER"_low.ogg oggenc --quiet -b 32 --downmix\ -a "$NAME" -l "Season $SEASON" -t "Episode $NUMBER - $EP_NAME"\ -G "$GENRE" -d "$YEAR" -o $TARGET $1 EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst encoding to low quality OGG." exit 1 fi # Add a track number, if set if [ -n "$TRACK" ]; then vorbiscomment -a $TARGET\ -t "TRACKNUMBER=$TRACK" EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding track number to low quality OGG." exit 1 fi fi # Add a comment, if set if [ -n "$COMMENT" ]; then vorbiscomment -a $TARGET\ -t "COMMENT=$COMMENT" EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding comments to low quality OGG." exit 1 fi fi # Embed image if [ "$IMAGE" == "yes" ]; then vorbiscomment -a $TARGET\ -t "COVERARTMIME=image/jpeg"\ -t "COVERART=`cat podcoder.temp`" EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding cover art to low quality OGG." exit 1 fi fi # Generate SHA1 checksum if [ "$SHA1" == "yes" ]; then sha1sum $TARGET >> SHA1SUMS fi fi # Encode high quality stereo OGG if [ "$HIGH_OGG" == "yes" ]; then if [ "$LOW_OGG" == "yes" ]; then TARGET="$BASENAME"_"$SEASON_PREFIX""$SEASON""$EPISODE_PREFIX""$NUMBER"_high.ogg else TARGET="$BASENAME"_"$SEASON_PREFIX""$SEASON""$EPISODE_PREFIX""$NUMBER".ogg fi oggenc --quiet -b 64\ -a "$NAME" -l "Season $SEASON" -t "Episode $NUMBER - $EP_NAME"\ -G "$GENRE" -d "$YEAR" -o $TARGET $1 EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst encoding to high quality OGG." exit 1 fi # Add a track number, if set if [ -n "$TRACK" ]; then vorbiscomment -a $TARGET\ -t "TRACKNUMBER=$TRACK" EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding track number to high quality OGG." exit 1 fi fi # Add a comment, if set if [ -n "$COMMENT" ]; then vorbiscomment -a $TARGET\ -t "COMMENT=$COMMENT" EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding comments to high quality OGG." exit 1 fi fi # Embed image if [ "$IMAGE" == "yes" ]; then vorbiscomment -a $TARGET\ -t "COVERARTMIME=image/jpeg"\ -t "COVERART=`cat podcoder.temp`" EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst adding cover art to high quality OGG." exit 1 fi fi # Generate SHA1 checksum if [ "$SHA1" == "yes" ]; then sha1sum $TARGET >> SHA1SUMS fi fi # Encode FLAC if [ "$FLAC" == "yes" ]; then flac -o "$BASENAME"_"$SEASON_PREFIX""$SEASON""$EPISODE_PREFIX""$NUMBER".flac $1 metaflac --set-tag=TITLE="$NUMBER - $EP_NAME"\ --set-tag=ALBUM="Season $SEASON"\ --set-tag=ARTIST="$NAME"\ "$BASENAME"_s"$SEASON"e"$NUMBER".flac EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst encoding to Flac" exit 1 fi fi # Encode speex if [ "$SPEEX" == "yes" ]; then speexenc --vbr --bitrate 64\ --title "$NUMBER - $EP_NAME" --author "$NAME"\ $1 "$BASENAME"_"$SEASON_PREFIX""$SEASON""$EPISODE_PREFIX""$NUMBER".spx EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst encoding to Speex." exit 1 fi fi # Clean up temporary file if [ "$IMAGE" == "yes" ]; then rm podcoder.temp EXIT=$? if [ $EXIT != 0 ]; then echo "Something went wrong whilst deleting temporary image file." exit 1 fi fi