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