Monday, November 24, 2008

fixfiles.py - A python script to rename files

Tired of crazy filenames with lots of spaces, CAPS and other characters on your linux machine? Many *nix users transfer files from windows or mac computers where filenames with spaces and other characters included in them dont matter so much. Here in the linux world, some people care about the excessive use of escaping all those spaces when addressing those filenames.

I wrote a simple python script to help me fix this for myself. The script will rename files that contain uppercase, ampersand or spaces and convert them into characters a bit more friendly to you while managing your files on your linux machine. Here is an example of it in action:

$ fixfiles.py /home/nmaxwell/foo/
Renaming: foo/YaDDA YAdda YaddA to: foo/yadda__yadda_yadda__
Renaming: foo/File With CAPS & Stuff to: foo/file_with_caps_-and-_stuff
Renaming: foo/BaZ to: foo/baz
Renaming: foo/Bar to: foo/bar
Renaming: foo/fOO to: foo/foo

As shown, it just searches filenames in a given directory, and renames them to be a little friendlier for you by changing the characters to something easier to manage.

Download fixfiles.py

Wednesday, November 19, 2008

Resizing avi or mpg video files for pmp devices

Recently I was looking for a small linux program to resize my avi and mpg files down to a smaller resolution to fit on my pmp device (Cowon D2), but didn't find much in the way of lightweight programs to do this. Up until now, I have just been using transcode on the cli with a bunch of options, but got tired of typing `history | grep transcode` or Ctrl+r to search my bash history for the exact params I used last time.

So, I just scripted this into a tiny python program to do what I wanted. Its called mini-encoder.py and simply resizes an avi or mpg file down to a resolution of 320x240, which is the native resolution on my Cowon D2 pmp player. The script also does some checks to make sure you are using the right input files, and that they actually exist!

The resolution is also hard-coded in the script itself, so if you want to use it and need a different resolution, just alter the resolution setting in the script. I am planning on adding a command line option to specify a resolution of choice, but haven't got around to doing it yet. Hope someone else finds this useful too. Enjoy!

Click on the link below to download the script (I have this hosted @ box.net):

Download mini-encoder.py