00001
00002 #include <iostream>
00003
00004
00005 #include "exitcodes.h"
00006 #include "mythlogging.h"
00007
00008
00009 #include "markuputils.h"
00010
00011 static int GetMarkupList(const MythUtilCommandLineParser &cmdline,
00012 const QString type)
00013 {
00014 ProgramInfo pginfo;
00015 if (!GetProgramInfo(cmdline, pginfo))
00016 return GENERIC_EXIT_NO_RECORDING_DATA;
00017
00018 frm_dir_map_t cutlist;
00019 frm_dir_map_t::const_iterator it;
00020 QString result;
00021
00022 if (type == "cutlist")
00023 pginfo.QueryCutList(cutlist);
00024 else
00025 pginfo.QueryCommBreakList(cutlist);
00026
00027 uint64_t lastStart = 0;
00028 for (it = cutlist.begin(); it != cutlist.end(); ++it)
00029 {
00030 if ((*it == MARK_COMM_START) ||
00031 (*it == MARK_CUT_START))
00032 {
00033 if (!result.isEmpty())
00034 result += ",";
00035 lastStart = it.key();
00036 result += QString("%1-").arg(lastStart);
00037 }
00038 else
00039 {
00040 if (result.isEmpty())
00041 result += "0-";
00042 result += QString("%1").arg(it.key());
00043 }
00044 }
00045
00046 if (result.endsWith('-'))
00047 {
00048 uint64_t lastFrame = pginfo.QueryLastFrameInPosMap() + 60;
00049 if (lastFrame > lastStart)
00050 result += QString("%1").arg(lastFrame);
00051 }
00052
00053 if (type == "cutlist")
00054 cout << QString("Cutlist: %1\n").arg(result).toLocal8Bit().constData();
00055 else
00056 {
00057 cout << QString("Commercial Skip List: %1\n")
00058 .arg(result).toLocal8Bit().constData();
00059 }
00060
00061 return GENERIC_EXIT_OK;
00062 }
00063
00064 static int SetMarkupList(const MythUtilCommandLineParser &cmdline,
00065 const QString &type, QString newList)
00066 {
00067 ProgramInfo pginfo;
00068 if (!GetProgramInfo(cmdline, pginfo))
00069 return GENERIC_EXIT_NO_RECORDING_DATA;
00070
00071 bool isCutlist = (type == "cutlist");
00072 frm_dir_map_t markuplist;
00073
00074 newList.replace(QRegExp(" "), "");
00075
00076 QStringList tokens = newList.split(",", QString::SkipEmptyParts);
00077
00078 if (newList.isEmpty())
00079 newList = "(EMPTY)";
00080
00081 for (int i = 0; i < tokens.size(); i++)
00082 {
00083 QStringList cutpair = tokens[i].split("-", QString::SkipEmptyParts);
00084 if (isCutlist)
00085 {
00086 markuplist[cutpair[0].toInt()] = MARK_CUT_START;
00087 markuplist[cutpair[1].toInt()] = MARK_CUT_END;
00088 }
00089 else
00090 {
00091 markuplist[cutpair[0].toInt()] = MARK_COMM_START;
00092 markuplist[cutpair[1].toInt()] = MARK_COMM_END;
00093 }
00094 }
00095
00096 if (isCutlist)
00097 {
00098 pginfo.SaveCutList(markuplist);
00099 cout << QString("Cutlist set to: %1\n")
00100 .arg(newList).toLocal8Bit().constData();
00101 LOG(VB_GENERAL, LOG_NOTICE, QString("Cutlist set to: %1").arg(newList));
00102 }
00103 else
00104 {
00105 pginfo.SaveCommBreakList(markuplist);
00106 cout << QString("Commercial Skip List set to: %1\n")
00107 .arg(newList).toLocal8Bit().constData();
00108 LOG(VB_GENERAL, LOG_NOTICE, QString("Commercial Skip List set to: %1").arg(newList));
00109 }
00110
00111 return GENERIC_EXIT_OK;
00112 }
00113
00114 static int GetCutList(const MythUtilCommandLineParser &cmdline)
00115 {
00116 return GetMarkupList(cmdline, "cutlist");
00117 }
00118
00119 static int SetCutList(const MythUtilCommandLineParser &cmdline)
00120 {
00121 return SetMarkupList(cmdline, QString("cutlist"),
00122 cmdline.toString("setcutlist"));
00123 }
00124
00125 static int ClearCutList(const MythUtilCommandLineParser &cmdline)
00126 {
00127 return SetMarkupList(cmdline, QString("cutlist"), QString(""));
00128 }
00129
00130 static int CopySkipListToCutList(const MythUtilCommandLineParser &cmdline)
00131 {
00132 ProgramInfo pginfo;
00133 if (!GetProgramInfo(cmdline, pginfo))
00134 return GENERIC_EXIT_NO_RECORDING_DATA;
00135
00136 frm_dir_map_t cutlist;
00137 frm_dir_map_t::const_iterator it;
00138
00139 pginfo.QueryCommBreakList(cutlist);
00140 for (it = cutlist.begin(); it != cutlist.end(); ++it)
00141 if (*it == MARK_COMM_START)
00142 cutlist[it.key()] = MARK_CUT_START;
00143 else
00144 cutlist[it.key()] = MARK_CUT_END;
00145 pginfo.SaveCutList(cutlist);
00146
00147 cout << "Commercial Skip List copied to Cutlist\n";
00148 LOG(VB_GENERAL, LOG_NOTICE, "Commercial Skip List copied to Cutlist");
00149
00150 return GENERIC_EXIT_OK;
00151 }
00152
00153 static int GetSkipList(const MythUtilCommandLineParser &cmdline)
00154 {
00155 return GetMarkupList(cmdline, "skiplist");
00156 }
00157
00158 static int SetSkipList(const MythUtilCommandLineParser &cmdline)
00159 {
00160 return SetMarkupList(cmdline, QString("skiplist"),
00161 cmdline.toString("setskiplist"));
00162 }
00163
00164 static int ClearSkipList(const MythUtilCommandLineParser &cmdline)
00165 {
00166 return SetMarkupList(cmdline, QString("skiplist"), QString(""));
00167 }
00168
00169 void registerMarkupUtils(UtilMap &utilMap)
00170 {
00171 utilMap["gencutlist"] = &CopySkipListToCutList;
00172 utilMap["getcutlist"] = &GetCutList;
00173 utilMap["setcutlist"] = &SetCutList;
00174 utilMap["clearcutlist"] = &ClearCutList;
00175 utilMap["getskiplist"] = &GetSkipList;
00176 utilMap["setskiplist"] = &SetSkipList;
00177 utilMap["clearskiplist"] = &ClearSkipList;
00178 }
00179
00180