My situation involves a directory containing MP3 files, and a database that should contain all the MP3 metadata (i.e. genres, artist names, album names, and track names) from the MP3 files in that directory. The database should always reflect what is in the directory, that is... the algorithm I'm searching for should never delete items from the directory, only from database. The directory is the original, the database should be the exact copy of the directory after the program is run, and the directory should remain untouched by the program.
From my understanding, I believe I would have to loop over the contents of the directory inserting records in the database when I come across MP3 metadata that is found in the directory but isn't found in the database. Then, loop over the contents of the database and delete from the database what isn't found in the directory.
Is there a general algorithm for synchronizing two things such as a directory and a database? Is there a better way to do this than what I've outlined?
I'm trying to complete this task using Ruby Sequel and MySQL, in case that matters.
Just to clarify, assume all MP3 tag data is correct. I run all files through an automatic MP3 tagger and make sure everything is accurately tagged before moving it to this directory.
My preferred solution would be by running a Ruby script manually, rather than with Cron for example. My reasons being because it is the language I am already using to implement most of this project, and I must manually tag all MP3 files and verify they are correct, so I don't want any scripts to be ran until I can verify that all files in my MP3 directory are good to go.