#!/bin/bash # Maurice Walton 2007 www.mauricewalton.com # MythTV job parameters # %DIR% - the directory component of the recording's filename # %FILE% - the filename component of the recording's filename # %TITLE% - the title of the recording (e.g., name of the series) # %SUBTITLE% - the subtitle of the recording (e.g., name of the episode) # %DESCRIPTION% - description text for the recording (from guide data) # %HOSTNAME% - the backend making the recording # %CATEGORY% - the category of the recording (from guide data) # %RECGROUP% - the recording group # %CHANID% - the MythTV channel ID making the recording # %STARTTIME% - the recording start time (YYYYMMDDhhmmss) # %ENDTIME% - the recording end time (YYYYMMDDhhmmss) # %STARTTIMEISO% - the recording start time in ISO 8601 format (YYYY-MM-DDTHH:MM:SS) # %ENDTIMEISO% - the recording end time in ISO 8601 format # %PROGSTART% - the recording's start time (from guide data; YYYYMMDDhhmmss) # %PROGEND% - the recording's end time (from guide data) # %PROGSTARTISO%, %PROGENDISO% - the recording's start and end time in ISO 8601 format. # # Usage: (from MythTV): # mythradiopodcast "%DIR%" "%FILE%" "%TITLE%" "%SUBTITLE%" "%DESCRIPTION%" "%HOSTNAME%" "%CATEGORY%" "%RECGROUP%" "%CHANID%" "%STARTTIME%" "%ENDTIME%" "%STARTTIMEISO%" "%ENDTIMEISO%" "%PROGSTART%" "%PROGEND%" "%PROGSTARTISO%" "%PROGENDISO%" # Display all values passed in (not all used but may be in future) echo "## SCRIPT: START" DIR="$1" echo "DIR=$DIR" FILE="$2" echo "FILE=$FILE" TITLE="$3" echo "TITLE=$TITLE" SUBTITLE="$4" echo "SUBTITLE=$SUBTITLE" DESCRIPTION="$5" echo "DESCRIPTION=$DESCRIPTION" HOSTNAME="$6" echo "HOSTNAME=$HOSTNAME" CATEGORY="$7" echo "CATEGORY=$CATEGORY" RECGROUP="$8" echo "RECCGROUP=$RECGROUP" CHANID="$9" echo "CHANID=$CHANID" STARTTIME="${10}" echo "STARTTIME=$STARTTIME" ENDTIME="${11}" echo "ENDTIME=$ENDTIME" STARTTIMEISO="${12}" echo "STARTTIMEISO=$STARTTIMEISO" ENDTIMEISO="${13}" echo "ENDTIMEISO=$ENDTIMEISO" PROGSTART="${14}" echo "PROGSTART=$PROGSTART" PROGEND="${15}" echo "PROGEND=$PROGEND" PROGSTARTISO="${16}" echo "PROGSTARTISO=$PROGSTARTISO" PROGENDISO="${17}" echo "PROGENDISO=$PROGENDISO" # Get the start time values YEAR=`expr substr $STARTTIME 1 4` echo "YEAR=$YEAR" MONTH=`expr substr $STARTTIME 5 2` echo "MONTH=$MONTH" DAY=`expr substr $STARTTIME 7 2` echo "DAY=$DAY" HOUR=`expr substr $STARTTIME 9 2` echo "HOUR=$HOUR" MINUTE=`expr substr $STARTTIME 11 2` echo "MINUTE=$MINUTE" # Use a version of the title without colons for the new file name TITLENOCOLON="${TITLE//:/-}" echo "TITLENOCOLON=$TITLENOCOLON" NEWFILENAME="$TITLENOCOLON ("$DAY"-"$MONTH"-"$YEAR" "$HOUR"-"$MINUTE").m4a" echo "NEWFILENAME=$NEWFILENAME" # If there's a colon in the title then use the title for the series name and episode name COLONPOS=`expr index "$TITLE" :` echo "COLONPOS=$COLONPOS" if [ $COLONPOS = 0 ]; then # No colon so use the title for the series name SERIES="$TITLE" if [ "" = "$SUBTITLE" ]; then # No subtitle so use the first sentance from the description as the episode name STOPPOS=`expr index "$DESCRIPTION" .` echo "STOPPOS=$STOPPOS" if [ $STOPPOS = 0 ]; then EPISODE="$DESCRIPTION ($DAY/$MONTH/$YEAR $HOUR:$MINUTE)" else EPISODE="${DESCRIPTION:0:$STOPPOS-1} ($DAY/$MONTH/$YEAR $HOUR:$MINUTE)" fi else # there is a subtitle, so use the first sentance of the subtitle as the episode STOPPOS=`expr index "$SUBTITLE" .` echo "STOPPOS=$STOPPOS" if [ $STOPPOS = 0 ]; then EPISODE="$SUBTITLE ($DAY/$MONTH/$YEAR $HOUR:$MINUTE)" else EPISODE="${SUBTITLE:0:$STOPPOS-1} ($DAY/$MONTH/$YEAR $HOUR:$MINUTE)" fi fi else # The is a colon in the title, so use it for the series and episode SERIES="${TITLE:0:$COLONPOS-1}" EPISODE="${TITLE:$COLONPOS+1} ($DAY/$MONTH/$YEAR $HOUR:$MINUTE)" fi echo "SERIES=$SERIES" echo "EPISODE=$EPISODE" # Find part number and total number for the programme, i.e. 1 of 5 or 1/5, default to 1/1 PARTCOLONTOTAL=`perl -e 'use strict;my $parameter = "$ARGV[0]";$parameter =~ /(\d+)(\ of\ |\/)(\d+)/;my $part = $1;my $seperator = $2;my $total = $3;if (($part gt "") && ($total gt "")){print "$part:$total";}else{print "1:1";}' "$SUBTITLE $DESCRIPTION"` echo "$PARTCOLONTOTAL" COLONPOS=`expr index "$PARTCOLONTOTAL" :` PART="${PARTCOLONTOTAL:0:$COLONPOS-1}" echo "PART=$PART" TOTAL="${PARTCOLONTOTAL:$COLONPOS}" # Convert channel ID to Channel Name echo "TOTAL=$TOTAL" if [ $CHANID = "1700" ]; then CHANNEL="BBC Radio 1" elif [ $CHANID = "1702" ]; then CHANNEL="BBC Radio 2" elif [ $CHANID = "1703" ]; then CHANNEL="BBC Radio 3" elif [ $CHANID = "1704" ]; then CHANNEL="BBC Radio 4" elif [ $CHANID = "1707" ]; then CHANNEL="BBC Radio 6" elif [ $CHANID = "1708" ]; then CHANNEL="BBC Radio 7" else CHANNEL=$CHANID fi echo "CHANNEL=$CHANNEL" # Convert MythTV mpeg to a temporary wav file (PCM) echo "## SCRIPT: MPLAYER" mplayer -quiet -vc null -vo null -ao pcm:fast:file="/tmp/$FILE.wav" "$DIR/$FILE" &> /dev/null # Convert wav file to m4a file at quality "200", "100" also sounds pretty good and is a bit smaller - note that the cover art parameter depends on gif files existing in target directory, remove the parameter if not wanted or no usuable m4a will be produced. The gif can be saved from the BBC radio pages, for example - see faac documentation for more details. echo "## SCRIPT: FAAC" faac -q 200 -o "/tmp/$NEWFILENAME" -w --artist "$CHANNEL" --writer "$CHANNEL" --title "$SERIES: $EPISODE" --genre "Books & Spoken" --album "$SERIES" --track "$PART"/"$TOTAL" --disc 1/1 --year "$YEAR" --cover-art "/var/www/mythcast/$CHANID.gif" --comment "$DESCRIPTION" "/tmp/$FILE.wav" &> /dev/null # Delete temporary wav file echo "## SCRIPT: REMOVE wav file from tmp" rm -fv "/tmp/$FILE.wav" # Now the m4a is ready, move it to the target directory (do not want partial files to be available) echo "## SCRIPT: MOVE m4a file from tmp" mv -fv "/tmp/$NEWFILENAME" "/var/www/mythcast/$NEWFILENAME" # Change the date of the m4a file to match the original MythCast mpeg file (to allow correct sorting by file date etc.) echo "## SCRIPT: TOUCH" touch --no-create --reference="$DIR/$FILE" "/var/www/mythcast/$NEWFILENAME" # Update the podcast XML echo "## SCRIPT: JAVA" java -cp /home/mythtv/bin MythPodcastMaker -title "$SERIES: $EPISODE" -subtitle "$DESCRIPTION" -summary "$DESCRIPTION" -holding "http://mrmozza.gotadsl.co.uk/mythcast" -keywords "MythTV iPod BBC Radio" -starttime "$STARTTIME" -endtime "$ENDTIME" -author "$CHANNEL" -xml "/var/www/mythcast/mythpodcast.xml" -keep "-1" -file "$NEWFILENAME" echo "## SCRIPT: DONE"