Index: mythplugins/mythmusic/mythmusic/aacdecoder.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/aacdecoder.cpp	(revision 7607)
+++ mythplugins/mythmusic/mythmusic/aacdecoder.cpp	(working copy)
@@ -614,39 +614,9 @@
     deinit();
 }
 
-Metadata* aacDecoder::getMetadata()
+MetaIO* aacDecoder::doCreateTagger()
 {
-
-    Metadata *mdata = new Metadata(filename);
-    if (mdata->isInDatabase(musiclocation))
-    {
-      return mdata;
-    }
-    
-    delete mdata;
-
-    MetaIOMP4* p_tagger = new MetaIOMP4;
-    if (ignore_id3) {
-        mdata = p_tagger->readFromFilename(filename);
-    } else {
-        mdata = p_tagger->read(filename);
-    }
-    
-    delete p_tagger;
-
-    if (mdata)
-        mdata->dumpToDatabase(musiclocation);
-    else
-      error(QString("aacdecoder.o: Could not read metadata from \"%1\"").arg(filename.local8Bit()));
-
-    return mdata;
-}    
-
-void aacDecoder::commitMetadata(Metadata *mdata)
-{
-    MetaIOMP4* p_tagger = new MetaIOMP4;
-    p_tagger->write(mdata);
-    delete p_tagger;
+    return new MetaIOMP4;
 }
 
 uint32_t aacDecoder::aacRead(char *buffer, uint32_t length)
Index: mythplugins/mythmusic/mythmusic/decoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/decoder.h	(revision 7607)
+++ mythplugins/mythmusic/mythmusic/decoder.h	(working copy)
@@ -8,6 +8,7 @@
 #include <qptrlist.h>
 
 class Metadata;
+class MetaIO;
 class Decoder;
 class DecoderFactory;
 
@@ -79,9 +80,54 @@
     static Decoder *create(const QString &, QIODevice *, AudioOutput *, 
                            bool = FALSE);
 
-    virtual Metadata *getMetadata() = 0;
-    virtual void commitMetadata(Metadata *mdata) = 0;
+    /** \brief Read the metadata from \p filename directly.
+	
+        Creates a \p MetaIO object using \p Decoder::doCreateTagger and uses
+        the MetaIO object to read the metadata.
+        
+        \returns an instance of \p Metadata owned by the caller
+     */
+    virtual Metadata *readMetadata(void);
 
+    /** \brief Get the metadata  for \p filename 
+	
+        First tries to read the metadata from the database. If there
+        is no database entry, it'll call \p Decoder::readMetadata.
+
+		\returns an instance of \p Metadata owned by the caller
+    */
+    virtual Metadata *getMetadata(void);
+
+    /** \brief Create a \p MetaIO object for the format.
+
+        This method should be overwritten by subclasses to return an
+        instance of the appropriate MetaIO subtype. It is used by \p
+        Decoder::getMetadata, \p Decoder::readMetadata and \p
+        Decoder::commitMetadata.
+        
+        The default implementation returns a NULL pointer, which
+        essentially means, that if the decoder does not overrider this
+        method or all of the users (see previous paragraph), files
+        that the decoder supports cannot be indexed using metadata in
+        the file.
+
+		Eg. the mp3 decoder (\p MadDecoder) implements this, whereas
+		the audio CD decoder (\p CdDecoder) does not.
+
+		\returns an instance of \p MetaIO owned by the caller
+     */
+    virtual MetaIO *doCreateTagger (void);
+
+    /** \brief Write the given metadata to the \p filename.
+	
+        Creates a \p MetaIO object using \p Decoder::doCreateTagger and
+        asks the MetaIO object to write the contents of mdata to \p
+        filename.
+
+        \params mdata the metadata to write to the disk
+     */
+    virtual void commitMetadata(Metadata *mdata);
+
     static void SetLocationFormatUseTags(void);
 
     QString getFilename(void) { return filename; }
Index: mythplugins/mythmusic/mythmusic/cddecoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/cddecoder.h	(revision 7607)
+++ mythplugins/mythmusic/mythmusic/cddecoder.h	(working copy)
@@ -26,8 +26,8 @@
     int getNumCDAudioTracks(void);
 
     Metadata *getMetadata(int track);
