diff options
author | Cecil <knoppmyth@gmail.com> | 2011-08-06 19:10:30 (GMT) |
---|---|---|
committer | Cecil <knoppmyth@gmail.com> | 2011-08-06 19:10:30 (GMT) |
commit | ad58e3033f6bb5137b8dcb0e7eca12d50d888402 (patch) | |
tree | 9321335a68173bc3e4c1d237c19c8880411fa676 /abs/core/linhes-scripts/screenshooter.sh | |
parent | 998faf16b1b62493b39aa13b3cb53dfac266ef4c (diff) | |
parent | 9709ca528ca5dfbdb6ec6ea283ac6670e8f33b9d (diff) | |
download | linhes_pkgbuild-ad58e3033f6bb5137b8dcb0e7eca12d50d888402.zip linhes_pkgbuild-ad58e3033f6bb5137b8dcb0e7eca12d50d888402.tar.gz linhes_pkgbuild-ad58e3033f6bb5137b8dcb0e7eca12d50d888402.tar.bz2 |
Merge branch 'testing' of ssh://cesman@linhes.org/mount/repository/linhes_pkgbuild into testing
Conflicts:
abs/core/tzdata/PKGBUILD
Diffstat (limited to 'abs/core/linhes-scripts/screenshooter.sh')
-rwxr-xr-x[-rw-r--r--] | abs/core/linhes-scripts/screenshooter.sh | 114 |
1 files changed, 57 insertions, 57 deletions
diff --git a/abs/core/linhes-scripts/screenshooter.sh b/abs/core/linhes-scripts/screenshooter.sh index 72f6cc0..1cb7a78 100644..100755 --- a/abs/core/linhes-scripts/screenshooter.sh +++ b/abs/core/linhes-scripts/screenshooter.sh @@ -5,6 +5,9 @@ # Email: bob@stormlogic.com # # If you run into problems with this script, please send me email +# +# Maintained by Michael Hanson <mihanson@linhes.org> +# # This is alpha code to auto-generate thumbnails for previews in MythVideo. # It won't currently work on some filenames that have spaces in them. @@ -24,42 +27,44 @@ Usage() { echo "USAGE:" - echo `basename $0` "-v PATHNAME [-s SECONDS] [-c] [-b HOSTNAME] [-u USERNAME] [-p PASSWORD] [-o]" - echo "-v: pathname to Video" + echo `basename $0` "-f FILENAME [-s SECONDS] [-c] [-b HOSTNAME] [-u USERNAME] [-p PASSWORD] [-v]" + echo "-f: video filename" echo "-s: number of Seconds to skip before capturing (270 by default)" echo "-c: Clobber any previous screenshot found for this video (off by default)" - echo "-b: mysql server (Backend) hostname (localhost by default)" + echo "-b: mysql server (Backend) hostname (default: dbhost in /etc/systemconfig)" echo "-u: mysql Username (mythtv by default)" echo "-p: mysql Password (mythtv by default)" - echo "-o: verbOse mode (off by default)" + echo "-v: verbose mode (off by default)" echo "-x: check for valid video eXtension (off by default)" echo - echo "EXAMPLE: $0 -v /myth/video/HDTV/shuttle.mpg -c -s 30" + echo "EXAMPLE: $0 -f shuttle.mpg -c -s 30" exit 3 } +. /etc/systemconfig + if [ -z $1 ]; then Usage fi -V_MISSING=1 +F_MISSING=1 -while getopts "v:sbupochx" FLAG ; do +while getopts "f:sbupvcx" FLAG ; do case "$FLAG" in - v) VIDEO_PATHNAME="$OPTARG" - V_MISSING=0;; + f) FILENAME="$OPTARG" + F_MISSING=0;; s) SKIPAHEAD="$OPTARG";; c) CLOBBER=1;; b) BACKEND_HOSTNAME="$OPTARG";; u) DBUSERNAME="$OPTARG";; p) DBPASSWORD="$OPTARG";; - o) VERBOSE=1;; + v) VERBOSE=1;; x) EXTENSION_CHECK=1;; *) Usage;; esac done -if [ $V_MISSING == 1 ]; then +if [ $F_MISSING == 1 ]; then Usage fi @@ -68,82 +73,75 @@ fi # SKIPAHEAD is the number of seconds to skip ahead before starting the frame capture. # Set it to an arbitrary value if none is specified. SKIPAHEAD=${SKIPAHEAD:-"270"} -BACKEND_HOSTNAME=${BACKEND_HOSTNAME:-"localhost"} +BACKEND_HOSTNAME=${BACKEND_HOSTNAME:-${dbhost}} DBUSERNAME=${DBUSERNAME:-"mythtv"} DBPASSWORD=${DBPASSWORD:-"mythtv"} -# Defaults to quiet. -VERBOSE=${VERBOSE:-0} +# Defaults to quiet. +VERBOSE=${VERBOSE:-0} # Unless otherwise told, do not clobber existing cover files. CLOBBER=${CLOBBER:-0} # Unless otherwise told, do not check the file extension against # MythTV's list of registered video file types. EXTENSION_CHECK=${EXTENSION_CHECK:-0} -VIDEO_CAPTURE_HOME=$(mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -sNBe "select data from settings where value='VideoArtworkDir' limit 1") -if [ ! -d "$VIDEO_CAPTURE_HOME" ] ; then - echo "Directory $VIDEO_CAPTURE_HOME does not exist, nowhere to put the screen shot!" - echo "Have you configured MythVideo yet?" +SG_VIDEOS=$(mysql -u $DBUSERNAME -p$DBPASSWORD -h $BACKEND_HOSTNAME -D mythconverg -sNBe \ + "SELECT dirname FROM storagegroup WHERE groupname='Videos'") +if [ ! -d "${SG_VIDEOS}" ] ; then + echo "Directory $SG_VIDEOS does not exist, nowhere to put the screen shot!" + echo "Have you configured Storage Groups yet?" exit 1 fi -VIDEO_HOME=$(mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -sNBe "select data from settings where value='VideoStartupDir' limit 1") -if [ ! -d "$VIDEO_HOME" ] ; then - echo "Directory $VIDEO_HOME does not exist, nowhere to put the screen shot!" - echo "Have you configured MythVideo yet?" +SG_SCREEN=$(mysql -u $DBUSERNAME -p$DBPASSWORD -h $BACKEND_HOSTNAME -D mythconverg -sNBe \ + "SELECT dirname FROM storagegroup WHERE groupname='Screenshots'") +if [ ! -d "${SG_SCREEN}" ] ; then + echo "Directory $SG_SCREEN does not exist, nowhere to put the screen shot!" + echo "Have you configured Storage Groups yet?" exit 1 fi -VIDEO_FILENAME=$(basename "$VIDEO_PATHNAME") -VIDEO_EXTENSION=${VIDEO_FILENAME##*.} +VIDEO_EXTENSION=${FILENAME##*.} # Since we cron'd lets first make sure the validity of the file if [ "$EXTENSION_CHECK" == "1" ]; then - EXCHECK=$(mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -sNBe "select f_ignore from videotypes where extension=\"$VIDEO_EXTENSION\";") - #excheck returns blank, it found nothing. + EXCHECK=$(mysql -u $DBUSERNAME -p$DBPASSWORD -h $BACKEND_HOSTNAME -D mythconverg -sNBe "select f_ignore from videotypes where extension='${VIDEO_EXTENSION}';") + #excheck returns blank, it found nothing. if [ "$EXCHECK" == "" ]; then if [ "$VERBOSE" == "1" ]; then echo "$VIDEO_EXTENSION does not appear to be a valid media file, skipping." fi exit 1 - else + else # It is valid, but should we ignore it. If so then excheck will equal 1. - if [ "EXCHECK" == "1" ]; then + if [ "EXCHECK" == "1" ]; then if [ "$VERBOSE" == "1" ]; then echo "$VIDEO_EXTENSION is set to ignore." fi exit 1 fi - # It is valid, it's not set to ignore. + # It is valid, it's not set to ignore. if [ "$VERBOSE" == "1" ]; then echo "$VIDEO_EXTENSION appears in the Database, checking further." fi - EXCHECK=$(mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -sNBe "select title from videometadata where filename=\"$VIDEO_PATHNAME\";") + EXCHECK=$(mysql -u $DBUSERNAME -p$DBPASSWORD -h $BACKEND_HOSTNAME -D mythconverg -sNBe "select title from videometadata where filename LIKE '%${FILENAME}';") #Right, the file is supposed to be playable. Has it been imported to the Db yet? if [ "$EXCHECK" == "" ] ; then - if [ "$VERBOSE" == "1" ]; then + if [ "$VERBOSE" == "1" ]; then echo "$VIDEO_FILENAME does not exist in the database." - fi + fi exit 1 - # If you decide you want the system to 'auto import' the video then comment out - # the exit line and uncomment the rest of it. Bewarned, this is sucky SQL at - # the best but will give sensible defaults. - # - # if [ "$VERBOSE" == "1" ]; then - # echo "Importing $VIDEO_FILENAME in to database." - # fi - # mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -sNBe "insert into videometadata (intid, title, director, plot, rating, inetref, year, userrating, length, showlevel, filename, coverfile, childid, browse, playcommand, category) values (' ', '$VIDEO_FILENAME', 'Unknown', 'Unknown', 'NR', '00000000', 1895, 0.0, 0, 1, '$VIDEO_PATHNAME', 'No Cover', -1, 1, ' ', 0);" fi fi fi if [ "$CLOBBER" -eq 0 ]; then # Since we're not clobbering, first check to see if this video already has a coverfile entry in MySQL: - SQL_CMD="select coverfile from videometadata where filename=\"$VIDEO_PATHNAME\";" - CURRENT_COVERFILE=`mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -B -e "$SQL_CMD" | tail -1` - - if [[ "$CURRENT_COVERFILE" != "" ]] && [[ "$CURRENT_COVERFILE" != "No Cover" ]]; then + SQL_CMD="SELECT coverfile FROM videometadata WHERE filename LIKE '%${FILENAME}';" + CURRENT_COVERFILE=`mysql -u $DBUSERNAME -p$DBPASSWORD -h $BACKEND_HOSTNAME -D mythconverg -B -e "$SQL_CMD" | tail -1` + + if [[ "$CURRENT_COVERFILE" != "" ]] && [[ "$CURRENT_COVERFILE" != " " ]] && [[ "$CURRENT_COVERFILE" != "No Cover" ]]; then # there's already a cover file for this video - if [ "$VERBOSE" == "1" ]; then - echo "$VIDEO_FILENAME has cover file, skipping." + if [ "$VERBOSE" == "1" ]; then + echo "$FILENAME has cover file, skipping." fi exit 2 fi @@ -151,7 +149,7 @@ fi # Swap the video file extension for png. Should work assuming the extension only appears ONCE! -VIDEO_CAPTURE_PATHNAME="$VIDEO_CAPTURE_HOME/$VIDEO_FILENAME.png" +VIDEO_CAPTURE_PATHNAME="$SG_SCREEN/${FILENAME%.*}.png" # How many frames of video to capture. We'll grab the last frame as our screenshot. if [ "$VIDEO_EXTENSION" == "m4v" ]; then @@ -163,13 +161,17 @@ fi SHOTFILE="000000"$FRAMES_TO_CAPTURE".png" VIDEO_STATS="/tmp/screenshooter_video_stats.txt" +# Get the full path of the video file, less the storage group prefix +FULL_PATH=$(mysql -u $DBUSERNAME -p$DBPASSWORD -h $BACKEND_HOSTNAME -D mythconverg -sNBe \ + "SELECT filename FROM videometadata WHERE filename LIKE '%${FILENAME}';") + cd /tmp # The video we're processing may be shorter than SKIPAHEAD seconds. # Keep trying to capture until we find a SKIPAHEAD value within the length of the video. # Give up if we reach 0 seconds. while [ ! -f "$SHOTFILE" ]; do - /usr/bin/mplayer -ss $SKIPAHEAD -vf scale=640:-2 -ao null -vo png -quiet -frames $FRAMES_TO_CAPTURE -identify "$VIDEO_PATHNAME" &> $VIDEO_STATS & + /usr/bin/mplayer -ss $SKIPAHEAD -vf scale=640:-2 -ao null -vo png -quiet -frames $FRAMES_TO_CAPTURE -identify "$SG_VIDEOS/$FULL_PATH" &> $VIDEO_STATS & TIMEOUT=9 # Some video formats will play audio only. This loop gives the above command 20 seconds to @@ -182,7 +184,7 @@ while [ ! -f "$SHOTFILE" ]; do fi sleep 1 done - + SKIPAHEAD=$(expr $SKIPAHEAD / 2) if [ "$SKIPAHEAD" -le 0 ]; then break @@ -205,20 +207,18 @@ if [ -f "$SHOTFILE" ]; then VIDEO_LENGTH_IN_MINUTES=$(expr $VIDEO_LENGTH_IN_INTEGER_SECONDS / 60) fi - SQL_CMD="update videometadata set length=\"$MIN_LENGTH\" where filename=\"$VIDEO_PATHNAME\";" - mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -e "$SQL_CMD" + SQL_CMD="UPDATE videometadata SET length = '${MIN_LENGTH}' WHERE filename LIKE '%$FILENAME';" + mysql -u $DBUSERNAME -p$DBPASSWORD -h $BACKEND_HOSTNAME -D mythconverg -e "$SQL_CMD" - # put the screenshot pathname and any runlength info into videometadatatable - # Pre-escape any single or double quotes for the SQL command. VIDEO_CAPTURE_PATHNAME=`echo $VIDEO_CAPTURE_PATHNAME | sed -e "s/'/\\\'/g" -e 's/"/\\\"/g' ` - VIDEO_PATHNAME=`echo $VIDEO_PATHNAME | sed -e "s/'/\\\'/g" -e 's/"/\\\"/g' ` - SQL_CMD="update videometadata set coverfile=\"$VIDEO_CAPTURE_PATHNAME\", length=\"$VIDEO_LENGTH_IN_MINUTES\" where filename=\"$VIDEO_PATHNAME\";" + FILENAME=`echo $FILENAME | sed -e "s/'/\\\'/g" -e 's/"/\\\"/g' ` + SQL_CMD="UPDATE videometadata SET coverfile = '${VIDEO_CAPTURE_PATHNAME}', length = '${VIDEO_LENGTH_IN_MINUTES}' WHERE filename LIKE '%${FILENAME}';" - mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -e "$SQL_CMD" + mysql -u $DBUSERNAME -p$DBPASSWORD -h $BACKEND_HOSTNAME -D mythconverg -e "$SQL_CMD" else - echo "No image could be captured from $VIDEO_PATHNAME" + echo "No image could be captured from $FILENAME" exit 1 fi |