Tagged “bash”

DVD-Titel auslesen mit VLC und Durchsatzmessung

Published by cybso on

This is a post from my original site, which was hosted by the former blog service of the University of Osnabrück. I have moved it to the new site for archiving. Pages linked in this article may no longer work today, and the blog comments under the article no longer exist. Opinions expressed in this article reflect the point of view of the time of publication and do not necessarily reflect my opinion today.

vlcvob:

#!/bin/sh

# Check prerequirements (assume that 'rm', 'mkfifo' etc are available)
echo "Checking prerequirements..."
if ! (which mktemp && which pv && which cvlc); then
    echo "Missing required programs. See output for info." >&2
    exit 1
fi

source="$1"
destination="$2"
fifo="$(mktemp)"

if [ "x$source" = "x" ] || [ "x$destination" = "x" ]; then
    echo "Read vob file from DVD using VLC." >&2
    echo "Usage: $0  " >&2
    echo "Example:" >&2
    echo "    Store first title from device '/dev/dvd' to 'filename.vob':">&2
    echo "    $0 dvdsimple:///dev/dvd@1 filename.vob" >&2
    exit 1
fi

if [ -e "$destination" ]; then
    echo "File '$destination' already exists. Please remove first." >&2
    exit
fi

# Command from http://www.gentoo-wiki.info/HOWTO_Backup_a_DVD.
# Other commands that should work (untested):
#    CMD="mplayer dvd://$TITLE -dvd-device $DEVICE -dumpstream -dumpfile '$fifo'"
#    CMD="mplayer dvdnav://$TITLE -nocache -dvd-device $DEVICE -dumpstream -dumpfile '$fifo'"
CMD="cvlc '$source' --sout '#standard{access=file,mux=ps,dst=$fifo}' vlc://quit"

echo "Creating FIFO file '$fifo'..."
rm "$fifo" && mkfifo "$fifo" || exit 1

echo "Starting VLC: $CMD"
eval $CMD &
vlcpid="$!"

# Wait a second or so to let VLC do it's work
sleep 5

pv -petrb "$fifo" > "$destination" &
pvpid="$!"

wait "$vlcpid"
kill "$pvpid"
rm "$fifo"

Disclaimer:

Selbstverständlich sind dabei die Urheberrechte zu beachten! Für selbsterstellte DVDs ist das unproblematisch. Ein Kopierschutz darf jedoch zumindest in Deutschland nicht umgangen werden.

How to escape filenames for save use within shell scripts

Published by cybso on

With bash and printf:

$ mkdir test
$ cd test
$ touch 'Little boby tab$(ls)'
$ ls -l
-rw-rw-r-- 1 roland roland 0 Mär 30 15:18 Little boby tab$(ls)
$ eval $(echo rm -v "$(echo Little*)")
rm: cannot remove 'Little': No such file or directory
rm: cannot remove 'boby': No such file or directory
rm: cannot remove 'tabLittle': No such file or directory
rm: cannot remove 'boby': No such file or directory
rm: cannot remove 'tab$(ls)': No such file or directory
$ printf %q Little*
Little\ boby\ tab\$\(ls\)
$ eval $(echo rm -v "$(printf %q Little*)")
removed 'Little boby tab$(ls)'