[mythtv] [PATCH] mythmusic: one path fits all is ugly
Stefan Frank
sfr+lists at 6913304088794.gnuu.de
Fri Dec 19 06:27:21 EST 2003
Hi,
this patch removes the current requirement of several frontends having
to have the same musiclocation defined in order to share a music
collection between them.
It also modifies mythmusic to allow for url-like filename fields like
shoutcast://my.favourite.webradio.
This will eventually be needed to store urls of your favourite webradio
stations.
The code is tested (upgrade, initial install) and works well for me.
Season's greetings to all of you
Stefan
--
"But Huey, you PROMISED!"
"Tell 'em I lied."
-------------- next part --------------
diff -urN ./mythmusic/mythmusic/main.cpp mythmusic-local/mythmusic/main.cpp
--- ./mythmusic/mythmusic/main.cpp 2003-12-14 04:57:14.000000000 +0100
+++ mythmusic-local/mythmusic/main.cpp 2003-12-18 17:23:44.000000000 +0100
@@ -179,8 +179,8 @@
BuildFileList(directory, music_files);
- QSqlQuery query("SELECT filename FROM musicmetadata;",
- QSqlDatabase::database());
+ QSqlQuery query("SELECT filename FROM musicmetadata WHERE filename NOT LIKE ('%://%');",
+ QSqlDatabase::database());
int counter = 0;
@@ -192,7 +192,7 @@
{
while (query.next())
{
- QString name = query.value(0).toString();
+ QString name = directory + query.value(0).toString();
if (name != QString::null)
{
if ((iter = music_files.find(name)) != music_files.end())
@@ -220,6 +220,7 @@
else if (*iter == kDatabase)
{
QString name(iter.key());
+ name.remove(0, directory.length());
name.replace(quote_regex, "\"\"");
QString querystr = QString("DELETE FROM musicmetadata WHERE "
@@ -433,6 +434,8 @@
// Load all available info about songs (once!)
QString startdir = gContext->GetSetting("MusicLocation");
+ if (!startdir.endsWith("/"));
+ startdir += "/";
// Only search music files if a directory was specified & there
// is no data in the database yet (first run). Otherwise, user
diff -urN ./mythmusic/mythmusic/metadata.cpp mythmusic-local/mythmusic/metadata.cpp
--- ./mythmusic/mythmusic/metadata.cpp 2003-09-10 02:21:45.000000000 +0200
+++ mythmusic-local/mythmusic/metadata.cpp 2003-12-18 17:29:15.000000000 +0100
@@ -73,7 +73,12 @@
{
bool retval = false;
+ QString startdir = gContext->GetSetting("MusicLocation");
+ if (!startdir.endsWith("/"))
+ startdir += "/";
+
QString sqlfilename = filename;
+ sqlfilename = filename.remove(0, startdir.length());
sqlfilename.replace(QRegExp("\""), QString("\\\""));
QString thequery = QString("SELECT artist,album,title,genre,year,tracknum,"
@@ -107,6 +112,10 @@
void Metadata::dumpToDatabase(QSqlDatabase *db)
{
+ QString startdir = gContext->GetSetting("MusicLocation");
+ if (!startdir.endsWith("/"))
+ startdir += "/";
+
if (artist == "")
artist = QObject::tr("Unknown Artist");
if (album == "")
@@ -122,6 +131,7 @@
genre.replace(QRegExp("\""), QString("\\\""));
QString sqlfilename = filename;
+ sqlfilename = filename.remove(0, startdir.length());
sqlfilename.replace(QRegExp("\""), QString("\\\""));
QString thequery = QString("INSERT INTO musicmetadata (artist,album,title,"
@@ -422,6 +432,11 @@
"lastplay, playcount FROM musicmetadata "
"ORDER BY intid ";
+ QString filename;
+ QString startdir = gContext->GetSetting("MusicLocation");
+ if (!startdir.endsWith("/"))
+ startdir += "/";
+
QSqlQuery query = db->exec(aquery);
all_music.clear();
@@ -430,9 +445,13 @@
{
while(query.next())
{
+ filename = query.value(8).toString();
+ if (!filename.contains("://"))
+ filename = startdir + filename;
+
Metadata *temp = new Metadata
(
- query.value(8).toString(),
+ filename,
query.value(1).toString(),
query.value(2).toString(),
query.value(3).toString(),
--- ./mythmusic/mythmusic/dbcheck.cpp 2003-12-18 15:35:48.000000000 +0100
+++ mythmusic-local/mythmusic/dbcheck.cpp 2003-12-18 17:42:11.000000000 +0100
@@ -8,7 +8,7 @@
#include "mythtv/mythcontext.h"
-const QString currentDatabaseVersion = "1000";
+const QString currentDatabaseVersion = "1001";
static void UpdateDBVersionNumber(const QString &newnumber)
{
@@ -82,5 +82,49 @@
};
performActualUpdate(updates, "1000", dbver);
}
+
+ if (dbver == "1000")
+ {
+ QString startdir = gContext->GetSetting("MusicLocation");
+ if (!startdir.endsWith("/"))
+ startdir += "/";
+
+ QSqlDatabase *db_conn = QSqlDatabase::database();
+ // urls as filenames are NOT officially supported yet
+ QSqlQuery query("SELECT filename, intid FROM musicmetadata WHERE "
+ "filename NOT LIKE ('%://%');", db_conn);
+ QSqlQuery modify;
+
+ if (query.isActive() && query.numRowsAffected() > 0)
+ {
+ int i = 0;
+ QString intid, name, newname;
+
+ while (query.next())
+ {
+ name = query.value(0).toString();
+ newname = name;
+ intid = query.value(1).toString();
+
+ if (newname.startsWith(startdir))
+ {
+ newname.remove(0, startdir.length());
+ modify.exec(QString("UPDATE musicmetadata SET "
+ "filename = \"%1\" "
+ "WHERE filename = \"%2\" AND intid = %3;")
+ .arg(newname, name, intid));
+ if (modify.isActive())
+ i += modify.numRowsAffected();
+ }
+ }
+ VERBOSE(VB_ALL, QString("Modified %1 entries for db schema 1001").arg(i));
+ }
+
+ const QString updates[] = {
+""
+};
+ performActualUpdate(updates, "1001", dbver);
+ }
+
}
More information about the mythtv-dev
mailing list