Skip to content

Commit

Permalink
MainServer: add a MUSIC_TAG_GETIMAGE command to the myth protocol
Browse files Browse the repository at this point in the history
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 committed Jan 30, 2014
1 parent 97ae3f5 commit e6c8a78
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
72 changes: 72 additions & 0 deletions mythtv/programs/mythbackend/mainserver.cpp
Expand Up @@ -796,6 +796,13 @@ void MainServer::ProcessRequestWork(MythSocket *sock)
else if (command == "SCAN_MUSIC") else if (command == "SCAN_MUSIC")
{ {
HandleScanMusic(tokens, pbs); 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") else if (command == "ALLOW_SHUTDOWN")
{ {
Expand Down Expand Up @@ -5221,6 +5228,71 @@ void MainServer::HandleScanMusic(const QStringList &slist, PlaybackSock *pbs)
SendResponse(pbssock, strlist); 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, void MainServer::HandleFileTransferQuery(QStringList &slist,
QStringList &commands, QStringList &commands,
PlaybackSock *pbs) PlaybackSock *pbs)
Expand Down
1 change: 1 addition & 0 deletions mythtv/programs/mythbackend/mainserver.h
Expand Up @@ -217,6 +217,7 @@ class MainServer : public QObject, public MythSocketCBs
void HandleSetSetting(QStringList &tokens, PlaybackSock *pbs); void HandleSetSetting(QStringList &tokens, PlaybackSock *pbs);
void HandleScanVideos(PlaybackSock *pbs); void HandleScanVideos(PlaybackSock *pbs);
void HandleScanMusic(const QStringList &slist, PlaybackSock *pbs); void HandleScanMusic(const QStringList &slist, PlaybackSock *pbs);
void HandleMusicTagGetImage(const QStringList &slist, PlaybackSock *pbs);
void HandleVersion(MythSocket *socket, const QStringList &slist); void HandleVersion(MythSocket *socket, const QStringList &slist);
void HandleBackendRefresh(MythSocket *socket); void HandleBackendRefresh(MythSocket *socket);
void HandleQueryLoad(PlaybackSock *pbs); void HandleQueryLoad(PlaybackSock *pbs);
Expand Down

0 comments on commit e6c8a78

Please sign in to comment.