Saving Video Files
I got this idea from Linux Journal. After you have watched a video online, run this script to save a local copy in the same place this script is run.
Some pre-reqs: I assume Firefox is your browser in both Linux and OS X, and I assume you have mplayer installed in Linux and VLC in OS X.
Here’s the Linux version:
#! /bin/bash
clearecho "Video Saver Script Foo by geezer"
echoPID=`ps xfa | grep firefox | awk '/firefox/ { print $1 }' | head -1`
VIDEO=`ls -lU /proc/$PID/fd | grep Flash | awk '{ print $10 }' | tail -1`
DELETED=`ls -lU /proc/$PID/fd | grep Flash | awk '{ print $11 }' | tail -1`if [ "$VIDEO" == "" ]; then
echo "No video found!"
exit
fiif [ "$DELETED" == "(deleted)" ]; then
echo "Video is no longer in cache! Please replay."
exit;
fiif [ "$1" == "-d" ]; then
echo $PID
echo $VIDEO
fiecho -n "Name your video file: "
read NAMEcp $VIDEO $NAME.flv
echo
echo -n "Do you want to play the video now? "
read ANSWERcase $ANSWER in
y | y)
mplayer $NAME.flv &> /dev/null &
echo;;
N | n)
exit;;
*)
exit;;
esac
And here's the OS X version:
#! /bin/bash
clearecho "Video Saver Script Foo by geezer"
echoPID=`ps xa | grep firefox | awk '/firefox/ { print $1 }' | head -1`
VIDEO=`lsof -p $PID | grep FlashTmp | awk '{ print $9 }' | tail -1`
if [ "$VIDEO" == "" ]; then
echo "No video found!"
exit
fiif [ "$1" == "-d" ]; then
echo $PID
echo $VIDEO
fiecho -n "Name your video file: "
read NAMEcp $VIDEO $NAME.flv
echo
echo -n "Do you want to play the video now? "
read ANSWERcase $ANSWER in
Y | y)
if [ -f "/Applications/VLC.app/Contents/MacOS/VLC" ]; then
open -a VLC $NAME.flv &> /dev/null &
else
echo "VLC is not found."
exit
fi
echo;;
N | n)
exit;;
*)
exit;;
esac
Posted in Chatter | 1 Comment »
October 30th, 2009 at 5:11 pm
I haven’t run this script (I’m using Ubuntu Linux), but I ran the PID=`…` line and it would always grab the PID of the grep command. This worked for me:
ps xfa | grep firefox | awk ‘/firefox\-/ { print $1 }’ | head -1