Skip to content

Commit 96bf5c6

Browse files
author
Paul Harrison
committed
MythMusic: update the metadata editor adding/removing images from the tag
This re-enables adding and removing embedded images from a tracks tag using the albumart editor screen which now works with storage groups.
1 parent 8c17413 commit 96bf5c6

File tree

2 files changed

+86
-43
lines changed

2 files changed

+86
-43
lines changed

mythplugins/mythmusic/mythmusic/editmetadata.cpp

Lines changed: 85 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,14 +1074,11 @@ void EditAlbumartDialog::showMenu(void )
10741074

10751075
menu->AddButton(tr("Search Internet For Images"));
10761076

1077-
// FIXME this needs updating to work with storage groups
1078-
#if 0
1079-
1080-
MetaIO *tagger = m_metadata->getTagger();
1077+
MetaIO *tagger = MetaIO::createTagger(m_metadata->Filename(false));
10811078

10821079
if (m_coverartList->GetItemCurrent())
10831080
{
1084-
menu->AddButton(tr("Change Image Type"), NULL, true);
1081+
//menu->AddButton(tr("Change Image Type"), NULL, true);
10851082

10861083
if (GetMythDB()->GetNumSetting("AllowTagWriting", 0))
10871084
{
@@ -1114,7 +1111,7 @@ void EditAlbumartDialog::showMenu(void )
11141111

11151112
if (tagger)
11161113
delete tagger;
1117-
#endif
1114+
11181115
popupStack->AddScreen(menu);
11191116
}
11201117

@@ -1255,6 +1252,22 @@ void EditAlbumartDialog::customEvent(QEvent *event)
12551252
{
12561253
if (tokens[0] == "BROWSER_DOWNLOAD_FINISHED")
12571254
rescanForImages();
1255+
else if (tokens[0] == "MUSIC_METADATA_CHANGED")
1256+
{
1257+
if (tokens.size() >= 2)
1258+
{
1259+
int songID = tokens[1].toInt();
1260+
1261+
if (m_metadata->ID() == songID)
1262+
{
1263+
// force all the image to reload
1264+
for (int x = 0; x < m_metadata->getAlbumArtImages()->getImageCount(); x++)
1265+
removeCachedImage(m_metadata->getAlbumArtImages()->getImageAt(x));
1266+
1267+
updateImageGrid();
1268+
}
1269+
}
1270+
}
12581271
}
12591272
}
12601273
}
@@ -1339,65 +1352,95 @@ void EditAlbumartDialog::doRemoveImageFromTag(bool doIt)
13391352
AlbumArtImage *image = qVariantValue<AlbumArtImage*> (item->GetData());
13401353
if (image)
13411354
{
1342-
MetaIO *tagger = m_metadata->getTagger();
1355+
// ask the backend to remove the image from the tracks tag
1356+
QStringList strList("MUSIC_TAG_REMOVEIMAGE");
1357+
strList << m_metadata->Hostname()
1358+
<< QString::number(m_metadata->ID())
1359+
<< QString::number(image->id);
13431360

1344-
if (tagger && !tagger->supportsEmbeddedImages())
1345-
{
1346-
LOG(VB_GENERAL, LOG_ERR, "EditAlbumartDialog: asked to remove an image from the tag "
1347-
"but the tagger doesn't support it!");
1348-
delete tagger;
1349-
return;
1350-
}
1351-
1352-
if (!tagger->removeAlbumArt(m_metadata->Filename(), image))
1353-
LOG(VB_GENERAL, LOG_ERR, "EditAlbumartDialog: failed to remove album art from tag");
1354-
else
1355-
LOG(VB_GENERAL, LOG_INFO, "EditAlbumartDialog: album art removed from tag");
1361+
gCoreContext->SendReceiveStringList(strList);
13561362

13571363
removeCachedImage(image);
13581364
rescanForImages();
1359-
1360-
if (tagger)
1361-
delete tagger;
13621365
}
13631366
}
13641367
}
13651368

