Permalink
Browse files

MainServer: add a MUSIC_TAG_GETIMAGE command to the myth protocol

This command will run mythutil on the appropriate host to extract an embedded
image in the tag of a music file and save the image in the 'AlbumArt' storage
group.
  • Loading branch information...
Paul Harrison
Paul Harrison committed Jan 30, 2014
1 parent 97ae3f5 commit e6c8a78685e6e1f12b533b81ff6b729adfdca174
Showing with 73 additions and 0 deletions.
  1. +72 −0 mythtv/programs/mythbackend/mainserver.cpp
  2. +1 −0 mythtv/programs/mythbackend/mainserver.h
@@ -796,6 +796,13 @@ void MainServer::ProcessRequestWork(MythSocket *sock)
else if (command == "SCAN_MUSIC")
{
HandleScanMusic(tokens, pbs);
+ }
+ else if (command == "MUSIC_TAG_GETIMAGE")
+ {
+ if (tokens.size() < 4)
+ LOG(VB_GENERAL, LOG_ERR, "Bad MUSIC_TAG_GETIMAGE");
+ else
+ HandleMusicTagGetImage(tokens, pbs);
}
else if (command == "ALLOW_SHUTDOWN")
{
@@ -5221,6 +5228,71 @@ void MainServer::HandleScanMusic(const QStringList &slist, PlaybackSock *pbs)
SendResponse(pbssock, strlist);
}
+void MainServer::HandleMusicTagGetImage(const QStringList &slist, PlaybackSock *pbs)
+{
+// format: MUSIC_TAG_GETIMAGE <hostname> <songid> <imagetype>
+
+ QStringList strlist;
+
+ MythSocket *pbssock = pbs->getSocket();
+
+ QString hostname = slist[1];
+ QString songid = slist[2];
+ QString imagetype = slist[3];
+
+ QStringList paramList;
+ paramList.append(QString("--songid='%1'").arg(songid));
+ paramList.append(QString("--imagetype='%1'").arg(imagetype));
+
+ QString command = "mythutil --extractimage " + paramList.join(" ");
+
+ if (ismaster)
+ {
+
+ if (hostname == gCoreContext->GetHostName())
+ {
+ // this is the master BE
+ LOG(VB_GENERAL, LOG_INFO, QString("HandleMusicTagGetImage: running %1 on master BE '%2'").arg(command).arg(hostname));
+
+ QScopedPointer<MythSystem> cmd(MythSystem::Create(command,
+ kMSAutoCleanup | kMSRunBackground |
+ kMSDontDisableDrawing | kMSProcessEvents |
+ kMSDontBlockInputDevs));
+ }
+ else
+ {
+ // forward the request to the slave BE
+ PlaybackSock *slave = GetMediaServerByHostname(hostname);
+ if (slave)
+ {
+ LOG(VB_GENERAL, LOG_INFO, QString("HandleMusicTagGetImage: asking slave '%1' to extract the image").arg(hostname));
+ strlist << slist.join(" ");
+ slave->ForwardRequest(strlist);
+ slave->DecrRef();
+ }
+ else
+ {
+ LOG(VB_GENERAL, LOG_INFO,
+ QString("HandleMusicTagGetImage: Failed to grab slave socket on '%1'").arg(hostname));
+ }
+ }
+ }
+ else
+ {
+ // must be a slave run mythutil to extract the image
+ LOG(VB_GENERAL, LOG_INFO, QString("HandleMusicTagGetImage: running %1 on slave BE '%2'").arg(command).arg(gCoreContext->GetHostName()));
+ QScopedPointer<MythSystem> cmd(MythSystem::Create(command,
+ kMSAutoCleanup | kMSRunBackground |
+ kMSDontDisableDrawing | kMSProcessEvents |
+ kMSDontBlockInputDevs));
+ }
+
+ strlist << "OK";
+
+ if (pbssock)
+ SendResponse(pbssock, strlist);
+}
+
void MainServer::HandleFileTransferQuery(QStringList &slist,
QStringList &commands,
PlaybackSock *pbs)
@@ -217,6 +217,7 @@ class MainServer : public QObject, public MythSocketCBs
void HandleSetSetting(QStringList &tokens, PlaybackSock *pbs);
void HandleScanVideos(PlaybackSock *pbs);
void HandleScanMusic(const QStringList &slist, PlaybackSock *pbs);
+ void HandleMusicTagGetImage(const QStringList &slist, PlaybackSock *pbs);
void HandleVersion(MythSocket *socket, const QStringList &slist);
void HandleBackendRefresh(MythSocket *socket);
void HandleQueryLoad(PlaybackSock *pbs);

0 comments on commit e6c8a78

Please sign in to comment.