Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

myth protocol: add a MUSIC_TAG_ADDIMAGE command

This command will be used by the music metadata editor to add an image to a
tracks tag.

format: MUSIC_TAG_ADDIMAGE <hostname> <songid> <filename> <imagetype>
  • Loading branch information...
commit e350c8fb09d59535143e47243e6713119dee7d68 1 parent a75cd55
Paul Harrison authored
View
166 mythtv/programs/mythbackend/mainserver.cpp
@@ -838,6 +838,13 @@ void MainServer::ProcessRequestWork(MythSocket *sock)
else
HandleMusicTagGetImage(tokens, pbs);
}
+ else if (command == "MUSIC_TAG_ADDIMAGE")
+ {
+ if (listline.size() < 5)
+ LOG(VB_GENERAL, LOG_ERR, LOC + "Bad MUSIC_TAG_ADDIMAGE");
+ else
+ HandleMusicTagAddImage(listline, pbs);
+ }
else if (command == "ALLOW_SHUTDOWN")
{
if (tokens.size() != 1)
@@ -5724,6 +5731,165 @@ void MainServer::HandleMusicTagGetImage(const QStringList &slist, PlaybackSock *
SendResponse(pbssock, strlist);
}
+void MainServer::HandleMusicTagAddImage(const QStringList& slist, PlaybackSock* pbs)
+{
+// format: MUSIC_TAG_ADDIMAGE <hostname> <songid> <filename> <imagetype>
+
+ QStringList strlist;
+
+ MythSocket *pbssock = pbs->getSocket();
+
+ QString hostname = slist[1];
+
+ if (ismaster && hostname != gCoreContext->GetHostName())
+ {
+ // forward the request to the slave BE
+ PlaybackSock *slave = GetMediaServerByHostname(hostname);
+ if (slave)
+ {
+ LOG(VB_GENERAL, LOG_INFO, LOC +
+ QString("HandleMusicTagAddImage: asking slave '%1' "
+ "to add the image").arg(hostname));
+ strlist = slave->ForwardRequest(slist);
+ slave->DecrRef();
+
+ if (pbssock)
+ SendResponse(pbssock, strlist);
+
+ return;
+ }
+ else
+ {
+ LOG(VB_GENERAL, LOG_INFO, LOC +
+ QString("HandleMusicTagAddImage: Failed to grab "
+ "slave socket on '%1'").arg(hostname));
+
+ strlist << "ERROR: slave not found";
+
+ if (pbssock)
+ SendResponse(pbssock, strlist);
+
+ return;
+ }
+ }
+ else
+ {
+ // load the metadata from the database
+ int songID = slist[2].toInt();
+ QString filename = slist[3];
+ ImageType imageType = (ImageType) slist[4].toInt();
+
+ MusicMetadata *mdata = MusicMetadata::createFromID(songID);
+
+ if (!mdata)
+ {
+ LOG(VB_GENERAL, LOG_ERR, LOC +
+ QString("HandleMusicTagAddImage: Cannot find metadata for trackid: %1")
+ .arg(songID));
+
+ strlist << "ERROR: track not found";
+
+ if (pbssock)
+ SendResponse(pbssock, strlist);
+
+ return;
+ }
+
+ MetaIO *tagger = mdata->getTagger();
+
+ if (!tagger)
+ {
+ LOG(VB_GENERAL, LOG_ERR, LOC +
+ "HandleMusicTagAddImage: failed to find a tagger for track");
+
+ strlist << "ERROR: tagger not found";
+
+ if (pbssock)
+ SendResponse(pbssock, strlist);
+
+ delete mdata;
+ return;
+ }
+
+ if (!tagger->supportsEmbeddedImages())
+ {
+ LOG(VB_GENERAL, LOG_ERR, LOC +
+ "HandleMusicTagAddImage: asked to write album art to the tag "
+ "but the tagger doesn't support it!");
+
+ strlist << "ERROR: embedded images not supported by tag";
+
+ if (pbssock)
+ SendResponse(pbssock, strlist);
+
+ delete tagger;
+ delete mdata;
+ return;
+ }
+
+ // is the image in the 'MusicArt' storage group
+ bool isDirectoryImage = false;
+ StorageGroup storageGroup("MusicArt", gCoreContext->GetHostName(), false);
+ QString imageFilename = storageGroup.FindFile("AlbumArt/" + filename);
+ if (imageFilename.isEmpty())
+ {
+ // not found there so look in the tracks directory
+ QFileInfo fi(mdata->getLocalFilename());
+ imageFilename = fi.absolutePath() + '/' + filename;
+ isDirectoryImage = true;
+ }
+
+ if (!QFile::exists(imageFilename))
+ {
+ LOG(VB_GENERAL, LOG_ERR, LOC +
+ QString("HandleMusicTagAddImage: cannot find image file %1").arg(filename));
+
+ strlist << "ERROR: failed to find image file";
+
+ if (pbssock)
+ SendResponse(pbssock, strlist);
+
+ delete tagger;
+ delete mdata;
+ return;
+ }
+
+ AlbumArtImage image;
+ image.filename = imageFilename;
+ image.imageType = imageType;
+
+ if (!tagger->writeAlbumArt(mdata->getLocalFilename(), &image))
+ {
+ LOG(VB_GENERAL, LOG_ERR, LOC + "HandleMusicTagAddImage: failed to write album art to tag");
+
+ strlist << "ERROR: failed to write album art to tag";
+
+ if (pbssock)
+ SendResponse(pbssock, strlist);
+
+ if (!isDirectoryImage)
+ QFile::remove(imageFilename);
+
+ delete tagger;
+ delete mdata;
+ return;
+ }
+
+ // only remove the image if we temporarily saved one to the 'AlbumArt' storage group
+ if (!isDirectoryImage)
+ QFile::remove(imageFilename);
+
+ delete tagger;
+ delete mdata;
+ }
+
+
+ strlist << "OK";
+
+ if (pbssock)
+ SendResponse(pbssock, strlist);
+}
+
void MainServer::HandleFileTransferQuery(QStringList &slist,
QStringList &commands,
PlaybackSock *pbs)
View
1  mythtv/programs/mythbackend/mainserver.h
@@ -221,6 +221,7 @@ class MainServer : public QObject, public MythSocketCBs
void HandleMusicTagUpdateMetadata(const QStringList &slist, PlaybackSock *pbs);
void HandleMusicFindAlbumArt(const QStringList &slist, PlaybackSock *pbs);
void HandleMusicTagGetImage(const QStringList &slist, PlaybackSock *pbs);
+ void HandleMusicTagAddImage(const QStringList &slist, PlaybackSock *pbs);
void HandleMusicCalcTrackLen(const QStringList &slist, PlaybackSock *pbs);
void HandleVersion(MythSocket *socket, const QStringList &slist);
void HandleBackendRefresh(MythSocket *socket);
Please sign in to comment.
Something went wrong with that request. Please try again.