[mythtv] mythmusic w/o id3 and setting to limit how often rereads dir

Benjamin Binford mythtv-dev@snowman.net
Tue, 10 Dec 2002 11:01:45 -0500


--PNTmBPCT7hxwcZjr
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Mon, Dec 09, 2002 at 07:00:51PM -0500, Isaac Richards wrote:
> On Monday 09 December 2002 06:16 pm, Isaac Richards wrote:
> > Hmmm.  Might be simpler to just do:
> >
> >  select filename from musicmetadata;
> >
> > store that in a map<qstring, bool> like you've got the file list, then
> > compare the music list against that.
> >
> > Reason being, that would make possible to cull entries out of the database
> > that are no longer present on the filesystem at the same time it's looking
> > for new files..
> 
> Ok, did that, checked something similar into CVS -- anyone want to let me know 
> if it helps them at all with the startup speed of mythmusic?

I did the same thing last night- you beat me to the list by about ten minutes. Attached is a merge of my patch and yours, since I included scavenging of database records that no longer exist in the filesystem.


> 
> Isaac
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev@snowman.net
> http://www.snowman.net/mailman/listinfo/mythtv-dev

-- 
Marge, this ticket doesn't just give me a seat.  It also gives me the 
right -- no, the duty -- to make a complete ass of myself.

		-- Homer Simpson
		   Dancin' Homer

--PNTmBPCT7hxwcZjr
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="startupspeed2.patch"

Index: main.cpp
===================================================================
RCS file: /var/lib/cvs/mythmusic/mythmusic/main.cpp,v
retrieving revision 1.15
diff -u -r1.15 main.cpp
--- main.cpp	9 Dec 2002 23:59:20 -0000	1.15
+++ main.cpp	10 Dec 2002 15:52:48 -0000
@@ -1,6 +1,7 @@
 #include <qdir.h>
 #include <iostream>
 #include <map>
+#include <qregexp.h>
 using namespace std;
 
 #include <qapplication.h>
@@ -73,7 +74,14 @@
     }
 }
 
-typedef map<QString, bool> MusicLoadedMap;
+enum MusicFileLocation
+  {
+    FILESYSTEM_ONLY,
+    DATABASE_ONLY,
+    BOTH
+  };
+
+typedef map<QString, MusicFileLocation> MusicLoadedMap;
 
 void BuildFileList(MythContext *context, QString &directory,
                    MusicLoadedMap &music_files)
@@ -99,7 +107,7 @@
         if (fi->isDir())
             BuildFileList(context, filename, music_files);
         else
-            music_files[filename] = false;
+            music_files[filename] = FILESYSTEM_ONLY;
     }
 }
 
@@ -121,22 +129,33 @@
             QString name = query.value(0).toString();
             if (name != QString::null)
             {
-                db_files[name] = false;
                 if ((iter = music_files.find(name)) != music_files.end())
                 {
-                    (*iter).second = true;
+                    (*iter).second = BOTH;
                 }
+		else
+		{
+  		    music_files[name] = DATABASE_ONLY;
+		}
             }
         }
     }
-
+    
+    QRegExp quote_regex("\"");
     for (iter = music_files.begin(); iter != music_files.end(); iter++)
     {
-        if ((*iter).second == false)
+        if ((*iter).second == FILESYSTEM_ONLY)
         {
             CheckFile(context, (*iter).first);
         }
+	else if ((*iter).second == DATABASE_ONLY)
+	{
+	    QString name((*iter).first);
+	    name.replace(quote_regex, "\"\""); // mysql escapes " inside string with ""
+	    query.exec(QString("DELETE FROM musicmetadata WHERE filename=\"%1\"").arg(name));
+	}
     }
+
 }
 
 void startPlayback(MythContext *context, QSqlDatabase *db, 

--PNTmBPCT7hxwcZjr--