Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for new MythMusic control added in SHA: 747c374 to the
frontend network control interface. Added commands are: play music play play music pause play music stop play music setvolume N play music file FILE play music track N play music url URL Also added to pull information: play music getvolume -> current volume play music getmeta -> metadata string of current media This commit also disables the regular expression character filter which is currently preventing Myth URIs with defined storage groups or UTF-8
- Loading branch information
Showing
1 changed file
with
151 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,4 +1,4 @@ | |||
#include <unistd.h> | # include <unistd.h> | ||
|
|
||
#include <QCoreApplication> | #include <QCoreApplication> | ||
#include <QRegExp> | #include <QRegExp> | ||
|
@@ -416,7 +416,7 @@ void NetworkControlClient::readClient(void) | ||
while (socket->canReadLine()) | while (socket->canReadLine()) | ||
{ | { | ||
lineIn = socket->readLine(); | lineIn = socket->readLine(); | ||
lineIn.replace(QRegExp("[^-a-zA-Z0-9\\s\\.:_#/$%&()*+,;<=>?\\[\\]\\|]"), ""); | // lineIn.replace(QRegExp("[^-a-zA-Z0-9\\s\\.:_#/$%&()*+,;<=>?\\[\\]\\|]"), ""); | ||
lineIn.replace(QRegExp("[\r\n]"), ""); | lineIn.replace(QRegExp("[\r\n]"), ""); | ||
lineIn.replace(QRegExp("^\\s"), ""); | lineIn.replace(QRegExp("^\\s"), ""); | ||
|
|
||
|
@@ -654,6 +654,86 @@ QString NetworkControl::processPlay(NetworkCommand *nc, int clientID) | ||
.arg(GetMythUI()->GetCurrentLocation()); | .arg(GetMythUI()->GetCurrentLocation()); | ||
} | } | ||
} | } | ||
else if (is_abbrev("music", nc->getArg(1))) | |||
{ | |||
if (GetMythUI()->GetCurrentLocation().toLower() != "playmusic") | |||
{ | |||
return QString("ERROR: You are in %1 mode and this command is " | |||
"only for MythMusic") | |||
.arg(GetMythUI()->GetCurrentLocation()); | |||
} | |||
|
|||
if (nc->getArgCount() == 3) | |||
{ | |||
if (is_abbrev("play", nc->getArg(2))) | |||
message = "MUSIC_COMMAND PLAY"; | |||
else if (is_abbrev("pause", nc->getArg(2))) | |||
message = "MUSIC_COMMAND PAUSE"; | |||
else if (is_abbrev("stop", nc->getArg(2))) | |||
message = "MUSIC_COMMAND STOP"; | |||
else if (is_abbrev("getvolume", nc->getArg(2))) | |||
{ | |||
gotAnswer = false; | |||
|
|||
MythEvent me(QString("MUSIC_COMMAND GET_VOLUME")); | |||
gCoreContext->dispatch(me); | |||
|
|||
QTime timer; | |||
timer.start(); | |||
while (timer.elapsed() < 2000 && !gotAnswer) | |||
{ | |||
qApp->processEvents(); | |||
usleep(10000); | |||
} | |||
|
|||
if (gotAnswer) | |||
return answer; | |||
|
|||
return "unknown"; | |||
} | |||
else if (is_abbrev("getmeta", nc->getArg(2))) | |||
{ | |||
gotAnswer = false; | |||
|
|||
MythEvent me(QString("MUSIC_COMMAND GET_METADATA")); | |||
gCoreContext->dispatch(me); | |||
|
|||
QTime timer; | |||
timer.start(); | |||
while (timer.elapsed() < 2000 && !gotAnswer) | |||
{ | |||
qApp->processEvents(); | |||
usleep(10000); | |||
} | |||
|
|||
if (gotAnswer) | |||
return answer; | |||
|
|||
return "unknown"; | |||
} | |||
else | |||
return QString("ERROR: Invalid 'play music' command"); | |||
} | |||
else if (nc->getArgCount() > 3) | |||
{ | |||
if (is_abbrev("setvolume", nc->getArg(2))) | |||
message = QString("MUSIC_COMMAND SET_VOLUME %1") | |||
.arg(nc->getArg(3)); | |||
else if (is_abbrev("track", nc->getArg(2))) | |||
message = QString("MUSIC_COMMAND PLAY_TRACK %1") | |||
.arg(nc->getArg(3)); | |||
else if (is_abbrev("url", nc->getArg(2))) | |||
message = QString("MUSIC_COMAMND PLAY_URL %1") | |||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
wagnerrp
Author
Member
|
|||
.arg(nc->getArg(3)); | |||
else if (is_abbrev("file", nc->getArg(2))) | |||
message = QString("MUSIC_COMMAND PLAY_FILE '%1'") | |||
.arg(nc->getFrom(3)); | |||
else | |||
return QString("ERROR: Invalid 'play music' command"); | |||
} | |||
else | |||
return QString("ERROR: Invalid 'play music' command"); | |||
} | |||
// Everything below here requires us to be in playback mode so check to | // Everything below here requires us to be in playback mode so check to | ||
// see if we are | // see if we are | ||
else if (GetMythUI()->GetCurrentLocation().toLower() != "playback") | else if (GetMythUI()->GetCurrentLocation().toLower() != "playback") | ||
|
@@ -1010,35 +1090,44 @@ QString NetworkControl::processHelp(NetworkCommand *nc) | ||
else if (is_abbrev("play", command)) | else if (is_abbrev("play", command)) | ||
{ | { | ||
helpText += | helpText += | ||
"play volume NUMBER% - Change volume to given percentage value\r\n" | "play volume NUMBER% - Change volume to given percentage value\r\n" | ||
"play channel up - Change channel Up\r\n" | "play channel up - Change channel Up\r\n" | ||
"play channel down - Change channel Down\r\n" | "play channel down - Change channel Down\r\n" | ||
"play channel NUMBER - Change to a specific channel number\r\n" | "play channel NUMBER - Change to a specific channel number\r\n" | ||
"play chanid NUMBER - Change to a specific channel id (chanid)\r\n" | "play chanid NUMBER - Change to a specific channel id (chanid)\r\n" | ||
"play file FILENAME - Play FILENAME (FILENAME may be a file or a myth:// URL)\r\n" | "play file FILENAME - Play FILENAME (FILENAME may be a file or a myth:// URL)\r\n" | ||
"play program CHANID yyyy-MM-ddThh:mm:ss\r\n" | "play program CHANID yyyy-MM-ddThh:mm:ss\r\n" | ||
" - Play program with chanid & starttime\r\n" | " - Play program with chanid & starttime\r\n" | ||
"play program CHANID yyyy-MM-ddThh:mm:ss resume\r\n" | "play program CHANID yyyy-MM-ddThh:mm:ss resume\r\n" | ||
" - Resume program with chanid & starttime\r\n" | " - Resume program with chanid & starttime\r\n" | ||
"play save preview\r\n" | "play save preview\r\n" | ||
" - Save preview image from current position\r\n" | " - Save preview image from current position\r\n" | ||
"play save preview FILENAME\r\n" | "play save preview FILENAME\r\n" | ||
" - Save preview image to FILENAME\r\n" | " - Save preview image to FILENAME\r\n" | ||
"play save preview FILENAME WxH\r\n" | "play save preview FILENAME WxH\r\n" | ||
" - Save preview image of size WxH\r\n" | " - Save preview image of size WxH\r\n" | ||
"play seek beginning - Seek to the beginning of the recording\r\n" | "play seek beginning - Seek to the beginning of the recording\r\n" | ||
"play seek forward - Skip forward in the video\r\n" | "play seek forward - Skip forward in the video\r\n" | ||
"play seek backward - Skip backwards in the video\r\n" | "play seek backward - Skip backwards in the video\r\n" | ||
"play seek HH:MM:SS - Seek to a specific position\r\n" | "play seek HH:MM:SS - Seek to a specific position\r\n" | ||
"play speed pause - Pause playback\r\n" | "play speed pause - Pause playback\r\n" | ||
"play speed normal - Playback at normal speed\r\n" | "play speed normal - Playback at normal speed\r\n" | ||
"play speed 1x - Playback at normal speed\r\n" | "play speed 1x - Playback at normal speed\r\n" | ||
"play speed SPEEDx - Playback where SPEED must be a decimal\r\n" | "play speed SPEEDx - Playback where SPEED must be a decimal\r\n" | ||
"play speed 1/8x - Playback at 1/8x speed\r\n" | "play speed 1/8x - Playback at 1/8x speed\r\n" | ||
"play speed 1/4x - Playback at 1/4x speed\r\n" | "play speed 1/4x - Playback at 1/4x speed\r\n" | ||
"play speed 1/3x - Playback at 1/3x speed\r\n" | "play speed 1/3x - Playback at 1/3x speed\r\n" | ||
"play speed 1/2x - Playback at 1/2x speed\r\n" | "play speed 1/2x - Playback at 1/2x speed\r\n" | ||
"play stop - Stop playback\r\n"; | "play stop - Stop playback\r\n" | ||
"play music play - Resume playback (MythMusic)\r\n" | |||
"play music pause - Pause playback (MythMusic)\r\n" | |||
"play music stop - Stop Playback (MythMusic)\r\n" | |||
"play music setvolume N - Set volume to number (MythMusic)\r\n" | |||
"play music getvolume - Get current volume (MythMusic)\r\n" | |||
"play music getmeta - Get metadata for current track (MythMusic)\r\n" | |||
"play music file NAME - Play specified file (MythMusic)\r\n" | |||
"play music track N - Switch to specified track (MythMusic)\r\n" | |||
"play music url URL - Play specified URL (MythMusic)\r\n"; | |||
} | } | ||
else if (is_abbrev("query", command)) | else if (is_abbrev("query", command)) | ||
{ | { | ||
|
@@ -1137,35 +1226,48 @@ void NetworkControl::customEvent(QEvent *e) | ||
MythEvent *me = (MythEvent *)e; | MythEvent *me = (MythEvent *)e; | ||
QString message = me->Message(); | QString message = me->Message(); | ||
|
|
||
if (message.left(15) != "NETWORK_CONTROL") | if (message.left(13) == "MUSIC_CONTROL") | ||
return; | |||
|
|||
QStringList tokens = message.simplified().split(" "); | |||
if ((tokens.size() >= 3) && | |||
(tokens[1] == "ANSWER")) | |||
{ | { | ||
answer = tokens[2]; | QStringList tokens = message.simplified().split(" "); | ||
for (int i = 3; i < tokens.size(); i++) | if ((tokens.size() >= 3) && | ||
answer += QString(" ") + tokens[i]; | (tokens[1] == "ANSWER")) | ||
gotAnswer = true; | { | ||
answer = tokens[2]; | |||
for (int i = 3; i < tokens.size(); i++) | |||
answer += QString(" ") + tokens[i]; | |||
gotAnswer = true; | |||
} | |||
|
|||
} | } | ||
else if ((tokens.size() >= 4) && | else if (message.left(15) == "NETWORK_CONTROL") | ||
(tokens[1] == "RESPONSE")) | |||
{ | { | ||
int clientID = tokens[2].toInt(); | QStringList tokens = message.simplified().split(" "); | ||
QString response = tokens[3]; | if ((tokens.size() >= 3) && | ||
for (int i = 4; i < tokens.size(); i++) | (tokens[1] == "ANSWER")) | ||
response += QString(" ") + tokens[i]; | { | ||
answer = tokens[2]; | |||
for (int i = 3; i < tokens.size(); i++) | |||
answer += QString(" ") + tokens[i]; | |||
gotAnswer = true; | |||
} | |||
else if ((tokens.size() >= 4) && | |||
(tokens[1] == "RESPONSE")) | |||
{ | |||
int clientID = tokens[2].toInt(); | |||
QString response = tokens[3]; | |||
for (int i = 4; i < tokens.size(); i++) | |||
response += QString(" ") + tokens[i]; | |||
|
|
||
clientLock.lock(); | clientLock.lock(); | ||
NetworkControlClient *ncc = clients.at(clientID); | NetworkControlClient *ncc = clients.at(clientID); | ||
clientLock.unlock(); | clientLock.unlock(); | ||
|
|
||
nrLock.lock(); | nrLock.lock(); | ||
networkControlReplies.push_back(new NetworkCommand(ncc, response)); | networkControlReplies.push_back(new NetworkCommand(ncc, response)); | ||
nrLock.unlock(); | nrLock.unlock(); | ||
|
|
||
notifyDataAvailable(); | notifyDataAvailable(); | ||
} | |||
} | } | ||
} | } | ||
else if (e->type() == kNetworkControlDataReadyEvent) | else if (e->type() == kNetworkControlDataReadyEvent) | ||
|
is this a typo? should be MUSIC_COMMAND?
is it worth #defining these constants so the compiler checks them?