Skip to content
Permalink
Browse files

myth protocol: add a MUSIC_TAG_REMOVEIMAGE command

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

format: MUSIC_TAG_REMOVEIMAGE <hostname> <songid> <imageid>
  • Loading branch information...
Paul Harrison
Paul Harrison committed Mar 9, 2014
1 parent e350c8f commit b9d40e4075aea4706736d4edec2761225ad76b46
Showing with 138 additions and 0 deletions.
  1. +137 −0 mythtv/programs/mythbackend/mainserver.cpp
  2. +1 −0 mythtv/programs/mythbackend/mainserver.h
@@ -845,6 +845,13 @@ void MainServer::ProcessRequestWork(MythSocket *sock)
else
HandleMusicTagAddImage(listline, pbs);
}
else if (command == "MUSIC_TAG_REMOVEIMAGE")
{
if (tokens.size() < 4)
LOG(VB_GENERAL, LOG_ERR, LOC + "Bad MUSIC_TAG_REMOVEIMAGE");
else
HandleMusicTagRemoveImage(listline, pbs);
}
else if (command == "ALLOW_SHUTDOWN")
{
if (tokens.size() != 1)
@@ -5890,6 +5897,136 @@ void MainServer::HandleMusicTagAddImage(const QStringList& slist, PlaybackSock*
SendResponse(pbssock, strlist);
}

void MainServer::HandleMusicTagRemoveImage(const QStringList& slist, PlaybackSock* pbs)
{
// format: MUSIC_TAG_REMOVEIMAGE <hostname> <songid> <imageid>

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("HandleMusicTagRemoveImage: asking slave '%1' "
"to remove the image").arg(hostname));
strlist = slave->ForwardRequest(slist);
slave->DecrRef();

if (pbssock)
SendResponse(pbssock, strlist);

return;
}
else
{
LOG(VB_GENERAL, LOG_INFO, LOC +
QString("HandleMusicTagRemoveImage: Failed to grab "
"slave socket on '%1'").arg(hostname));

strlist << "ERROR: slave not found";

if (pbssock)
SendResponse(pbssock, strlist);

return;
}
}
else
{
int songID = slist[2].toInt();
int imageID = slist[3].toInt();

// load the metadata from the database
MusicMetadata *mdata = MusicMetadata::createFromID(songID);

if (!mdata)
{
LOG(VB_GENERAL, LOG_ERR, LOC +
QString("HandleMusicTagRemoveImage: 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 +
"HandleMusicTagRemoveImage: 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 + "HandleMusicTagRemoveImage: asked to remove album art "
"from the tag but the tagger doesn't support it!");

strlist << "ERROR: embedded images not supported by tag";

if (pbssock)
SendResponse(pbssock, strlist);

delete mdata;
delete tagger;
return;
}

AlbumArtImage *image = mdata->getAlbumArtImages()->getImageByID(imageID);
if (!image)
{
LOG(VB_GENERAL, LOG_ERR, LOC +
QString("HandleMusicTagRemoveImage: Cannot find image for imageid: %1")
.arg(imageID));

strlist << "ERROR: image not found";

if (pbssock)
SendResponse(pbssock, strlist);

delete mdata;
delete tagger;
return;
}

if (!tagger->removeAlbumArt(mdata->getLocalFilename(), image))
{
LOG(VB_GENERAL, LOG_ERR, LOC + "HandleMusicTagRemoveImage: failed to remove album art from tag");

strlist << "ERROR: failed to remove album art from tag";

if (pbssock)
SendResponse(pbssock, strlist);

return;
}
}

strlist << "OK";

if (pbssock)
SendResponse(pbssock, strlist);
}

void MainServer::HandleFileTransferQuery(QStringList &slist,
QStringList &commands,
PlaybackSock *pbs)
@@ -222,6 +222,7 @@ class MainServer : public QObject, public MythSocketCBs
void HandleMusicFindAlbumArt(const QStringList &slist, PlaybackSock *pbs);
void HandleMusicTagGetImage(const QStringList &slist, PlaybackSock *pbs);
void HandleMusicTagAddImage(const QStringList &slist, PlaybackSock *pbs);
void HandleMusicTagRemoveImage(const QStringList &slist, PlaybackSock *pbs);
void HandleMusicCalcTrackLen(const QStringList &slist, PlaybackSock *pbs);
void HandleVersion(MythSocket *socket, const QStringList &slist);
void HandleBackendRefresh(MythSocket *socket);

0 comments on commit b9d40e4

Please sign in to comment.
You can’t perform that action at this time.