1366-
void EditAlbumartDialog::doCopyImageToTag(const AlbumArtImage *image)
1369+
class CopyImageThread: public MThread
13671370
{
1368-
MetaIO *tagger = m_metadata->getTagger();
1371+
public:
1372+
CopyImageThread(QStringList strList) :
1373+
MThread("CopyImage"), m_strList(strList) {}
13691374

1370-
if (tagger && !tagger->supportsEmbeddedImages())
1375+
virtual void run()
13711376
{
1372-
LOG(VB_GENERAL, LOG_ERR, "EditAlbumartDialog: asked to write album art to the tag "
1373-
"but the tagger does't support it!");
1374-
delete tagger;
1375-
return;
1377+
RunProlog();
1378+
gCoreContext->SendReceiveStringList(m_strList);
1379+
RunEpilog();
13761380
}
13771381

1378-
if (!tagger->writeAlbumArt(m_metadata->Filename(), image))
1379-
LOG(VB_GENERAL, LOG_ERR, "EditAlbumartDialog: failed to write album art to tag");
1382+
QStringList getResult(void) { return m_strList; }
1383+
1384+
private:
1385+
QStringList m_strList;
1386+
};
1387+
1388+
void EditAlbumartDialog::doCopyImageToTag(const AlbumArtImage *image)
1389+
{
1390+
MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
1391+
MythUIBusyDialog *busy = new MythUIBusyDialog(tr("Copying image to tag..."),
1392+
popupStack, "copyimagebusydialog");
1393+
1394+
if (busy->Create())
1395+
{
1396+
popupStack->AddScreen(busy, false);
1397+
}
13801398
else
1381-
LOG(VB_GENERAL, LOG_INFO, "EditAlbumartDialog: album art written to tag");
1399+
{
1400+
delete busy;
1401+
busy = NULL;
1402+
}
1403+
1404+
// copy the image to the tracks host
1405+
QFileInfo fi(image->filename);
1406+
QString saveFilename = gCoreContext->GenMythURL(m_metadata->Hostname(), 0,
1407+
QString("AlbumArt/") + fi.fileName(),
1408+
"MusicArt");
1409+
1410+
RemoteFile::CopyFile(image->filename, saveFilename);
1411+
1412+
// ask the backend to add the image to the tracks tag
1413+
QStringList strList("MUSIC_TAG_ADDIMAGE");
1414+
strList << m_metadata->Hostname()
1415+
<< QString::number(m_metadata->ID())
1416+
<< fi.fileName()
1417+
<< QString::number(image->imageType);
1418+
1419+
CopyImageThread *copyThread = new CopyImageThread(strList);
1420+
copyThread->start();
1421+
1422+
while (copyThread->isRunning())
1423+
{
1424+
qApp->processEvents();
1425+
usleep(1000);
1426+
}
1427+
1428+
strList = copyThread->getResult();
1429+
1430+
delete copyThread;
1431+
1432+
if (busy)
1433+
busy->Close();
13821434

13831435
removeCachedImage(image);
13841436

13851437
rescanForImages();
1386-
1387-
if (tagger)
1388-
delete tagger;
13891438
}
13901439

13911440
void EditAlbumartDialog::removeCachedImage(const AlbumArtImage *image)
13921441
{
13931442
if (!image->embedded)
13941443
return;
13951444

1396-
QString imageFilename = QString(GetConfDir() + "/MythMusic/AlbumArt/%1-%2.jpg")
1397-
.arg(m_metadata->ID()).arg(AlbumArtImages::getTypeFilename(image->imageType));
1398-
1399-
if (QFile::exists(imageFilename))
1400-
QFile::remove(imageFilename);
1401-
1402-
GetMythUI()->RemoveFromCacheByFile(imageFilename);
1445+
GetMythUI()->RemoveFromCacheByFile(image->filename);
14031446
}

mythtv/libs/libmythmetadata/musicmetadata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ void AlbumArtImages::scanForImages()
17851785
busy = NULL;
17861786
}
17871787

1788-
QStringList strList(QString("MUSIC_FIND_ALBUMART %1 %2 0")
1788+
QStringList strList(QString("MUSIC_FIND_ALBUMART %1 %2 1")
17891789
.arg(m_parent->Hostname())
17901790
.arg(m_parent->ID()));
17911791

0 commit comments

Comments
 (0)