#!/bin/bash

# Description: properties.sh
#
# This script has been written so that vdr users are able to find
# out more information about their files. Did that mpg complete
# without errors (which would make it smaller than it should be, etc.
# 
#	This script is part of the vdr-roaster plugin
#
#		    TESTED WITH VDR-1.4.4
#
#
# command-line usage:   sh properties.sh /full/path/to/misc_file.xxx
#			sh properties.sh /full/path/to/misc_file.xxx
#
#
#					02/03/2007 John Germs

# Variables
MISC_FILE="$1"
TMP_EXT1="/tmp/file_ext1_tmp.txt"
TMP_EXT2="/tmp/file_ext2_tmp.txt"
TMP_FILE="/tmp/file_info_tmp.txt"

echo "$1" > "$TMP_EXT1"
tr -d '\012' < "$TMP_EXT1" > "$TMP_EXT2"
EXT=$(tail -c 6 "$TMP_EXT2")

case "$EXT" in
*.avi)
  FILE_TYPE="AVI Video"
  ;;
*.iso)
  FILE_TYPE="ISO Image"
  ;;
*.mp3)
  FILE_TYPE="MP3 Audio"
  ;;
*.mpg)
  FILE_TYPE="MPG Video"
  ;;
*1.vdr | *2.vdr | *3.vdr | *4.vdr | *5.vdr | *6.vdr | *7.vdr | *8.vdr | *9.vdr | *0.vdr)
  FILE_TYPE="VDR Recording Segment"
  ;;
*.wav)
  FILE_TYPE="Windows Audio"
  ;;
*.wmv)
  FILE_TYPE="Windows Media"
  ;;
*)
  FILE_TYPE="Unknown"
  ;;
esac

echo
echo "       Type:  $FILE_TYPE"
du -sh --apparent-size --time=ctime --time-style=iso "$MISC_FILE" > "$TMP_FILE"

sed -i 's/	/:/g' $TMP_FILE
sed -i 's/:  /:/g' $TMP_FILE
cat $TMP_FILE | sort -k3 -t: -n | awk -F: '{
	print "  Created:  "$2
	print "        Size:  "$1
}'

rm "$TMP_EXT1"
rm "$TMP_EXT2"
rm "$TMP_FILE"