-    Metadata *getMetadata();
-    Metadata *getLastMetadata();
+    Metadata *getMetadata(void);
+    Metadata *getLastMetadata(void);
     void commitMetadata(Metadata *mdata);
 
   private:
Index: mythplugins/mythmusic/mythmusic/decoder.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/decoder.cpp	(revision 7607)
+++ mythplugins/mythmusic/mythmusic/decoder.cpp	(working copy)
@@ -6,6 +6,8 @@
 
 #include "decoder.h"
 #include "constants.h"
+#include "metadata.h"
+#include "metaio.h"
 #include <mythtv/output.h>
 #include <mythtv/visual.h>
 
@@ -87,7 +89,58 @@
     listeners.remove(object);
 }
 
+Metadata *Decoder::readMetadata(void) 
+{
+    Metadata *mdata = NULL;
+    MetaIO* p_tagger = doCreateTagger();
 
+    if (p_tagger) 
+    {
+        if (ignore_id3)
+            mdata = p_tagger->readFromFilename(filename);
+        else
+            mdata = p_tagger->read(filename);
+        
+        delete p_tagger;
+    } 
+    else 
+    {
+        if (!mdata)
+            cerr << "maddecoder.o: Could not read metadata from " << filename.local8Bit() << endl;
+    }
+
+    return mdata;    
+}
+
+Metadata* Decoder::getMetadata(void)
+{
+
+    Metadata *mdata = new Metadata(filename);
+    if (mdata->isInDatabase(musiclocation))
+    {
+      return mdata;
+    }
+    
+    delete mdata;
+
+    return readMetadata();
+}    
+
+void Decoder::commitMetadata(Metadata *mdata)
+{
+    MetaIO* p_tagger = doCreateTagger();
+    if (p_tagger) 
+    {
+        p_tagger->write(mdata);
+        delete p_tagger;
+    }
+}
+
+MetaIO *Decoder::doCreateTagger() 
+{
+    return NULL;
+}
+
 // static methods
 
 int Decoder::ignore_id3 = 0;
Index: mythplugins/mythmusic/mythmusic/aacdecoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/aacdecoder.h	(revision 7607)
+++ mythplugins/mythmusic/mythmusic/aacdecoder.h	(working copy)
@@ -29,8 +29,7 @@
     void seek(double);
     void stop();
 
-    Metadata *getMetadata();
-    void commitMetadata(Metadata *mdata);
+    MetaIO *doCreateTagger(void);
 
     bool     initializeMP4();
     int      getAACTrack(mp4ff_t *infile);
Index: mythplugins/mythmusic/mythmusic/vorbisdecoder.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/vorbisdecoder.cpp	(revision 7607)
+++ mythplugins/mythmusic/mythmusic/vorbisdecoder.cpp	(working copy)
@@ -293,38 +293,9 @@
     deinit();
 }
 
-Metadata *VorbisDecoder::getMetadata()
+MetaIO *VorbisDecoder::doCreateTagger()
 {
-    Metadata *mdata = new Metadata(filename);
-    if (mdata->isInDatabase(musiclocation))
-    {
-        return mdata;
-    }
-
-    delete mdata;
-
-
-    MetaIOOggVorbisComment* p_tagger = new MetaIOOggVorbisComment;
-    if (ignore_id3)
-        mdata = p_tagger->readFromFilename(filename);
-    else
-        mdata = p_tagger->read(filename);
-
-    delete p_tagger;
-
-    if (mdata)
-        mdata->dumpToDatabase(musiclocation);
-    else
-        cerr << "vorbisdecoder.o: Could not read metadata from " << filename.local8Bit() << endl;    
-
-    return mdata;
-}    
-
-void VorbisDecoder::commitMetadata(Metadata *mdata)
-{
-    MetaIOOggVorbisComment* p_tagger = new MetaIOOggVorbisComment;
-    p_tagger->write(mdata);
-    delete p_tagger;
+    return new MetaIOOggVorbisComment;
 }
 
 
