diff --exclude='Makefile*' --exclude='*svn*' -ru ../observable/mythplugins/mythmusic/mythmusic/metadata.cpp mythplugins/mythmusic/mythmusic/metadata.cpp
--- ../observable/mythplugins/mythmusic/mythmusic/metadata.cpp	2005-11-23 12:40:28.000000000 -0800
+++ mythplugins/mythmusic/mythmusic/metadata.cpp	2005-11-30 10:28:40.267856112 -0800
@@ -119,6 +119,24 @@
         MythContext::DBError("music persist", query);
 }
 
+int Metadata::compare(Metadata *other) 
+{
+    if (format == "cast") 
+    {
+        int artist_cmp = qstrcmp (Artist(), other->Artist());
+        int title_cmp = qstrcmp (Title(), other->Title());
+        
+        if (artist_cmp == 0) 
+            return title_cmp;
+        
+        return artist_cmp;
+    } 
+    else 
+    {
+        return (Track() - other->Track());
+    }
+}
+
 bool Metadata::isInDatabase(QString startdir)
 {
     bool retval = false;
@@ -128,7 +146,7 @@
 
     MSqlQuery query(MSqlQuery::InitCon());
     query.prepare("SELECT artist,compilation_artist,album,title,genre,year,tracknum,"
-                  "length,intid,rating,playcount,lastplay,compilation FROM "
+                  "length,intid,rating,playcount,lastplay,compilation,format FROM "
                   "musicmetadata WHERE filename = :FILENAME ;");
     query.bindValue(":FILENAME", sqlfilename.utf8());
 
@@ -149,6 +167,7 @@
         playcount = query.value(10).toInt();
         lastplay = query.value(11).toString();
         compilation = (query.value(12).toInt() > 0);
+        format = query.value(13).toString();
         
         retval = true;
     }
@@ -181,7 +200,8 @@
                   "( album = :ALBUM ) AND ( title = :TITLE ) "
                   "AND ( genre = :GENRE ) AND "
                   "( year = :YEAR ) AND ( tracknum = :TRACKNUM ) "
-                  "AND ( length = :LENGTH ) );");
+                  "AND ( length = :LENGTH ) "
+                  "AND ( format = :FORMAT) );");
     query.bindValue(":ARTIST", artist.utf8());
     query.bindValue(":COMPILATION_ARTIST", compilation_artist.utf8());
     query.bindValue(":ALBUM", album.utf8());
@@ -190,6 +210,7 @@
     query.bindValue(":YEAR", year);
     query.bindValue(":TRACKNUM", tracknum);
     query.bindValue(":LENGTH", length);
+    query.bindValue(":FORMAT", format);
 
     if (query.exec() && query.isActive() && query.size() > 0)
         return;
@@ -197,11 +218,13 @@
     query.prepare("INSERT INTO musicmetadata "
                   "(artist,   compilation_artist, album,      title,  "
                   " genre,    year,               tracknum,   length, "
-                  " filename, compilation,        date_added, date_modified) "
+                  " filename, compilation,        date_added, date_modified, "
+                  " format ) "
                   "VALUES "
                   "(:ARTIST,  :COMPILATION_ARTIST,:ALBUM,     :TITLE,   "
                   " :GENRE,   :YEAR,              :TRACKNUM,  :LENGTH,  "
-                  " :FILENAME,:COMPILATION,       :DATE_ADDED,:DATE_MOD)");
+                  " :FILENAME,:COMPILATION,       :DATE_ADDED,:DATE_MOD,"
+                  " :FORMAT)");
     query.bindValue(":ARTIST", artist.utf8());
     query.bindValue(":COMPILATION_ARTIST", compilation_artist.utf8());
     query.bindValue(":ALBUM", album.utf8());
@@ -214,6 +237,7 @@
     query.bindValue(":COMPILATION", compilation);
     query.bindValue(":DATE_ADDED",  QDateTime::currentDateTime());
     query.bindValue(":DATE_MOD",    QDateTime::currentDateTime());
+    query.bindValue(":FORMAT", format);
     
     query.exec();
 
@@ -376,7 +400,8 @@
                   "    rating   = :RATING,   " 
                   "    date_modified      = :DATE_MODIFIED, "
                   "    compilation        = :COMPILATION,   "
-                  "    compilation_artist = :COMPILATION_ARTIST "
+                  "    compilation_artist = :COMPILATION_ARTIST, "
+                  "    format             = :FORMAT "
                   "WHERE intid = :ID;");
     query.bindValue(":ARTIST",             artist.utf8());
     query.bindValue(":ALBUM",              album.utf8());
@@ -388,6 +413,7 @@
     query.bindValue(":DATE_MODIFIED",      QDateTime::currentDateTime());
     query.bindValue(":COMPILATION",        compilation);
     query.bindValue(":COMPILATION_ARTIST", compilation_artist.utf8());
