#!/bin/sh

PROGRAM_NAME=$1
RECORD_SECS=$2 
DEST_DIR=$3/$1`date +_%y%m`

FFMPEG=/usr/local/ffmpeg/bin/ffmpeg
RADIO_ADDR="rtsp://new_iradio.ebs.co.kr:554/iradio/iradiolive_m4a"
TITLE=$PROGRAM_NAME`date "+ %Y.%_m.%_d."`
DEST_FILE=$PROGRAM_NAME`date +_%y%m%d`.m4a

if [ ! -d "$DEST_DIR" ] ; then
  mkdir -p "$DEST_DIR"
  synoindex -A "$3"
fi

$FFMPEG -rtsp_transport tcp -i $RADIO_ADDR -t $RECORD_SECS -codec:a copy -vn -metadata title="$TITLE" -metadata date=`date +%F` "$DEST_DIR/$DEST_FILE"

synoindex -a "$DEST_DIR/$DEST_FILE"
