Friday, March 20, 2009

Scraping The Browser Cache for Video Files

I use the following script to find video files in the web browser's (Iceweasel/Firefox) cache directory (or any other directory that's provided as an argument):

#! /bin/sh
find $cache -print0 | xargs --null file | grep -e "[^:]*:.*\([Vv]ideo\|MPEG v4\|Microsoft ASF\)" | cut -d: -f1 | sort -u |
while read file ; do
    mplayer -identify -frames 0 -vo null -nosound "$file" 2>&1
done | 
gawk -F= '
($1=="ID_FILENAME") {
($1=="ID_VIDEO_WIDTH") {
($1=="ID_VIDEO_FPS") {
($1=="ID_LENGTH" && $2 != 0) {
    print file" ("format") "w"x"h" ("$2" sec, "fps" fps)"
(have you noticed that this is actually an overgrown one-liner?)



  1. You could also check (in graphic mode) with nautilus that link in your script (I go to /temp actually) if the 'video/audio preview' is trying to read a video file. And do a copy of it.

    I have been using this method all the time. Just wait until it finish downloading the streamed video (or audio) and copy it whenever I want to.

    At least that works on Debian and Ubuntu.

    What exactly does that script?
    Search for videos with mplayer and tell you what it discovers?

    What if I don't use mplayer?
    Have you tried with, lets say, totem or vlc?

  2. The script just lists all video files in the cache directory, together with their respective length in seconds and frame size.

    You're right of course - visual inspection of the cache directory contents is the straightforward way of doing this.

    But I find nautilus to be rather slow on my old machine. It's also cumbersome, since I usually right-click each multimedia file that I find in order to view its properties. The script simply automates the process.

    I use 'find' and 'file' to do the search. And I only use mplayer to get the file properties. I don't know if this is possible to do at the command line with totem or vlc.