Skip to content
Browse files

Myth Protocol: add a MUSIC_CALC_TRACK_LENGTH command

This command will run mythutil to decode a music track to determin it's exact
length and will then update the database and send a MUSIC_METADATA_CHANGED
event if it changed.

format: MUSIC_CALC_TRACK_LENGTH <hostname> <songid>
  • Loading branch information...
1 parent 98c3f59 commit b257f3c8608856a2aafdf9bd02a4976d3816f8e1 Paul Harrison committed Feb 18, 2014
Showing with 68 additions and 0 deletions.
  1. +67 −0 mythtv/programs/mythbackend/mainserver.cpp
  2. +1 −0 mythtv/programs/mythbackend/mainserver.h
View
67 mythtv/programs/mythbackend/mainserver.cpp
@@ -806,6 +806,13 @@ void MainServer::ProcessRequestWork(MythSocket *sock)
else
HandleMusicTagUpdateVolatile(tokens, pbs);
}
+ else if (command == "MUSIC_CALC_TRACK_LENGTH")
+ {
+ if (tokens.size() != 3)
+ LOG(VB_GENERAL, LOG_ERR, "Bad MUSIC_CALC_TRACK_LENGTH");
+ else
+ HandleMusicCalcTrackLen(tokens, pbs);
+ }
else if (command == "MUSIC_TAG_UPDATE_METADATA")
{
if (tokens.size() != 3)
@@ -5314,6 +5321,66 @@ void MainServer::HandleMusicTagUpdateVolatile(const QStringList &slist, Playback
SendResponse(pbssock, strlist);
}
+void MainServer::HandleMusicCalcTrackLen(const QStringList &slist, PlaybackSock *pbs)
+{
+// format: MUSIC_CALC_TRACK_LENGTH <hostname> <songid>
+
+ 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("HandleMusicCalcTrackLen: asking slave '%1' to update the track length").arg(hostname));
+ strlist << slist.join(" ");
+ strlist = slave->ForwardRequest(strlist);
+ slave->DecrRef();
+
+ if (pbssock)
+ SendResponse(pbssock, strlist);
+
+ return;
+ }
+ else
+ {
+ LOG(VB_GENERAL, LOG_INFO,
+ QString("HandleMusicCalcTrackLen: Failed to grab slave socket on '%1'").arg(hostname));
+
+ strlist << "ERROR: slave not found";
+
+ if (pbssock)
+ SendResponse(pbssock, strlist);
+
+ return;
+ }
+ }
+ else
+ {
+ // run mythutil to calc the tracks length
+ QStringList paramList;
+ paramList.append(QString("--songid='%1'").arg(slist[2]));
+
+ QString command = "mythutil --calctracklen " + paramList.join(" ");
+
+ LOG(VB_GENERAL, LOG_INFO, QString("HandleMusicCalcTrackLen: running %1'").arg(command));
+ QScopedPointer<MythSystem> cmd(MythSystem::Create(command,
+ kMSAutoCleanup | kMSRunBackground |
+ kMSDontDisableDrawing | kMSProcessEvents |
+ kMSDontBlockInputDevs));
+ }
+
+ strlist << "OK";
+
+ if (pbssock)
+ SendResponse(pbssock, strlist);
+}
+
void MainServer::HandleMusicTagUpdateMetadata(const QStringList &slist, PlaybackSock *pbs)
{
// format: MUSIC_TAG_UPDATE_METADATA <hostname> <songid>
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 HandleMusicCalcTrackLen(const QStringList &slist, PlaybackSock *pbs);
void HandleVersion(MythSocket *socket, const QStringList &slist);
void HandleBackendRefresh(MythSocket *socket);
void HandleQueryLoad(PlaybackSock *pbs);

0 comments on commit b257f3c

Please sign in to comment.
Something went wrong with that request. Please try again.