00001
00002 #include <iostream>
00003
00004
00005 #include "exitcodes.h"
00006 #include "mythcorecontext.h"
00007 #include "mythlogging.h"
00008 #include "remoteutil.h"
00009 #include "scheduledrecording.h"
00010 #include "videometadata.h"
00011
00012
00013 #include "backendutils.h"
00014
00015 static int RawSendEvent(const QStringList &eventStringList)
00016 {
00017 if (eventStringList.isEmpty() || eventStringList[0].isEmpty())
00018 return GENERIC_EXIT_INVALID_CMDLINE;
00019
00020 if (gCoreContext->ConnectToMasterServer(false, false))
00021 {
00022 QStringList message("MESSAGE");
00023 message << eventStringList;
00024 gCoreContext->SendReceiveStringList(message);
00025 return GENERIC_EXIT_OK;
00026 }
00027 return GENERIC_EXIT_CONNECT_ERROR;
00028 }
00029
00030 static int ClearSettingsCache(const MythUtilCommandLineParser &cmdline)
00031 {
00032 if (gCoreContext->ConnectToMasterServer(false, false))
00033 {
00034 gCoreContext->SendMessage("CLEAR_SETTINGS_CACHE");
00035 LOG(VB_GENERAL, LOG_INFO, "Sent CLEAR_SETTINGS_CACHE message");
00036 return GENERIC_EXIT_OK;
00037 }
00038
00039 LOG(VB_GENERAL, LOG_ERR, "Unable to connect to backend, settings "
00040 "cache will not be cleared.");
00041 return GENERIC_EXIT_CONNECT_ERROR;
00042 }
00043
00044 static int SendEvent(const MythUtilCommandLineParser &cmdline)
00045 {
00046 return RawSendEvent(cmdline.toStringList("event"));
00047 }
00048
00049 static int SendSystemEvent(const MythUtilCommandLineParser &cmdline)
00050 {
00051 return RawSendEvent(QStringList(QString("SYSTEM_EVENT %1 SENDER %2")
00052 .arg(cmdline.toString("systemevent"))
00053 .arg(gCoreContext->GetHostName())));
00054 }
00055
00056 static int Reschedule(const MythUtilCommandLineParser &cmdline)
00057 {
00058 if (gCoreContext->ConnectToMasterServer(false, false))
00059 {
00060 ScheduledRecording::RescheduleMatch(0, 0, 0, QDateTime(),
00061 "MythUtilCommand");
00062 LOG(VB_GENERAL, LOG_INFO, "Reschedule command sent to master");
00063 return GENERIC_EXIT_OK;
00064 }
00065
00066 LOG(VB_GENERAL, LOG_ERR, "Cannot connect to master for reschedule");
00067 return GENERIC_EXIT_CONNECT_ERROR;
00068 }
00069
00070 static int ScanVideos(const MythUtilCommandLineParser &cmdline)
00071 {
00072 if (gCoreContext->ConnectToMasterServer(false, false))
00073 {
00074 gCoreContext->SendReceiveStringList(QStringList() << "SCAN_VIDEOS");
00075 LOG(VB_GENERAL, LOG_INFO, "Requested video scan");
00076 return GENERIC_EXIT_OK;
00077 }
00078
00079 LOG(VB_GENERAL, LOG_ERR, "Cannot connect to master for video scan");
00080 return GENERIC_EXIT_CONNECT_ERROR;
00081 }
00082
00083 static int ParseVideoFilename(const MythUtilCommandLineParser &cmdline)
00084 {
00085 QString filename = cmdline.toString("parsevideo");
00086 cout << "Title: " << VideoMetadata::FilenameToMeta(filename, 1)
00087 .toLocal8Bit().constData() << endl
00088 << "Season: " << VideoMetadata::FilenameToMeta(filename, 2)
00089 .toLocal8Bit().constData() << endl
00090 << "Episode: " << VideoMetadata::FilenameToMeta(filename, 3)
00091 .toLocal8Bit().constData() << endl
00092 << "Subtitle: " << VideoMetadata::FilenameToMeta(filename, 4)
00093 .toLocal8Bit().constData() << endl;
00094
00095 return GENERIC_EXIT_OK;
00096 }
00097
00098 void registerBackendUtils(UtilMap &utilMap)
00099 {
00100 utilMap["clearcache"] = &ClearSettingsCache;
00101 utilMap["event"] = &SendEvent;
00102 utilMap["resched"] = &Reschedule;
00103 utilMap["scanvideos"] = &ScanVideos;
00104 utilMap["systemevent"] = &SendSystemEvent;
00105 utilMap["parsevideo"] = &ParseVideoFilename;
00106 }
00107
00108