Index: mythplugins/mythmusic/mythmusic/flacdecoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/flacdecoder.h	(revision 7607)
+++ mythplugins/mythmusic/mythmusic/flacdecoder.h	(working copy)
@@ -22,8 +22,7 @@
     void doWrite(const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
     void setFlacMetadata(const FLAC__StreamMetadata *metadata);
 
-    Metadata *getMetadata();
-    void commitMetadata(Metadata *mdata);
+    MetaIO *doCreateTagger(void);
 
   private:
     void run();
Index: mythplugins/mythmusic/mythmusic/avfdecoder.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/avfdecoder.cpp	(revision 7607)
+++ mythplugins/mythmusic/mythmusic/avfdecoder.cpp	(working copy)
@@ -357,40 +357,11 @@
     deinit();
 }
 
-Metadata* avfDecoder::getMetadata()
+MetaIO* avfDecoder::doCreateTagger()
 {
-    Metadata *mdata = new Metadata(filename);
-    if (mdata->isInDatabase(musiclocation))
-    {
-        return mdata;
-    }
-
-    delete mdata;
-
-
-    MetaIOAVFComment* p_tagger = new MetaIOAVFComment;
-    if (ignore_id3)
-        mdata = p_tagger->readFromFilename(filename);
-    else
-        mdata = p_tagger->read(filename);
-    
-    delete p_tagger;
-
-    if (mdata)
-        mdata->dumpToDatabase(musiclocation);
-    else
-        cerr << "avfdecoder.o: Could not read metadata from " << filename << endl;
-
-    return mdata;
+    return new MetaIOAVFComment;
 }    
 
-void avfDecoder::commitMetadata(Metadata *mdata)
-{
-    MetaIOAVFComment* p_tagger = new MetaIOAVFComment;
-    p_tagger->write(mdata);
-    delete p_tagger;
-}
-
 bool avfDecoderFactory::supports(const QString &source) const
 {
     return (source.right(extension().length()).lower() == extension());
Index: mythplugins/mythmusic/mythmusic/main.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/main.cpp	(revision 7607)
+++ mythplugins/mythmusic/mythmusic/main.cpp	(working copy)
@@ -65,20 +65,34 @@
     return decoder;
 }
 
-void CheckFile(const QString &filename)
+void AddFileToDB(const QString &directory, const QString &filename)
 {
     Decoder *decoder = getDecoder(filename);
 
     if (decoder)
     {
         Metadata *data = decoder->getMetadata();
-        if (data)
+        if (data) {
+            data->dumpToDatabase(directory);
             delete data;
+        }
 
         delete decoder;
     }
 }
 
