Firefox 4: How to capture Flash video from cache
by Fran Ontanaya
Firefox 4 changed how the cache is stored. Until now it was easy to find cached Flash videos and copy them elsewhere to save them. On Linux, the new caching method plainly removes their entry from the filesystem and you can’t access them directly. But, of course, Firefox still can access the cached data ―through symlinks―, so we only need to follow the same path.
I will save you the reading ―just copy the following code to a new file called, for example, cpflash.sh, inside ~/bin, replacing /home/user/temporaldirectory with a folder where the script can process the files (keep it empty!) and /home/user/saveto with the folder where you want to store the captured videos:
#!/bin/bash
tempDir="/home/user/temporaldirectory"
saveTo="/home/user/saveto"
if [ ! -d "$tempDir" ]; then
echo "Error 1: $tempDir doesn't exist"
exit 1
fi
if [ ! -d "$saveTo" ]
then
echo "Error 2: $saveTo doesn't exist"
exit 1
fi
now=$(date '+%s')
pid=$(ps -C plugin-container -o pid= | awk '{print $1}')
if [ "$pid" ]
then
if [ -d "/proc/$pid/fd" ]
then
cd /proc/$pid/fd
files=$(ls -al | grep Flash | awk '//{printf "%s ", $8}')
if [ "$files" ]
then
cp -v $files $tempDir
cd $tempDir
for i in *
do
mv -v $tempDir/$i $saveTo/$now$i.flv
done
else
echo "Error 5: No cached flash videos were found."
fi
else
echo "Error 4: Couldn't find /proc/$pid/fd"
fi
else
echo "Error 3: Couldn't get a PID for plugin-container"
fi
Now load the flash videos and, once they are fully buffered, run the script (if you put it inside ~/bin, you can just type “cpflash.sh”). The files will be copied from the hidden cache to your destination folder and renamed to avoid overwriting the older ones. If you want to capture more videos, close the tabs with the videos you already got, buffer the new ones and repeat.
And here are the great news: unlike the Firefox 3 cache (the one you could access through your profile folder, and where file size was capped at 64MB), this cache stores the whole video!
PS. If you found this useful, why not buy me a beer? Good karma keeps the world rolling!


