Skip to content
Permalink
Browse files

mainserver: Add MUSIC_LYRICS_SAVE command

format: MUSIC_LYRICS_SAVE <hostname> <songid>
followed by the lyrics lines
  • Loading branch information...
Paul Harrison
Paul Harrison committed Sep 23, 2015
1 parent 7126654 commit 20603add41a1ee9eaa85cd11b8e73f3487eca765
Showing with 85 additions and 3 deletions.
  1. +84 −3 mythtv/programs/mythbackend/mainserver.cpp
  2. +1 −0 mythtv/programs/mythbackend/mainserver.h
@@ -898,6 +898,13 @@ void MainServer::ProcessRequestWork(MythSocket *sock)
{
HandleMusicGetLyricGrabbers(listline, pbs);
}
else if (command == "MUSIC_LYRICS_SAVE")
{
if (listline.size() < 3)
SendErrorResponse(pbs, "Bad MUSIC_LYRICS_SAVE");
else
HandleMusicSaveLyrics(listline, pbs);
}
else if (command == "IMAGE_SCAN")
{
QStringList reply = ImageScan::getInstance()->HandleScanRequest(listline);
@@ -6542,13 +6549,13 @@ void MainServer::HandleMusicFindLyrics(const QStringList &slist, PlaybackSock *p
paramList.append(QString("--grabber='%1'").arg(grabberName));

if (!artist.isEmpty())
paramList.append(QString("--artist='%1'").arg(artist));
paramList.append(QString("--artist=\"%1\"").arg(artist));

if (!album.isEmpty())
paramList.append(QString("--album='%1'").arg(album));
paramList.append(QString("--album=\"%1\"").arg(album));

if (!title.isEmpty())
paramList.append(QString("--title='%1'").arg(title));
paramList.append(QString("--title=\"%1\"").arg(title));

QString command = GetAppBinDir() + "mythutil --findlyrics " + paramList.join(" ");

@@ -6649,6 +6656,80 @@ void MainServer::HandleMusicGetLyricGrabbers(const QStringList &slist, PlaybackS
SendResponse(pbssock, strlist);
}

void MainServer::HandleMusicSaveLyrics(const QStringList& slist, PlaybackSock* pbs)
{
// format: MUSIC_LYRICS_SAVE <hostname> <songid>
// followed by the lyrics lines

QStringList strlist;

MythSocket *pbssock = pbs->getSocket();

QString hostname = slist[1];
int songID = slist[2].toInt();

if (ismaster && !gCoreContext->IsThisHost(hostname))
{
// forward the request to the slave BE
PlaybackSock *slave = GetMediaServerByHostname(hostname);
if (slave)
{
LOG(VB_GENERAL, LOG_INFO, LOC +
QString("HandleMusicSaveLyrics: asking slave '%1' to "
"save the lyrics").arg(hostname));
strlist = slave->ForwardRequest(slist);
slave->DecrRef();

if (pbssock)
SendResponse(pbssock, strlist);

return;
}
else
{
LOG(VB_GENERAL, LOG_INFO, LOC +
QString("HandleMusicSaveLyrics: Failed to grab slave "
"socket on '%1'").arg(hostname));
}
}
else
{
MusicMetadata *mdata = MusicMetadata::createFromID(songID);
if (!mdata)
{
LOG(VB_GENERAL, LOG_ERR, QString("Cannot find metadata for trackid: %1").arg(songID));
strlist << QString("ERROR: Cannot find metadata for trackid: %1").arg(songID);

if (pbssock)
SendResponse(pbssock, strlist);

return;
}

QString lyricsFile = GetConfDir() + QString("/MythMusic/Lyrics/%1.txt").arg(songID);

// remove any existing lyrics for this songID
if (QFile::exists(lyricsFile))
QFile::remove(lyricsFile);

// save the new lyrics
QFile file(QLatin1String(qPrintable(lyricsFile)));

if (file.open(QIODevice::WriteOnly))
{
QTextStream stream(&file);
for (int x = 3; x < slist.count(); x++)
stream << slist.at(x);
file.close();
}
}

strlist << "OK";

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

void MainServer::HandleFileTransferQuery(QStringList &slist,
QStringList &commands,
PlaybackSock *pbs)
@@ -231,6 +231,7 @@ class MainServer : public QObject, public MythSocketCBs
void HandleMusicCalcTrackLen(const QStringList &slist, PlaybackSock *pbs);
void HandleMusicFindLyrics(const QStringList &slist, PlaybackSock *pbs);
void HandleMusicGetLyricGrabbers(const QStringList &slist, PlaybackSock *pbs);
void HandleMusicSaveLyrics(const QStringList &slist, PlaybackSock *pbs);
void HandleVersion(MythSocket *socket, const QStringList &slist);
void HandleBackendRefresh(MythSocket *socket);
void HandleQueryLoad(PlaybackSock *pbs);

0 comments on commit 20603ad

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