+// Remove a file from the database
+void RemoveFileFromDB (const QString &directory, const QString &filename)
+{
+    QString name(filename);
+    name.remove(0, directory.length());
+    MSqlQuery query(MSqlQuery::InitCon());
+    query.prepare("DELETE FROM musicmetadata WHERE "
+                  "filename = :NAME ;");
+    query.bindValue(":NAME", name.utf8());
+    query.exec();
+}
+
 enum MusicFileLocation
 {
     kFileSystem,
@@ -196,8 +210,7 @@
     busy->start();
     BuildFileList(directory, music_files);
     busy->Close();
-    busy->deleteLater();
-    busy = NULL;
+    delete busy;
 
     MSqlQuery query(MSqlQuery::InitCon());
     query.exec("SELECT filename "
@@ -234,24 +247,14 @@
     file_checking = new MythProgressDialog(
         QObject::tr("Updating music database"), music_files.size());
 
-    QRegExp quote_regex("\"");
+    counter = 0;
     for (iter = music_files.begin(); iter != music_files.end(); iter++)
     {
         if (*iter == kFileSystem)
-        {
-            CheckFile(iter.key());
-        }
+            AddFileToDB(directory, iter.key());
         else if (*iter == kDatabase)
-        {
-            QString name(iter.key());
-            name.remove(0, directory.length());
+            RemoveFileFromDB(directory, iter.key ());
 
-            query.prepare("DELETE FROM musicmetadata WHERE "
-                          "filename = :NAME ;");
-            query.bindValue(":NAME", name.utf8());
-            query.exec();
-        }
-
         file_checking->setProgress(++counter);
     }
     file_checking->Close();
Index: mythplugins/mythmusic/mythmusic/flacdecoder.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/flacdecoder.cpp	(revision 7607)
+++ mythplugins/mythmusic/mythmusic/flacdecoder.cpp	(working copy)
@@ -385,40 +385,12 @@
         char *field_value;
 } Argument_VcField;
 
-Metadata *FlacDecoder::getMetadata()
+MetaIO *FlacDecoder::doCreateTagger()
 {
-    Metadata *mdata = new Metadata(filename);
-    if (mdata->isInDatabase(musiclocation))
-    {
-        return mdata;
-    }
+    return new MetaIOFLACVorbisComment;
+}
 
-    delete mdata;
 
-    MetaIOFLACVorbisComment* p_tagger = new MetaIOFLACVorbisComment;
-    if (ignore_id3)
-        mdata = p_tagger->readFromFilename(filename);
-    else
-        mdata = p_tagger->read(filename);
-
-    delete p_tagger;
-
-    if (mdata)
-        mdata->dumpToDatabase(musiclocation);
-    else
-        cerr << "flacdecoder.o: Could not read metadata from " << filename.local8Bit() << endl;
-
-    return mdata;
-}    
-
-void FlacDecoder::commitMetadata(Metadata *mdata)
-{
-    MetaIOFLACVorbisComment* p_tagger = new MetaIOFLACVorbisComment;
-    p_tagger->write(mdata);
-    delete p_tagger;
-    }
-
-
 bool FlacDecoderFactory::supports(const QString &source) const
 {
     return (source.right(extension().length()).lower() == extension());
Index: mythplugins/mythmusic/mythmusic/maddecoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/maddecoder.h	(revision 7607)
+++ mythplugins/mythmusic/mythmusic/maddecoder.h	(working copy)
@@ -24,8 +24,7 @@
     static const int maxFrameCheck;
     static const int initialFrameSize;
 
-    Metadata *getMetadata();
-    void commitMetadata(Metadata *mdata);
+    MetaIO *doCreateTagger(void);
 
 private:
     void run();
Index: mythplugins/mythmusic/mythmusic/vorbisdecoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/vorbisdecoder.h	(revision 7607)
+++ mythplugins/mythmusic/mythmusic/vorbisdecoder.h	(working copy)
@@ -18,8 +18,7 @@
     void seek(double);
     void stop();
 
-    Metadata *getMetadata();
-    void commitMetadata(Metadata *mdata);
+    MetaIO *doCreateTagger(void);
 
   private:
     void run();
Index: mythplugins/mythmusic/mythmusic/avfdecoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/avfdecoder.h	(revision 7607)
+++ mythplugins/mythmusic/mythmusic/avfdecoder.h	(working copy)
@@ -18,8 +18,7 @@
     void seek(double);
     void stop();
 
-    Metadata *getMetadata();
-    void commitMetadata(Metadata *mdata);
+    MetaIO *doCreateTagger(void);
 
   private:
     void run();
Index: mythplugins/mythmusic/mythmusic/maddecoder.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/maddecoder.cpp	(revision 7607)
+++ mythplugins/mythmusic/mythmusic/maddecoder.cpp	(working copy)
@@ -512,40 +512,11 @@
     return MAD_FLOW_STOP;
 }
 
-Metadata *MadDecoder::getMetadata()
+MetaIO *MadDecoder::doCreateTagger()
 {
-    Metadata *mdata = new Metadata(filename);
-    if (mdata->isInDatabase(musiclocation))
-    {
-        return mdata;
-    }
-
-    delete mdata;
-
-
-    MetaIOID3v2* p_tagger = new MetaIOID3v2;
-    if (ignore_id3)
-        mdata = p_tagger->readFromFilename(filename);
-    else
-        mdata = p_tagger->read(filename);
-
-    delete p_tagger;
-
-    if (mdata)
-        mdata->dumpToDatabase(musiclocation);
-    else
-        cerr << "maddecoder.o: Could not read metadata from " << filename.local8Bit() << endl;
-
-    return mdata;
+    return new MetaIOID3v2;
 }
 
-void MadDecoder::commitMetadata(Metadata *mdata)
-{
-    MetaIOID3v2* p_tagger = new MetaIOID3v2;
-    p_tagger->write(mdata);
-    delete p_tagger;
-}
-
 bool MadDecoderFactory::supports(const QString &source) const
 {
     bool res = false;
