Permalink
Browse files

Myth Protocol: add a MUSIC_TAG_UPDATE_VOLATILE command

This command will be used to update the rating, last played time and play
count in a music tracks tag.

format:-
MUSIC_TAG_UPDATE_VOLATILE <hostname> <songid> <rating> <playcount> <lastplayed>
  • Loading branch information...
1 parent f20b9ca commit 2f1a5350be38597ddbac337dc10cf7932fadc0c2 Paul Harrison committed Feb 8, 2014
Showing with 72 additions and 1 deletion.
  1. +71 −1 mythtv/programs/mythbackend/mainserver.cpp
  2. +1 −0 mythtv/programs/mythbackend/mainserver.h
@@ -797,7 +797,14 @@ void MainServer::ProcessRequestWork(MythSocket *sock)
{
HandleScanMusic(tokens, pbs);
}
- else if (command == "MUSIC_TAG_GETIMAGE")
+ else if (command == "MUSIC_TAG_UPDATE_VOLATILE")
+ {
+ if (tokens.size() < 6)
+ LOG(VB_GENERAL, LOG_ERR, "Bad MUSIC_TAG_UPDATE_VOLATILE");
+ else
+ HandleMusicTagUpdateVolatile(tokens, pbs);
+ }
+ else if (command == "MUSIC_TAG_GETIMAGE")
{
if (tokens.size() < 4)
LOG(VB_GENERAL, LOG_ERR, "Bad MUSIC_TAG_GETIMAGE");
@@ -5228,6 +5235,69 @@ void MainServer::HandleScanMusic(const QStringList &slist, PlaybackSock *pbs)
SendResponse(pbssock, strlist);
}
+void MainServer::HandleMusicTagUpdateVolatile(const QStringList &slist, PlaybackSock *pbs)
+{
+// format: MUSIC_TAG_UPDATE_VOLATILE <hostname> <songid> <rating> <playcount> <lastplayed>
+
+ 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, QString("HandleMusicTagUpdateVolatile: asking slave '%1' to update the metadata").arg(hostname));
+ strlist << slist.join(" ");
+ strlist = slave->ForwardRequest(strlist);
+ slave->DecrRef();
+
+ if (pbssock)
+ SendResponse(pbssock, strlist);
+
+ return;
+ }
+ else
+ {
+ LOG(VB_GENERAL, LOG_INFO,
+ QString("HandleMusicTagUpdateVolatile: Failed to grab slave socket on '%1'").arg(hostname));
+
+ strlist << "ERROR: slave not found";
+
+ if (pbssock)
+ SendResponse(pbssock, strlist);
+
+ return;
+ }
+ }
+ else
+ {
+ // run mythutil to update the metadata
+ QStringList paramList;
+ paramList.append(QString("--songid='%1'").arg(slist[2]));
+ paramList.append(QString("--rating='%1'").arg(slist[3]));
+ paramList.append(QString("--playcount='%1'").arg(slist[4]));
+ paramList.append(QString("--lastplayed='%1'").arg(slist[5]));
+
+ QString command = "mythutil --updatemeta " + paramList.join(" ");
+
+ LOG(VB_GENERAL, LOG_INFO, QString("HandleMusicTagUpdateVolatile: running %1'").arg(command));
+ QScopedPointer<MythSystem> cmd(MythSystem::Create(command,
+ kMSAutoCleanup | kMSRunBackground |
+ kMSDontDisableDrawing | kMSProcessEvents |
+ kMSDontBlockInputDevs));
+ }
+
+ strlist << "OK";
+
+ if (pbssock)
+ SendResponse(pbssock, strlist);
+}
+
void MainServer::HandleMusicTagGetImage(const QStringList &slist, PlaybackSock *pbs)
{
// format: MUSIC_TAG_GETIMAGE <hostname> <songid> <imagetype>
@@ -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 HandleMusicTagUpdateVolatile(const QStringList &slist, PlaybackSock *pbs);
void HandleMusicTagGetImage(const QStringList &slist, PlaybackSock *pbs);
void HandleVersion(MythSocket *socket, const QStringList &slist);
void HandleBackendRefresh(MythSocket *socket);

0 comments on commit 2f1a535

Please sign in to comment.