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.

8 comments:

  1. thanks, this works great, I can keep a copy of any good video I watch online

    ReplyDelete
  2. thanks a lot it works great!

    ReplyDelete
  3. Great work. Your script will be featured on Episode 196 of Category5 Technology TV.

    Thanks for sharing this with the community!

    ReplyDelete
  4. Thank you, was very helpful.

    ReplyDelete
  5. I used a version of this script in combination with a proxy rule in order to save Pandora music. Thanks!

    ReplyDelete
  6. Thanks, but it doesn't work now for Youtube. Regards

    ReplyDelete