network shenanigans or just smoke and mirrors

Saving Video Files

October 29th, 2009 by geezer

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

clear

echo "Video Saver Script Foo by geezer"
echo

PID=`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
fi

if [ "$DELETED" == "(deleted)" ]; then
     echo "Video is no longer in cache! Please replay."
     exit;
fi

if [ "$1" == "-d" ]; then
	echo $PID
	echo $VIDEO
fi

echo -n "Name your video file: "
read NAME

cp $VIDEO $NAME.flv

echo
echo -n "Do you want to play the video now?  "
read ANSWER

case $ANSWER in
	y | y)
		mplayer $NAME.flv &> /dev/null &
		echo;;
	N | n)
		exit;;
	    *)
		exit;;
esac



And here’s the OS X version:

#! /bin/bash
clear

echo "Video Saver Script Foo by geezer"
echo

PID=`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
fi

if [ "$1" == "-d" ]; then
	echo $PID
	echo $VIDEO
fi

echo -n "Name your video file: "
read NAME

cp $VIDEO $NAME.flv

echo
echo -n "Do you want to play the video now?  "
read ANSWER

case $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 »

One Response

  1. teastburn Says:

    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

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.