Saturday, February 28, 2009

More Bash tricks

While trying to figure out how to pack several scripts of functionality into a single script to make it a bit more portable (and depending on filesystem, possibly more efficient), I came up with the following concept, which has probably been used in quite a few programs before for consolidation purposes.


case "$(basename $0)" in
"rip.tv.sh")
[tv-dvd rip procedure]
;;
"rip.movie.sh")
[movie-dvd procedure]
;;
"rip.trailer.sh")
[music video or trailer rip procedure]
;;
esac

Of course, in order to use this, you then have to symlink (or hard link, your choice) the alternate names to the script to the actual script.

Friday, February 27, 2009

HandBrakeCLI helper

In attempting to automate some things with HandBrake, I've started using bash wrappers to handle passing the proper sets of parameters for the type of encode desired.

One hiccup I've noticed is that some DVDs have their directories upper case, while others have them as lower case.
My solution, after doing some searching online for how to use the bash built-in tests is as follows.


#!/bin/bash
if [ -d "/media/dvd/VIDEO_TS" ]; then
  location="/media/dvd/VIDEO_TS";
else
  location="/media/dvd/video_ts";
fi
HandBrakeCLI -i $location -t 0