On Thu, 2005-09-15 at 09:46 -0400, Alan Kligman wrote:
> I'd like to make this modification, but I've just started looking over the
> source. Would someone let me know which files to touch?
The ones that the attached patch modifies.
(also filed ticket#341 and attached the patch).
eskil
---
Index: mythplugins/mythmusic/mythmusic/aacdecoder.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/aacdecoder.cpp (revision 7255)
+++ mythplugins/mythmusic/mythmusic/aacdecoder.cpp (working copy)
@@ -614,17 +614,9 @@
deinit();
}
-Metadata* aacDecoder::getMetadata()
+Metadata* aacDecoder::readMetadata()
{
-
- Metadata *mdata = new Metadata(filename);
- if (mdata->isInDatabase(musiclocation))
- {
- return mdata;
- }
-
- delete mdata;
-
+ Metadata *mdata = NULL;
MetaIOMP4* p_tagger = new MetaIOMP4;
if (ignore_id3) {
mdata = p_tagger->readFromFilename(filename);
@@ -634,9 +626,7 @@
delete p_tagger;
- if (mdata)
- mdata->dumpToDatabase(musiclocation);
- else
+ if (!mdata)
error(QString("aacdecoder.o: Could not read metadata from \"%1\"").arg(filename.local8Bit()));
return mdata;
Index: mythplugins/mythmusic/mythmusic/decoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/decoder.h (revision 7255)
+++ mythplugins/mythmusic/mythmusic/decoder.h (working copy)
@@ -79,7 +79,8 @@
static Decoder *create(const QString &, QIODevice *, AudioOutput *,
bool = FALSE);
- virtual Metadata *getMetadata() = 0;
+ virtual Metadata *readMetadata() = 0;
+ virtual Metadata *getMetadata();
virtual void commitMetadata(Metadata *mdata) = 0;
static void SetLocationFormatUseTags(void);
Index: mythplugins/mythmusic/mythmusic/metadata.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/metadata.cpp (revision 7255)
+++ mythplugins/mythmusic/mythmusic/metadata.cpp (working copy)
@@ -148,7 +148,7 @@
playcount = query.value(10).toInt();
lastplay = query.value(11).toString();
compilation = (query.value(12).toInt() > 0);
-
+
retval = true;
}
@@ -194,9 +194,10 @@
return;
query.prepare("INSERT INTO musicmetadata (artist,compilation_artist,album,title,"
- "genre,year,tracknum,length,filename,compilation,date_added) VALUES "
+ "genre,year,tracknum,length,filename,compilation,date_added,"
+ "date_modified) VALUES "
"(:ARTIST, :COMPILATION_ARTIST, :ALBUM, :TITLE, :GENRE, :YEAR, :TRACKNUM, "
- ":LENGTH, :FILENAME, :COMPILATION, :DATE_ADDED );");
+ ":LENGTH, :FILENAME, :COMPILATION, :DATE_ADDED, :DATE_MODIFIED );");
query.bindValue(":ARTIST", artist.utf8());
query.bindValue(":COMPILATION_ARTIST", compilation_artist.utf8());
query.bindValue(":ALBUM", album.utf8());
@@ -207,7 +208,8 @@
query.bindValue(":LENGTH", length);
query.bindValue(":FILENAME", sqlfilename.utf8());
query.bindValue(":COMPILATION", compilation);
- query.bindValue(":DATE_ADDED", QDate::currentDate());
+ query.bindValue(":DATE_ADDED", QDateTime::currentDateTime());
+ query.bindValue(":DATE_MODIFIED", QDateTime::currentDateTime());
query.exec();
@@ -364,7 +366,8 @@
"compilation_artist = :COMPILATION_ARTIST, "
"title = :TITLE, genre = :GENRE, year = :YEAR, "
"tracknum = :TRACKNUM, rating = :RATING, "
- "compilation = :COMPILATION "
+ "compilation = :COMPILATION, "
+ "date_modified= :DATE_MODIFIED "
"WHERE intid = :ID;");
query.bindValue(":ARTIST", artist.utf8());
query.bindValue(":COMPILATION_ARTIST", compilation_artist.utf8());
@@ -375,6 +378,7 @@
query.bindValue(":TRACKNUM", tracknum);
query.bindValue(":RATING", rating);
query.bindValue(":COMPILATION", compilation);
+ query.bindValue(":DATE_MODIFIED", QDateTime::currentDateTime());
query.bindValue(":ID", id);
if (!query.exec())
@@ -1193,6 +1197,7 @@
if( *it != "genre" &&
*it != "artist" &&
*it != "splitartist" &&
+ *it != "splitartist1" &&
*it != "album" &&
*it != "title")
{
Index: mythplugins/mythmusic/mythmusic/cddecoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/cddecoder.h (revision 7255)
+++ mythplugins/mythmusic/mythmusic/cddecoder.h (working copy)
@@ -25,6 +25,7 @@
int getNumTracks(void);
int getNumCDAudioTracks(void);
+ Metadata *readMetadata();
Metadata *getMetadata(int track);
Metadata *getMetadata();
Metadata *getLastMetadata();
Index: mythplugins/mythmusic/mythmusic/decoder.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/decoder.cpp (revision 7255)
+++ mythplugins/mythmusic/mythmusic/decoder.cpp (working copy)
@@ -6,6 +6,7 @@
#include "decoder.h"
#include "constants.h"
+#include "metadata.h"
#include <mythtv/output.h>
#include <mythtv/visual.h>
@@ -87,7 +88,20 @@
listeners.remove(object);
}
+Metadata* Decoder::getMetadata()
+{
+ Metadata *mdata = new Metadata(filename);
+ if (mdata->isInDatabase(musiclocation))
+ {
+ return mdata;
+ }
+
+ delete mdata;
+
+ return readMetadata ();
+}
+
// static methods
int Decoder::ignore_id3 = 0;
Index: mythplugins/mythmusic/mythmusic/aacdecoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/aacdecoder.h (revision 7255)
+++ mythplugins/mythmusic/mythmusic/aacdecoder.h (working copy)
@@ -29,7 +29,7 @@
void seek(double);
void stop();
- Metadata *getMetadata();
+ Metadata *readMetadata();
void commitMetadata(Metadata *mdata);
bool initializeMP4();
Index: mythplugins/mythmusic/mythmusic/vorbisdecoder.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/vorbisdecoder.cpp (revision 7255)
+++ mythplugins/mythmusic/mythmusic/vorbisdecoder.cpp (working copy)
@@ -293,17 +293,9 @@
deinit();
}
-Metadata *VorbisDecoder::getMetadata()
+Metadata *VorbisDecoder::readMetadata()
{
- Metadata *mdata = new Metadata(filename);
- if (mdata->isInDatabase(musiclocation))
- {
- return mdata;
- }
-
- delete mdata;
-
-
+ Metadata *mdata = NULL;
MetaIOOggVorbisComment* p_tagger = new MetaIOOggVorbisComment;
if (ignore_id3)
mdata = p_tagger->readFromFilename(filename);
@@ -312,9 +304,7 @@
delete p_tagger;
- if (mdata)
- mdata->dumpToDatabase(musiclocation);
- else
+ if (!mdata)
cerr << "vorbisdecoder.o: Could not read metadata from " << filename.local8Bit() << endl;
return mdata;
Index: mythplugins/mythmusic/mythmusic/flacdecoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/flacdecoder.h (revision 7255)
+++ mythplugins/mythmusic/mythmusic/flacdecoder.h (working copy)
@@ -22,7 +22,7 @@
void doWrite(const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
void setFlacMetadata(const FLAC__StreamMetadata *metadata);
- Metadata *getMetadata();
+ Metadata *readMetadata();
void commitMetadata(Metadata *mdata);
private:
Index: mythplugins/mythmusic/mythmusic/avfdecoder.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/avfdecoder.cpp (revision 7255)
+++ mythplugins/mythmusic/mythmusic/avfdecoder.cpp (working copy)
@@ -357,17 +357,9 @@
deinit();
}
-Metadata* avfDecoder::getMetadata()
+Metadata* avfDecoder::readMetadata()
{
- Metadata *mdata = new Metadata(filename);
- if (mdata->isInDatabase(musiclocation))
- {
- return mdata;
- }
-
- delete mdata;
-
-
+ Metadata *mdata = NULL;
MetaIOAVFComment* p_tagger = new MetaIOAVFComment;
if (ignore_id3)
mdata = p_tagger->readFromFilename(filename);
@@ -376,9 +368,7 @@
delete p_tagger;
- if (mdata)
- mdata->dumpToDatabase(musiclocation);
- else
+ if (!mdata)
cerr << "avfdecoder.o: Could not read metadata from " << filename << endl;
return mdata;
Index: mythplugins/mythmusic/mythmusic/main.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/main.cpp (revision 7255)
+++ mythplugins/mythmusic/mythmusic/main.cpp (working copy)
@@ -6,6 +6,8 @@
#include <qapplication.h>
#include <qsqldatabase.h>
#include <qregexp.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <cdaudio.h>
@@ -65,16 +67,57 @@
return decoder;
}
-void CheckFile(const QString &filename)
+// Add a file to the database
+void CheckFile(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 RemoveFile (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();
+}
+
+// Update a file's metadata in the database, preserving it's id
+void UpdateFile (const QString &directory, const QString &filename)
+{
+ Decoder *decoder = getDecoder (filename);
+
+ if (decoder)
+ {
+ Metadata *dbmeta = decoder->getMetadata ();
+ Metadata *fmeta = decoder->readMetadata ();
+
+ if (dbmeta && fmeta)
+ {
+ fmeta->setID (dbmeta->ID ());
+ fmeta->updateDatabase (directory);
+ }
+
+ if (fmeta)
+ delete fmeta;
+
+ if (dbmeta)
+ delete dbmeta;
+
delete decoder;
}
}
@@ -83,7 +126,7 @@
{
kFileSystem,
kDatabase,
- kBoth
+ kNeedUpdate,
};
typedef QMap <QString, MusicFileLocation> MusicLoadedMap;
@@ -115,6 +158,18 @@
}
}
+/* Check if the file's mdate is after the date_modified */
+bool HasFileChanged (const QString &filename, const QString &date_modified)
+{
+ struct stat sbuf;
+ if (stat (filename.ascii (), &sbuf) == 0) {
+ if (sbuf.st_mtime > (time_t)QDateTime::fromString (date_modified, Qt::ISODate).toTime_t ()) {
+ return true;
+ }
+ }
+ return false;
+}
+
void SavePending(int pending)
{
// Temporary Hack until mythmusic
@@ -180,7 +235,7 @@
BuildFileList(directory, music_files);
MSqlQuery query(MSqlQuery::InitCon());
- query.exec("SELECT filename FROM musicmetadata "
+ query.exec("SELECT filename, date_modified FROM musicmetadata "
"WHERE filename NOT LIKE ('%://%');");
int counter = 0;
@@ -196,10 +251,15 @@
QString name = directory + QString::fromUtf8(query.value(0).toString());
if (name != QString::null)
{
- if ((iter = music_files.find(name)) != music_files.end())
- music_files.remove(iter);
- else
+ if ((iter = music_files.find(name)) != music_files.end()) {
+ if (HasFileChanged (name, query.value (1).toString ())) {
+ music_files[name] = kNeedUpdate;
+ } else {
+ music_files.remove(iter);
+ }
+ } else {
music_files[name] = kDatabase;
+ }
}
file_checking->setProgress(++counter);
}
@@ -214,21 +274,17 @@
QRegExp quote_regex("\"");
for (iter = music_files.begin(); iter != music_files.end(); iter++)
{
- if (*iter == kFileSystem)
- {
- CheckFile(iter.key());
+ switch (*iter) {
+ case kFileSystem:
+ CheckFile(directory, iter.key());
+ break;
+ case kDatabase:
+ RemoveFile (directory, iter.key());
+ break;
+ case kNeedUpdate:
+ UpdateFile (directory, iter.key ());
+ break;
}
- else if (*iter == kDatabase)
- {
- QString name(iter.key());
- name.remove(0, directory.length());
-
- 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 7255)
+++ mythplugins/mythmusic/mythmusic/flacdecoder.cpp (working copy)
@@ -385,16 +385,9 @@
char *field_value;
} Argument_VcField;
-Metadata *FlacDecoder::getMetadata()
+Metadata *FlacDecoder::readMetadata()
{
- Metadata *mdata = new Metadata(filename);
- if (mdata->isInDatabase(musiclocation))
- {
- return mdata;
- }
-
- delete mdata;
-
+ Metadata *mdata = NULL;
MetaIOFLACVorbisComment* p_tagger = new MetaIOFLACVorbisComment;
if (ignore_id3)
mdata = p_tagger->readFromFilename(filename);
@@ -403,9 +396,7 @@
delete p_tagger;
- if (mdata)
- mdata->dumpToDatabase(musiclocation);
- else
+ if (!mdata)
cerr << "flacdecoder.o: Could not read metadata from " << filename.local8Bit() << endl;
return mdata;
Index: mythplugins/mythmusic/mythmusic/maddecoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/maddecoder.h (revision 7255)
+++ mythplugins/mythmusic/mythmusic/maddecoder.h (working copy)
@@ -24,7 +24,7 @@
static const int maxFrameCheck;
static const int initialFrameSize;
- Metadata *getMetadata();
+ Metadata *readMetadata();
void commitMetadata(Metadata *mdata);
private:
Index: mythplugins/mythmusic/mythmusic/vorbisdecoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/vorbisdecoder.h (revision 7255)
+++ mythplugins/mythmusic/mythmusic/vorbisdecoder.h (working copy)
@@ -18,7 +18,7 @@
void seek(double);
void stop();
- Metadata *getMetadata();
+ Metadata *readMetadata();
void commitMetadata(Metadata *mdata);
private:
Index: mythplugins/mythmusic/mythmusic/avfdecoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/avfdecoder.h (revision 7255)
+++ mythplugins/mythmusic/mythmusic/avfdecoder.h (working copy)
@@ -18,7 +18,7 @@
void seek(double);
void stop();
- Metadata *getMetadata();
+ Metadata *readMetadata();
void commitMetadata(Metadata *mdata);
private:
Index: mythplugins/mythmusic/mythmusic/cddecoder.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/cddecoder.cpp (revision 7255)
+++ mythplugins/mythmusic/mythmusic/cddecoder.cpp (working copy)
@@ -331,6 +331,11 @@
return NULL;
}
+Metadata *CdDecoder::readMetadata()
+{
+ return NULL;
+}
+
Metadata *CdDecoder::getMetadata()
{
Index: mythplugins/mythmusic/mythmusic/maddecoder.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/maddecoder.cpp (revision 7255)
+++ mythplugins/mythmusic/mythmusic/maddecoder.cpp (working copy)
@@ -512,17 +512,9 @@
return MAD_FLOW_STOP;
}
-Metadata *MadDecoder::getMetadata()
+Metadata *MadDecoder::readMetadata()
{
- Metadata *mdata = new Metadata(filename);
- if (mdata->isInDatabase(musiclocation))
- {
- return mdata;
- }
-
- delete mdata;
-
-
+ Metadata *mdata = NULL;
MetaIOID3v2* p_tagger = new MetaIOID3v2;
if (ignore_id3)
mdata = p_tagger->readFromFilename(filename);
@@ -531,9 +523,7 @@
delete p_tagger;
- if (mdata)
- mdata->dumpToDatabase(musiclocation);
- else
+ if (!mdata)
cerr << "maddecoder.o: Could not read metadata from " << filename.local8Bit() << endl;
return mdata;
_______________________________________________
mythtv-dev mailing list
[email protected]
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev