Showing posts with label videos. Show all posts
Showing posts with label videos. Show all posts

Friday, April 1, 2011

Saving watched online videos in linux, firefox cache flash extractor bash script

I recently upgraded to Ubuntu 10.10 and needed to rewrite a couple of useful scripts I use.

Here's a simplified version of a bash script that reads your firefox cache, finds flash files over a certain size, saves them in directory and opens the directory with nautilus to browse the extracted videos/flash files:

#!/bin/bash
# flvcache script

CACHE=~/.mozilla/firefox/xxxxxxxx.default/Cache
OUTPUTDIR=~/Videos/flvs
MINFILESIZE=2M

for f in `find $CACHE -size +$MINFILESIZE`
do
    a=$(file $f | cut -f2 -d ' ')
    o=$(basename $f)
    if [ "$a" = "Macromedia" ]
        then
            cp "$f" "$OUTPUTDIR/$o"
    fi
done

nautilus  "$OUTPUTDIR"&

Remember to chmod 755 the file so you can execute it from the command line.

Change the variable CACHE to your firefox cache location, it'll be somewhere like: ~/.mozilla/firefox/xxxxxxxx.default/Cache

Create a directory to save them into, I chose:
mkdir ~/Videos/flvs

I hope somebody finds this useful.

The script is presented in a simplified format to show bash scripting, you can see how to: use a for loop using bash, load output from external programs into a variable using bash and use an if statement using bash.