Posts tagged shell script

media management script

I’ve always heard “necessity is the mother of invention”.  I’m sure you’ve come across this a time or two as well.  While this idiom is true, it is not a whole truth.  Necessity is not the ONLY mother of invention ;)  Laziness, boredom — pick your poison.  Well, I’ve sure been bored.  Bored enough to write a script that I could have likely picked up on my first search of google.  Last night I was watching a movie, fighting boredom tooth and nail the entire way, and I lost.  I was thinking about how I always manually manage my movies and music.  So very 20th century.

I decided I’d write a quick little script to manage this, and so I did.  And here it is, nothing fancy.  This fits my personal needs,  but I’d be happy to oblige any change/fix requests.  It will use the ID3 tag data from the first file in a directory to create destination directories and move all MP3s there.  The script utilizes mp3info to perform this ID3 tag information retrieval, so be sure you have it installed.  I did not add any sanity checks to the script!

There is one caveat soundtracks will not workout in your favor, additional logic is required to handle these.  I rarely if ever download soundtracks, so it has not been included — yet.  This has been addressed and soundtracks are now supported.

As I’m sure you’re aware, the easiest method for implementing this script is a cron job.  Below is my cron entry:

*/15 * * * * /usr/bin/mvdownloads >> /tmp/mvdownloads.log

This will run the cron job every 15 minutes and redirect the output to /tmp/mvdownloads.log.  Very simple.  I believe that covers everything — oh, if you do not restart your machine often, make sure that you have some mechanism for removing temp files/logs that either or not needed or are too large :)  Logging in this script is very basic!

Updates:

(12-20-09) – Fixed a bug where small or sample media files would not get deleted.  Included variable for movie size threshold so this can be adjusted based on your management needs.  Finalized logging output. Included support for soundtracks (Note: this causes the script to run longer, not much, and once the initial execution is complete, you will find it is negiligible.). Removed unnecessary debug logging, script is complete for now.

(12-19-09) – Added additional protection for primary source directory to ensure files are not lost, cleaned up logging, and organized script a bit better.  Added functionality to update firefly media server database.  Please note, this functionality requires additional variables set in the mt-daapd configuration file, read the script comments before using this or you will see no gain!  I’ve decided not to add concatenation support into the script, as sequence matching would be a bit iffy and the little benefit from this isn’t worth the possible issues.

(12-14-09) – Modified script so that the find command is case insensitive for all occurrences.

So here it is, enjoy: http://www.trippholden.com/wp-content/uploads/2009/12/mvdownloads

G1 USB Tethering Startup Script for use with Azilink

A couple months ago, I was at Charlotte Douglas International Airport waiting on my flight to NYC.  As usual, I had a connecting flight on my way from the tiny airport in my hometown to New York.  After an hour or so of reading, I decided it was a good chance for me to check my email and check my fantasy football team.  In typical fashion, the CLT Airport wireless would not allow me to connect — it’s a rather pathetic implementation, although I’ve devoted absolutely no time or thought to what the problem may be.

Anyway, I decided to use my G1, which is very nice and all, but for continued use, just doesn’t fit the bill.  That’s when it occurred to me that I had not checked on tethering capabilities in a while.  So I did a bit of research and came across this site:  http://xdatap1.wordpress.com/2009/08/10/g1-usb-tethering-with-ubuntu/.  This was a very informative and complete set of instructions for setting up USB tethering on my linux box/G1 phone.  In about 15 minutes (most of it downloading the necessary files) I was up and running.  I had my laptop browsing the web using the 3G capabilities of my G1!

The only thing that was missing from this was a startup script, so I decided to create one as usual to make my life a bit easier.  Please use, update, change, improve this script as you see fit.  The only thing I ask is if you come up with any improvements, please let me know!

Download it HERE.