Ticket #2942: mythmusic_apic2.diff
| File mythmusic_apic2.diff, 17.4 KB (added by myth@…, 5 years ago) |
|---|
-
mythmusic/mythmusic/visualize.cpp
389 389 return false; 390 390 } 391 391 392 QString AlbumArt::getImageFilename()393 {394 return m_pParent->metadata()->getAlbumArt(m_currImageType);395 }396 397 392 bool AlbumArt::draw(QPainter *p, const QColor &back) 398 393 { 399 394 if (!m_pParent->decoder()) … … 402 397 // If the directory has changed (new album) or the size, reload 403 398 if (needsUpdate()) 404 399 { 405 QImage art( getImageFilename());400 QImage art(m_pParent->metadata()->getAlbumArt(m_currImageType)); 406 401 if (art.isNull()) 407 402 { 408 403 m_cursize = m_size; -
mythmusic/mythmusic/metadata.cpp
381 381 382 382 if (m_id < 1 && query.isActive() && 1 == query.numRowsAffected()) 383 383 m_id = query.lastInsertId().toInt(); 384 385 if (! m_albumart.empty()) 386 { 387 QValueList<struct AlbumArtImage>::iterator it; 388 for ( it = m_albumart.begin(); it != m_albumart.end(); ++it ) 389 { 390 query.prepare("INSERT INTO music_albumart ( filename, " 391 "imagetype, song_id, embedded ) VALUES ( " 392 ":FILENAME, :TYPE, :SONGID, :EMBED );"); 393 394 query.bindValue(":FILENAME", (*it).description); 395 query.bindValue(":TYPE", (*it).imageType); 396 query.bindValue(":SONGID", m_id); 397 query.bindValue(":EMBED", 1); 398 399 if (!query.exec() || !query.isActive() || query.numRowsAffected() <= 0) 400 { 401 MythContext::DBError("music insert albumart", query); 402 } 403 } 404 } 384 405 } 385 406 386 407 // Default values for formats … … 616 637 m_changed = true; 617 638 } 618 639 640 void Metadata::setEmbeddedAlbumArt(QValueList<struct AlbumArtImage> albumart) 641 { 642 m_albumart = albumart; 643 } 644 619 645 QStringList Metadata::fillFieldList(QString field) 620 646 { 621 647 QStringList searchList; … … 658 684 return searchList; 659 685 } 660 686 661 Q StringList Metadata::AlbumArtInDir(QString directory)687 QImage Metadata::getAlbumArt(ImageType type) 662 688 { 663 QStringList paths;689 AlbumArtImages albumArt(this); 664 690 665 directory.remove(0, m_startdir.length());691 QImage image; 666 692 667 MSqlQuery query(MSqlQuery::InitCon()); 668 query.prepare("SELECT CONCAT_WS('/', music_directories.path, " 669 "music_albumart.filename) FROM music_albumart " 670 "LEFT JOIN music_directories ON " 671 "music_directories.directory_id=music_albumart.directory_id " 672 "WHERE music_directories.path = :DIR;"); 673 query.bindValue(":DIR", directory.utf8()); 674 if (query.exec()) 693 if (albumArt.isImageEmbedded(type)) 675 694 { 676 while (query.next()) 677 { 678 paths += m_startdir + "/" + 679 QString::fromUtf8(query.value(0).toString()); 680 } 695 image = QImage(MetaIOTagLib::getAlbumArt(m_filename, type)); 681 696 } 682 return paths; 683 } 697 else 698 { 699 image = QImage(albumArt.getImageFilename(type)); 700 } 684 701 685 QString Metadata::getAlbumArt(ImageType type) 686 { 687 QString res = ""; 688 AlbumArtImages albumArt(this); 689 690 res = albumArt.getImageFilename(type); 691 692 return res; 702 return image; 693 703 } 694 704 695 705 MetadataLoadingThread::MetadataLoadingThread(AllMusic *parent_ptr) … … 1375 1385 /**************************************************************************/ 1376 1386 1377 1387 AlbumArtImages::AlbumArtImages(Metadata *metadata) 1388 : m_parent(metadata) 1378 1389 { 1379 m_parent = metadata;1380 1390 m_imageList.setAutoDelete(true); 1381 1391 1382 1392 findImages(); … … 1386 1396 { 1387 1397 m_imageList.clear(); 1388 1398 1399 if (m_parent == NULL) 1400 return; 1401 1402 int trackid = m_parent->ID(); 1403 1389 1404 QFileInfo fi(m_parent->Filename()); 1390 1405 QString dir = fi.dirPath(true); 1391 1406 dir.remove(0, Metadata::GetStartdir().length()); 1392 1407 1393 1408 MSqlQuery query(MSqlQuery::InitCon()); 1394 1409 query.prepare("SELECT albumart_id, CONCAT_WS('/', music_directories.path, " 1395 "music_albumart.filename), music_albumart.imagetype " 1410 "music_albumart.filename), music_albumart.imagetype, " 1411 "music_albumart.embedded " 1396 1412 "FROM music_albumart " 1397 1413 "LEFT JOIN music_directories ON " 1398 1414 "music_directories.directory_id=music_albumart.directory_id " 1399 1415 "WHERE music_directories.path = :DIR " 1416 "OR song_id = :SONGID " 1400 1417 "ORDER BY music_albumart.imagetype;"); 1401 1418 query.bindValue(":DIR", dir.utf8()); 1419 query.bindValue(":SONGID", trackid); 1402 1420 if (query.exec()) 1403 1421 { 1404 1422 while (query.next()) … … 1409 1427 QString::fromUtf8(query.value(1).toString()); 1410 1428 image->imageType = (ImageType) query.value(2).toInt(); 1411 1429 image->typeName = getTypeName(image->imageType); 1430 if (query.value(3).toInt() == 1) 1431 { 1432 image->description = query.value(1).toString(); 1433 image->embedded = true; 1434 } 1435 else { 1436 image->embedded = false; 1437 } 1412 1438 m_imageList.append(image); 1413 1439 } 1414 1440 } … … 1422 1448 for (image = m_imageList.first(); image; image = m_imageList.next()) 1423 1449 { 1424 1450 if (image->imageType == type) 1451 { 1452 if (image->embedded) 1453 return "embedded"; 1454 1425 1455 return image->filename; 1456 } 1426 1457 } 1427 1458 1428 1459 return ""; … … 1442 1473 return paths; 1443 1474 } 1444 1475 1476 AlbumArtImage AlbumArtImages::getImageAt(uint index) 1477 { 1478 return *(m_imageList.at(index)); 1479 } 1480 1481 bool AlbumArtImages::isImageEmbedded(ImageType type) 1482 { 1483 AlbumArtImage *image; 1484 1485 for (image = m_imageList.first(); image; image = m_imageList.next()) 1486 { 1487 if (image->imageType == type) 1488 return image->embedded; 1489 } 1490 1491 return false; 1492 } 1493 1445 1494 bool AlbumArtImages::isImageAvailable(ImageType type) 1446 1495 { 1447 1496 // try to find a matching image -
mythmusic/mythmusic/dbcheck.cpp
9 9 #include "mythtv/mythcontext.h" 10 10 #include "mythtv/mythdbcon.h" 11 11 12 const QString currentDatabaseVersion = "101 1";12 const QString currentDatabaseVersion = "1012"; 13 13 14 14 static bool UpdateDBVersionNumber(const QString &newnumber) 15 15 { … … 587 587 return false; 588 588 589 589 } 590 591 if (dbver == "1011") 592 { 593 const QString updates[] = { 594 "ALTER TABLE music_albumart ADD COLUMN song_id int(11) NOT NULL DEFAULT '0', ADD COLUMN embedded TINYINT(1) NOT NULL DEFAULT '0';", 595 "" 596 }; 597 598 if (!performActualUpdate(updates, "1012", dbver)) 599 return false; 600 601 } 590 602 /* in 0.21 */ 591 603 //"DROP TABLE musicmetadata;", 592 604 //"DROP TABLE musicplaylist;", -
mythmusic/mythmusic/metadata.h
4 4 #include <qstring.h> 5 5 #include <qstringlist.h> 6 6 #include <qptrlist.h> 7 #include <qvaluelist.h> 7 8 #include <qmap.h> 8 9 #include <qthread.h> 9 10 10 11 #include "treecheckitem.h" 11 12 #include <mythtv/uitypes.h> 12 13 14 13 15 class AllMusic; 14 16 class CoverArt; 15 17 … … 23 25 IT_LAST 24 26 }; 25 27 28 #include "metaiotaglib.h" 29 26 30 typedef struct AlbumArtImage 27 31 { 28 32 int id; 29 33 QString filename; 30 34 ImageType imageType; 31 35 QString typeName; 36 QString description; 37 bool embedded; 32 38 } AlbumArtImage; 33 39 40 //typedef QValueList<struct AlbumArtImage> AlbumArtList; 41 34 42 class Metadata 35 43 { 36 44 public: … … 59 67 m_lastplay(llastplay), 60 68 m_playcount(lplaycount), 61 69 m_compilation(lcompilation), 70 m_albumart(), 62 71 m_id(lid), 63 72 m_filename(lfilename), 64 73 m_changed(false), … … 159 168 } 160 169 bool determineIfCompilation(bool cd = false); 161 170 171 void setEmbeddedAlbumArt(QValueList<struct AlbumArtImage> art); 172 162 173 bool isInDatabase(void); 163 174 void dumpToDatabase(void); 164 175 void setField(const QString &field, const QString &data); … … 173 184 174 185 static QStringList fillFieldList(QString field); 175 186 176 QStringList AlbumArtInDir(QString directory); 177 QString getAlbumArt(ImageType type); 187 QImage getAlbumArt(ImageType type); 178 188 179 189 private: 180 190 void setCompilationFormatting(bool cd = false); … … 201 211 QString m_lastplay; 202 212 int m_playcount; 203 213 bool m_compilation; 214 QValueList<struct AlbumArtImage> m_albumart; 204 215 205 216 unsigned int m_id; 206 217 QString m_filename; … … 394 405 QStringList getImageFilenames(); 395 406 QPtrList<AlbumArtImage> *getImageList() { return &m_imageList; } 396 407 AlbumArtImage getImageAt(uint index); 408 bool isImageEmbedded(ImageType type); 397 409 398 410 bool isImageAvailable(ImageType type); 399 411 -
mythmusic/mythmusic/metaiotaglib.h
2 2 #define METAIOTAGLIB_H_ 3 3 4 4 #include "metaio.h" 5 #include "metadata.h" 5 6 #include <id3v2tag.h> 6 7 #include <textidentificationframe.h> 8 #include <attachedpictureframe.h> 7 9 #include <mpegfile.h> 10 #include <mpegproperties.h> 8 11 9 12 using TagLib::MPEG::File; 10 13 using TagLib::Tag; 11 14 using TagLib::ID3v2::UserTextIdentificationFrame; 15 using TagLib::ID3v2::AttachedPictureFrame; 12 16 using TagLib::String; 17 using TagLib::MPEG::Properties; 13 18 14 19 class MetaIOTagLib : public MetaIO 15 20 { … … 20 25 bool write(Metadata* mdata, bool exclusive = false); 21 26 Metadata* read(QString filename); 22 27 28 static QImage getAlbumArt(QString filename, ImageType type); 29 23 30 private: 24 31 25 int getTrackLength(QString filename);32 int getTrackLength(QString filename); 26 33 27 UserTextIdentificationFrame* find(TagLib::ID3v2::Tag *tag, const String &description); 34 QValueList<struct AlbumArtImage> readAlbumArt(TagLib::ID3v2::Tag *tag); 35 UserTextIdentificationFrame* find(TagLib::ID3v2::Tag *tag, const String &description); 28 36 }; 29 37 30 38 #endif -
mythmusic/mythmusic/metaiotaglib.cpp
102 102 genre = ""; 103 103 int year = 0, tracknum = 0, length = 0, playcount = 0, rating = 0, id = 0; 104 104 bool compilation = false; 105 QValueList<struct AlbumArtImage> albumart; 105 106 106 107 QString extension = filename.section( '.', -1 ) ; 107 108 … … 151 152 // Length 152 153 if(!taglib->ID3v2Tag()->frameListMap()["TLEN"].isEmpty()) 153 154 length = taglib->ID3v2Tag()->frameListMap()["TLEN"].front()->toString().toInt(); 155 156 // Album Art 157 if(!taglib->ID3v2Tag()->frameListMap()["APIC"].isEmpty()) 158 { 159 albumart = readAlbumArt(taglib->ID3v2Tag()); 160 } 154 161 } 155 162 156 163 // Fallback to filename reading … … 183 190 id, rating, playcount); 184 191 185 192 retdata->setCompilation(compilation); 193 retdata->setEmbeddedAlbumArt(albumart); 186 194 187 195 return retdata; 188 196 } … … 203 211 } 204 212 205 213 /*! 214 * \brief Read the albumart image from the file 215 * 216 * \param filename The filename for which we want to find the length. 217 * \param type The type of image we want - front/back etc 218 * \returns A QByteArray that can contains the image data. 219 */ 220 QImage MetaIOTagLib::getAlbumArt(QString filename, ImageType type) 221 { 222 QImage picture; 223 224 AttachedPictureFrame::Type apicType 225 = AttachedPictureFrame::FrontCover; 226 227 switch (type) 228 { 229 case IT_UNKNOWN : 230 apicType = AttachedPictureFrame::Other; 231 break; 232 case IT_FRONTCOVER : 233 apicType = AttachedPictureFrame::FrontCover; 234 break; 235 case IT_BACKCOVER : 236 apicType = AttachedPictureFrame::BackCover; 237 break; 238 case IT_CD : 239 apicType = AttachedPictureFrame::Media; 240 break; 241 case IT_INLAY : 242 apicType = AttachedPictureFrame::LeafletPage; 243 break; 244 default: 245 return picture; 246 } 247 248 File *taglib = new TagLib::MPEG::File(filename.local8Bit()); 249 250 if (taglib->isOpen() && !taglib->ID3v2Tag()->frameListMap()["APIC"].isEmpty()) 251 { 252 TagLib::ID3v2::FrameList apicframes = taglib->ID3v2Tag()->frameListMap()["APIC"]; 253 254 for(TagLib::ID3v2::FrameList::Iterator it = apicframes.begin(); it != apicframes.end(); ++it) { 255 AttachedPictureFrame *frame = static_cast<AttachedPictureFrame *>(*it); 256 if(frame && frame->type() == apicType) 257 { 258 QImage picture; 259 picture.loadFromData((const uchar *)frame->picture().data(), frame->picture().size()); 260 return picture; 261 } 262 } 263 } 264 265 return picture; 266 } 267 268 /*! 269 * \brief Read the albumart image from the file 270 * 271 * \param tag The ID3v2 tag object in which to look for Album Art 272 * \returns A QValueList containing a list of AlbumArtImage structs 273 * with the type and description of the APIC tag. 274 */ 275 QValueList<struct AlbumArtImage> MetaIOTagLib::readAlbumArt(TagLib::ID3v2::Tag *tag) 276 { 277 278 QValueList<struct AlbumArtImage> artlist; 279 280 if (!tag->frameListMap()["APIC"].isEmpty()) 281 { 282 TagLib::ID3v2::FrameList apicframes = tag->frameListMap()["APIC"]; 283 284 for(TagLib::ID3v2::FrameList::Iterator it = apicframes.begin(); 285 it != apicframes.end(); ++it) 286 { 287 288 AttachedPictureFrame *frame = 289 static_cast<AttachedPictureFrame *>(*it); 290 291 AlbumArtImage art; 292 293 if (!frame->description().isEmpty()) 294 { 295 art.description = TStringToQString(frame->description()); 296 } else 297 { 298 art.description = ""; 299 } 300 301 art.embedded = true; 302 303 switch (frame->type()) 304 { 305 case AttachedPictureFrame::FrontCover : 306 art.imageType = IT_FRONTCOVER; 307 art.typeName = "Front Cover"; 308 break; 309 case AttachedPictureFrame::BackCover : 310 art.imageType = IT_BACKCOVER; 311 art.typeName = "Back Cover"; 312 break; 313 case AttachedPictureFrame::Media : 314 art.imageType = IT_CD; 315 art.typeName = "CD"; 316 break; 317 case AttachedPictureFrame::LeafletPage : 318 art.imageType = IT_INLAY; 319 art.typeName = "Inlay"; 320 break; 321 case AttachedPictureFrame::Other : 322 art.imageType = IT_UNKNOWN; 323 art.typeName = "Other"; 324 break; 325 default: 326 VERBOSE(VB_GENERAL, "Music Scanner - APIC tag found " 327 "with unsupported type"); 328 continue; 329 } 330 331 artlist.append(art); 332 } 333 } 334 335 return artlist; 336 } 337 338 /*! 206 339 * \brief Find the a custom comment tag by description. 207 340 * This is a copy of the same function in the 208 341 * TagLib::ID3v2::UserTextIdentificationFrame Class with a static -
mythmusic/mythmusic/mainvisual.cpp
350 351 return; 351 352 352 353 QString text = "\"" + mdata->Title() + "\"\n" + mdata->Artist() + "\n" + mdata->Album(); 353 Q StringalbumArt = mdata->getAlbumArt(IT_FRONTCOVER);354 QImage albumArt = mdata->getAlbumArt(IT_FRONTCOVER); 354 355 355 356 if (text == info) 356 357 return; … … 370 371 } 371 372 372 373 // ...and only then when we have an album art image to show 373 if (visMode != 2 && fullScreen && albumArt == "")374 if (visMode != 2 && fullScreen && ! albumArt.isNull()) 374 375 { 375 376 hide(); 376 377 return; 377 378 } 378 379 379 if (fullScreen && albumArt != "")380 if (fullScreen && ! albumArt.isNull()) 380 381 { 381 382 resize(parentWidget()->width(), parentWidget()->height()); 382 383 move(0, 0); … … 400 401 int x = indent; 401 402 int y = indent; 402 403 403 if (fullScreen && albumArt != "")404 if (fullScreen && ! albumArt.isNull()) 404 405 { 405 406 p.fillRect(0, 0, info_pixmap.width(), info_pixmap.height(), QColor ("black")); 406 407 … … 419 420 { 420 421 p.fillRect(0, 0, info_pixmap.width(), info_pixmap.height(), QColor ("darkblue")); 421 422 422 if ( albumArt != "")423 if (! albumArt.isNull()) 423 424 { 424 425 // draw the albumArt image 425 426 -
mythmusic/mythmusic/visualize.h
91 91 92 92 private: 93 93 bool needsUpdate(void); 94 QString getImageFilename(void);95 94 void findFrontCover(void); 96 95 97 96 QSize m_size, m_cursize;