+    query.bindValue(":FORMAT", format);
     query.bindValue(":ID", id);
 
     if (!query.exec())
@@ -538,7 +564,7 @@
         return;
 
     QString thequery = "SELECT artist,compilation_artist,album,title,genre,year,tracknum,length,"
-                       "filename,intid,rating,playcount,lastplay,compilation "
+                       "filename,intid,rating,playcount,lastplay,compilation,format "
                        "FROM musicmetadata WHERE title = :TITLE";
 
     if (album != "")
@@ -575,6 +601,7 @@
         playcount = query.value(11).toInt();
         lastplay = query.value(12).toString();
         compilation = (query.value(13).toInt() > 0);
+        format = query.value(14).toString();
 
         if (!filename.contains("://"))
             filename = m_startdir + filename;
@@ -588,7 +615,7 @@
         
     MSqlQuery query(MSqlQuery::InitCon());
     query.prepare("SELECT title,artist,compilation_artist,album,title,genre,year,tracknum,"
-                  "length,filename,rating,playcount,lastplay,compilation FROM "
+                  "length,filename,rating,playcount,lastplay,compilation,format FROM "
                   "musicmetadata WHERE intid = :ID ;");
     query.bindValue(":ID", id);
         
@@ -610,6 +637,7 @@
         playcount = query.value(11).toInt();
         lastplay = query.value(12).toString();
         compilation = (query.value(13).toInt() > 0);
+        format = query.value(14).toString();
 
         if (!filename.contains("://"))
             filename = m_startdir + filename;
@@ -758,7 +786,8 @@
     done_loading = false;
     QString aquery =    "SELECT intid, artist, compilation_artist, album, title, genre, "
                         "year, tracknum, length, filename, rating, "
-                        "lastplay, playcount, compilation FROM musicmetadata "
+                        "lastplay, playcount, compilation, format "
+                        "FROM musicmetadata "
                         "ORDER BY intid;";
 
     QString filename;
@@ -797,8 +826,9 @@
                 query.value(10).toInt(),
                 query.value(12).toInt(),
                 query.value(11).toString(),
-                (query.value(13).toInt() > 0));
-
+                (query.value(13).toInt() > 0),
+                query.value(14).toString());
+            
             //  Don't delete temp, as PtrList now owns it
             all_music.append(temp);
 
@@ -1503,7 +1533,7 @@
 int MetadataPtrList::compareItems(QPtrCollection::Item item1, 
                                   QPtrCollection::Item item2)
 {
-    return ((Metadata*)item1)->Track() - ((Metadata*)item2)->Track();
+    return ((Metadata*)item1)->compare((Metadata*)item2);
 }
 
 int MusicNodePtrList::compareItems (QPtrCollection::Item item1, 
diff --exclude='Makefile*' --exclude='*svn*' -ru ../observable/mythplugins/mythmusic/mythmusic/metadata.h mythplugins/mythmusic/mythmusic/metadata.h
--- ../observable/mythplugins/mythmusic/mythmusic/metadata.h	2005-11-23 12:40:28.000000000 -0800
+++ mythplugins/mythmusic/mythmusic/metadata.h	2005-11-30 10:28:40.333846080 -0800
@@ -19,7 +19,7 @@
              QString lalbum = "", QString ltitle = "", QString lgenre = "",
              int lyear = 0, int ltracknum = 0, int llength = 0, int lid = 0,
              int lrating = 0, int lplaycount = 0, QString llastplay = "",
-             bool lcompilation = false)
+             bool lcompilation = false, QString lformat="")
             {
                 filename = lfilename;
                 artist = lartist;
@@ -39,6 +39,7 @@
                 compilation = lcompilation;
                 changed = false;
                 show = true;
+                format = lformat;
             }
 
     Metadata(const Metadata &other) 
@@ -61,6 +62,7 @@
                 compilation = other.compilation;
                 show = other.show;
                 changed = false;
+                format = other.format;
             }
 
     Metadata& operator=(Metadata *rhs);
@@ -101,6 +103,9 @@
     QString Filename() const { return filename; }
     void setFilename(QString &lfilename) { filename = lfilename; }
     
+    QString Format() const { return format; }
+    void setFormat(const QString &lformat) { format = lformat; }
+    
     int Rating() { return rating; }
     void decRating();
     void incRating();
@@ -131,6 +136,7 @@
     void fillDataFromID();
     void persist();
     bool hasChanged(){return changed;}
+    int compare (Metadata *other);
     static void setArtistAndTrackFormats();
 
     static void SetStartdir(const QString &dir);
@@ -146,6 +152,7 @@
     QString formattedartist;
     QString formattedtitle;
     QString genre;
+    QString format;
     int year;
     int tracknum;
     int length;
