Ticket #341: dbupdate.patch
File dbupdate.patch, 16.2 KB (added by , 19 years ago) |
---|
-
mythplugins/mythmusic/mythmusic/aacdecoder.cpp
614 614 deinit(); 615 615 } 616 616 617 Metadata* aacDecoder:: getMetadata()617 Metadata* aacDecoder::readMetadata() 618 618 { 619 620 Metadata *mdata = new Metadata(filename); 621 if (mdata->isInDatabase(musiclocation)) 622 { 623 return mdata; 624 } 625 626 delete mdata; 627 619 Metadata *mdata = NULL; 628 620 MetaIOMP4* p_tagger = new MetaIOMP4; 629 621 if (ignore_id3) { 630 622 mdata = p_tagger->readFromFilename(filename); … … 634 626 635 627 delete p_tagger; 636 628 637 if (mdata) 638 mdata->dumpToDatabase(musiclocation); 639 else 629 if (!mdata) 640 630 error(QString("aacdecoder.o: Could not read metadata from \"%1\"").arg(filename.local8Bit())); 641 631 642 632 return mdata; -
mythplugins/mythmusic/mythmusic/decoder.h
79 79 static Decoder *create(const QString &, QIODevice *, AudioOutput *, 80 80 bool = FALSE); 81 81 82 virtual Metadata *getMetadata() = 0; 82 virtual Metadata *readMetadata() = 0; 83 virtual Metadata *getMetadata(); 83 84 virtual void commitMetadata(Metadata *mdata) = 0; 84 85 85 86 static void SetLocationFormatUseTags(void); -
mythplugins/mythmusic/mythmusic/metadata.cpp
148 148 playcount = query.value(10).toInt(); 149 149 lastplay = query.value(11).toString(); 150 150 compilation = (query.value(12).toInt() > 0); 151 151 152 152 retval = true; 153 153 } 154 154 … … 194 194 return; 195 195 196 196 query.prepare("INSERT INTO musicmetadata (artist,compilation_artist,album,title," 197 "genre,year,tracknum,length,filename,compilation,date_added) VALUES " 197 "genre,year,tracknum,length,filename,compilation,date_added," 198 "date_modified) VALUES " 198 199 "(:ARTIST, :COMPILATION_ARTIST, :ALBUM, :TITLE, :GENRE, :YEAR, :TRACKNUM, " 199 ":LENGTH, :FILENAME, :COMPILATION, :DATE_ADDED );");200 ":LENGTH, :FILENAME, :COMPILATION, :DATE_ADDED, :DATE_MODIFIED );"); 200 201 query.bindValue(":ARTIST", artist.utf8()); 201 202 query.bindValue(":COMPILATION_ARTIST", compilation_artist.utf8()); 202 203 query.bindValue(":ALBUM", album.utf8()); … … 207 208 query.bindValue(":LENGTH", length); 208 209 query.bindValue(":FILENAME", sqlfilename.utf8()); 209 210 query.bindValue(":COMPILATION", compilation); 210 query.bindValue(":DATE_ADDED", QDate::currentDate()); 211 query.bindValue(":DATE_ADDED", QDateTime::currentDateTime()); 212 query.bindValue(":DATE_MODIFIED", QDateTime::currentDateTime()); 211 213 212 214 query.exec(); 213 215 … … 364 366 "compilation_artist = :COMPILATION_ARTIST, " 365 367 "title = :TITLE, genre = :GENRE, year = :YEAR, " 366 368 "tracknum = :TRACKNUM, rating = :RATING, " 367 "compilation = :COMPILATION " 369 "compilation = :COMPILATION, " 370 "date_modified= :DATE_MODIFIED " 368 371 "WHERE intid = :ID;"); 369 372 query.bindValue(":ARTIST", artist.utf8()); 370 373 query.bindValue(":COMPILATION_ARTIST", compilation_artist.utf8()); … … 375 378 query.bindValue(":TRACKNUM", tracknum); 376 379 query.bindValue(":RATING", rating); 377 380 query.bindValue(":COMPILATION", compilation); 381 query.bindValue(":DATE_MODIFIED", QDateTime::currentDateTime()); 378 382 query.bindValue(":ID", id); 379 383 380 384 if (!query.exec()) … … 1193 1197 if( *it != "genre" && 1194 1198 *it != "artist" && 1195 1199 *it != "splitartist" && 1200 *it != "splitartist1" && 1196 1201 *it != "album" && 1197 1202 *it != "title") 1198 1203 { -
mythplugins/mythmusic/mythmusic/cddecoder.h
25 25 int getNumTracks(void); 26 26 int getNumCDAudioTracks(void); 27 27 28 Metadata *readMetadata(); 28 29 Metadata *getMetadata(int track); 29 30 Metadata *getMetadata(); 30 31 Metadata *getLastMetadata(); -
mythplugins/mythmusic/mythmusic/decoder.cpp
6 6 7 7 #include "decoder.h" 8 8 #include "constants.h" 9 #include "metadata.h" 9 10 #include <mythtv/output.h> 10 11 #include <mythtv/visual.h> 11 12 … … 87 88 listeners.remove(object); 88 89 } 89 90 91 Metadata* Decoder::getMetadata() 92 { 90 93 94 Metadata *mdata = new Metadata(filename); 95 if (mdata->isInDatabase(musiclocation)) 96 { 97 return mdata; 98 } 99 100 delete mdata; 101 102 return readMetadata (); 103 } 104 91 105 // static methods 92 106 93 107 int Decoder::ignore_id3 = 0; -
mythplugins/mythmusic/mythmusic/aacdecoder.h
29 29 void seek(double); 30 30 void stop(); 31 31 32 Metadata * getMetadata();32 Metadata *readMetadata(); 33 33 void commitMetadata(Metadata *mdata); 34 34 35 35 bool initializeMP4(); -
mythplugins/mythmusic/mythmusic/vorbisdecoder.cpp
293 293 deinit(); 294 294 } 295 295 296 Metadata *VorbisDecoder:: getMetadata()296 Metadata *VorbisDecoder::readMetadata() 297 297 { 298 Metadata *mdata = new Metadata(filename); 299 if (mdata->isInDatabase(musiclocation)) 300 { 301 return mdata; 302 } 303 304 delete mdata; 305 306 298 Metadata *mdata = NULL; 307 299 MetaIOOggVorbisComment* p_tagger = new MetaIOOggVorbisComment; 308 300 if (ignore_id3) 309 301 mdata = p_tagger->readFromFilename(filename); … … 312 304 313 305 delete p_tagger; 314 306 315 if (mdata) 316 mdata->dumpToDatabase(musiclocation); 317 else 307 if (!mdata) 318 308 cerr << "vorbisdecoder.o: Could not read metadata from " << filename.local8Bit() << endl; 319 309 320 310 return mdata; -
mythplugins/mythmusic/mythmusic/flacdecoder.h
22 22 void doWrite(const FLAC__Frame *frame, const FLAC__int32 * const buffer[]); 23 23 void setFlacMetadata(const FLAC__StreamMetadata *metadata); 24 24 25 Metadata * getMetadata();25 Metadata *readMetadata(); 26 26 void commitMetadata(Metadata *mdata); 27 27 28 28 private: -
mythplugins/mythmusic/mythmusic/avfdecoder.cpp
357 357 deinit(); 358 358 } 359 359 360 Metadata* avfDecoder:: getMetadata()360 Metadata* avfDecoder::readMetadata() 361 361 { 362 Metadata *mdata = new Metadata(filename); 363 if (mdata->isInDatabase(musiclocation)) 364 { 365 return mdata; 366 } 367 368 delete mdata; 369 370 362 Metadata *mdata = NULL; 371 363 MetaIOAVFComment* p_tagger = new MetaIOAVFComment; 372 364 if (ignore_id3) 373 365 mdata = p_tagger->readFromFilename(filename); … … 376 368 377 369 delete p_tagger; 378 370 379 if (mdata) 380 mdata->dumpToDatabase(musiclocation); 381 else 371 if (!mdata) 382 372 cerr << "avfdecoder.o: Could not read metadata from " << filename << endl; 383 373 384 374 return mdata; -
mythplugins/mythmusic/mythmusic/main.cpp
6 6 #include <qapplication.h> 7 7 #include <qsqldatabase.h> 8 8 #include <qregexp.h> 9 #include <sys/types.h> 10 #include <sys/stat.h> 9 11 #include <unistd.h> 10 12 11 13 #include <cdaudio.h> … … 65 67 return decoder; 66 68 } 67 69 68 void CheckFile(const QString &filename) 70 // Add a file to the database 71 void CheckFile(const QString &directory, const QString &filename) 69 72 { 70 73 Decoder *decoder = getDecoder(filename); 71 74 72 75 if (decoder) 73 76 { 74 77 Metadata *data = decoder->getMetadata(); 75 if (data) 78 if (data) 79 { 80 data->dumpToDatabase(directory); 76 81 delete data; 82 } 83 delete decoder; 84 } 85 } 77 86 87 // Remove a file from the database 88 void RemoveFile (const QString &directory, const QString &filename) 89 { 90 QString name(filename); 91 name.remove(0, directory.length()); 92 MSqlQuery query(MSqlQuery::InitCon()); 93 query.prepare("DELETE FROM musicmetadata WHERE " 94 "filename = :NAME ;"); 95 query.bindValue(":NAME", name.utf8()); 96 query.exec(); 97 } 98 99 // Update a file's metadata in the database, preserving it's id 100 void UpdateFile (const QString &directory, const QString &filename) 101 { 102 Decoder *decoder = getDecoder (filename); 103 104 if (decoder) 105 { 106 Metadata *dbmeta = decoder->getMetadata (); 107 Metadata *fmeta = decoder->readMetadata (); 108 109 if (dbmeta && fmeta) 110 { 111 fmeta->setID (dbmeta->ID ()); 112 fmeta->updateDatabase (directory); 113 } 114 115 if (fmeta) 116 delete fmeta; 117 118 if (dbmeta) 119 delete dbmeta; 120 78 121 delete decoder; 79 122 } 80 123 } … … 83 126 { 84 127 kFileSystem, 85 128 kDatabase, 86 k Both129 kNeedUpdate, 87 130 }; 88 131 89 132 typedef QMap <QString, MusicFileLocation> MusicLoadedMap; … … 115 158 } 116 159 } 117 160 161 /* Check if the file's mdate is after the date_modified */ 162 bool HasFileChanged (const QString &filename, const QString &date_modified) 163 { 164 struct stat sbuf; 165 if (stat (filename.ascii (), &sbuf) == 0) { 166 if (sbuf.st_mtime > (time_t)QDateTime::fromString (date_modified, Qt::ISODate).toTime_t ()) { 167 return true; 168 } 169 } 170 return false; 171 } 172 118 173 void SavePending(int pending) 119 174 { 120 175 // Temporary Hack until mythmusic … … 180 235 BuildFileList(directory, music_files); 181 236 182 237 MSqlQuery query(MSqlQuery::InitCon()); 183 query.exec("SELECT filename FROM musicmetadata "238 query.exec("SELECT filename, date_modified FROM musicmetadata " 184 239 "WHERE filename NOT LIKE ('%://%');"); 185 240 186 241 int counter = 0; … … 196 251 QString name = directory + QString::fromUtf8(query.value(0).toString()); 197 252 if (name != QString::null) 198 253 { 199 if ((iter = music_files.find(name)) != music_files.end()) 200 music_files.remove(iter); 201 else 254 if ((iter = music_files.find(name)) != music_files.end()) { 255 if (HasFileChanged (name, query.value (1).toString ())) { 256 music_files[name] = kNeedUpdate; 257 } else { 258 music_files.remove(iter); 259 } 260 } else { 202 261 music_files[name] = kDatabase; 262 } 203 263 } 204 264 file_checking->setProgress(++counter); 205 265 } … … 214 274 QRegExp quote_regex("\""); 215 275 for (iter = music_files.begin(); iter != music_files.end(); iter++) 216 276 { 217 if (*iter == kFileSystem) 218 { 219 CheckFile(iter.key()); 277 switch (*iter) { 278 case kFileSystem: 279 CheckFile(directory, iter.key()); 280 break; 281 case kDatabase: 282 RemoveFile (directory, iter.key()); 283 break; 284 case kNeedUpdate: 285 UpdateFile (directory, iter.key ()); 286 break; 220 287 } 221 else if (*iter == kDatabase)222 {223 QString name(iter.key());224 name.remove(0, directory.length());225 226 query.prepare("DELETE FROM musicmetadata WHERE "227 "filename = :NAME ;");228 query.bindValue(":NAME", name.utf8());229 query.exec();230 }231 232 288 file_checking->setProgress(++counter); 233 289 } 234 290 file_checking->Close(); -
mythplugins/mythmusic/mythmusic/flacdecoder.cpp
385 385 char *field_value; 386 386 } Argument_VcField; 387 387 388 Metadata *FlacDecoder:: getMetadata()388 Metadata *FlacDecoder::readMetadata() 389 389 { 390 Metadata *mdata = new Metadata(filename); 391 if (mdata->isInDatabase(musiclocation)) 392 { 393 return mdata; 394 } 395 396 delete mdata; 397 390 Metadata *mdata = NULL; 398 391 MetaIOFLACVorbisComment* p_tagger = new MetaIOFLACVorbisComment; 399 392 if (ignore_id3) 400 393 mdata = p_tagger->readFromFilename(filename); … … 403 396 404 397 delete p_tagger; 405 398 406 if (mdata) 407 mdata->dumpToDatabase(musiclocation); 408 else 399 if (!mdata) 409 400 cerr << "flacdecoder.o: Could not read metadata from " << filename.local8Bit() << endl; 410 401 411 402 return mdata; -
mythplugins/mythmusic/mythmusic/maddecoder.h
24 24 static const int maxFrameCheck; 25 25 static const int initialFrameSize; 26 26 27 Metadata * getMetadata();27 Metadata *readMetadata(); 28 28 void commitMetadata(Metadata *mdata); 29 29 30 30 private: -
mythplugins/mythmusic/mythmusic/vorbisdecoder.h
18 18 void seek(double); 19 19 void stop(); 20 20 21 Metadata * getMetadata();21 Metadata *readMetadata(); 22 22 void commitMetadata(Metadata *mdata); 23 23 24 24 private: -
mythplugins/mythmusic/mythmusic/avfdecoder.h
18 18 void seek(double); 19 19 void stop(); 20 20 21 Metadata * getMetadata();21 Metadata *readMetadata(); 22 22 void commitMetadata(Metadata *mdata); 23 23 24 24 private: -
mythplugins/mythmusic/mythmusic/cddecoder.cpp
331 331 return NULL; 332 332 } 333 333 334 Metadata *CdDecoder::readMetadata() 335 { 336 return NULL; 337 } 338 334 339 Metadata *CdDecoder::getMetadata() 335 340 { 336 341 -
mythplugins/mythmusic/mythmusic/maddecoder.cpp
512 512 return MAD_FLOW_STOP; 513 513 } 514 514 515 Metadata *MadDecoder:: getMetadata()515 Metadata *MadDecoder::readMetadata() 516 516 { 517 Metadata *mdata = new Metadata(filename); 518 if (mdata->isInDatabase(musiclocation)) 519 { 520 return mdata; 521 } 522 523 delete mdata; 524 525 517 Metadata *mdata = NULL; 526 518 MetaIOID3v2* p_tagger = new MetaIOID3v2; 527 519 if (ignore_id3) 528 520 mdata = p_tagger->readFromFilename(filename); … … 531 523 532 524 delete p_tagger; 533 525 534 if (mdata) 535 mdata->dumpToDatabase(musiclocation); 536 else 526 if (!mdata) 537 527 cerr << "maddecoder.o: Could not read metadata from " << filename.local8Bit() << endl; 538 528 539 529 return mdata;