/
markuputils.cpp
200 lines (167 loc) · 5.66 KB
/
markuputils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// C++ includes
#include <iostream>
// libmyth* includes
#include "exitcodes.h"
#include "mythlogging.h"
// Local includes
#include "markuputils.h"
static int GetMarkupList(const MythUtilCommandLineParser &cmdline,
const QString type)
{
ProgramInfo pginfo;
if (!GetProgramInfo(cmdline, pginfo))
return GENERIC_EXIT_NO_RECORDING_DATA;
frm_dir_map_t cutlist;
frm_dir_map_t::const_iterator it;
QString result;
if (type == "cutlist")
pginfo.QueryCutList(cutlist);
else
pginfo.QueryCommBreakList(cutlist);
uint64_t lastStart = 0;
for (it = cutlist.begin(); it != cutlist.end(); ++it)
{
if ((*it == MARK_COMM_START) ||
(*it == MARK_CUT_START))
{
if (!result.isEmpty())
result += ",";
lastStart = it.key();
result += QString("%1-").arg(lastStart);
}
else
{
if (result.isEmpty())
result += "0-";
result += QString("%1").arg(it.key());
}
}
if (result.endsWith('-'))
{
uint64_t lastFrame = pginfo.QueryLastFrameInPosMap() + 60;
if (lastFrame > lastStart)
result += QString("%1").arg(lastFrame);
}
if (type == "cutlist")
cout << QString("Cutlist: %1\n").arg(result).toLocal8Bit().constData();
else
{
cout << QString("Commercial Skip List: %1\n")
.arg(result).toLocal8Bit().constData();
}
return GENERIC_EXIT_OK;
}
static int SetMarkupList(const MythUtilCommandLineParser &cmdline,
const QString &type, QString newList)
{
ProgramInfo pginfo;
if (!GetProgramInfo(cmdline, pginfo))
return GENERIC_EXIT_NO_RECORDING_DATA;
bool isCutlist = (type == "cutlist");
frm_dir_map_t markuplist;
newList.replace(QRegExp(" "), "");
QStringList tokens = newList.split(",", QString::SkipEmptyParts);
if (newList.isEmpty())
newList = "(EMPTY)";
for (int i = 0; i < tokens.size(); i++)
{
QStringList cutpair = tokens[i].split("-", QString::SkipEmptyParts);
if (isCutlist)
{
markuplist[cutpair[0].toInt()] = MARK_CUT_START;
markuplist[cutpair[1].toInt()] = MARK_CUT_END;
}
else
{
markuplist[cutpair[0].toInt()] = MARK_COMM_START;
markuplist[cutpair[1].toInt()] = MARK_COMM_END;
}
}
if (isCutlist)
{
pginfo.SaveCutList(markuplist);
cout << QString("Cutlist set to: %1\n")
.arg(newList).toLocal8Bit().constData();
LOG(VB_GENERAL, LOG_NOTICE, QString("Cutlist set to: %1").arg(newList));
}
else
{
pginfo.SaveCommBreakList(markuplist);
cout << QString("Commercial Skip List set to: %1\n")
.arg(newList).toLocal8Bit().constData();
LOG(VB_GENERAL, LOG_NOTICE, QString("Commercial Skip List set to: %1").arg(newList));
}
return GENERIC_EXIT_OK;
}
static int GetCutList(const MythUtilCommandLineParser &cmdline)
{
return GetMarkupList(cmdline, "cutlist");
}
static int SetCutList(const MythUtilCommandLineParser &cmdline)
{
return SetMarkupList(cmdline, QString("cutlist"),
cmdline.toString("setcutlist"));
}
static int ClearCutList(const MythUtilCommandLineParser &cmdline)
{
return SetMarkupList(cmdline, QString("cutlist"), QString(""));
}
static int CopySkipListToCutList(const MythUtilCommandLineParser &cmdline)
{
ProgramInfo pginfo;
if (!GetProgramInfo(cmdline, pginfo))
return GENERIC_EXIT_NO_RECORDING_DATA;
frm_dir_map_t cutlist;
frm_dir_map_t::const_iterator it;
pginfo.QueryCommBreakList(cutlist);
for (it = cutlist.begin(); it != cutlist.end(); ++it)
if (*it == MARK_COMM_START)
cutlist[it.key()] = MARK_CUT_START;
else
cutlist[it.key()] = MARK_CUT_END;
pginfo.SaveCutList(cutlist);
cout << "Commercial Skip List copied to Cutlist\n";
LOG(VB_GENERAL, LOG_NOTICE, "Commercial Skip List copied to Cutlist");
return GENERIC_EXIT_OK;
}
static int GetSkipList(const MythUtilCommandLineParser &cmdline)
{
return GetMarkupList(cmdline, "skiplist");
}
static int SetSkipList(const MythUtilCommandLineParser &cmdline)
{
return SetMarkupList(cmdline, QString("skiplist"),
cmdline.toString("setskiplist"));
}
static int ClearSkipList(const MythUtilCommandLineParser &cmdline)
{
return SetMarkupList(cmdline, QString("skiplist"), QString(""));
}
static int ClearSeekTable(const MythUtilCommandLineParser &cmdline)
{
ProgramInfo pginfo;
if (!GetProgramInfo(cmdline, pginfo))
return GENERIC_EXIT_NO_RECORDING_DATA;
cout << "Clearing Seek Table\n";
LOG(VB_GENERAL, LOG_NOTICE,
QString("Clearing Seek Table for Channel ID %1 @ %2")
.arg(pginfo.GetChanID())
.arg(pginfo.GetScheduledStartTime().toString()));
pginfo.ClearPositionMap(MARK_GOP_BYFRAME);
pginfo.ClearPositionMap(MARK_GOP_START);
pginfo.ClearPositionMap(MARK_KEYFRAME);
pginfo.ClearPositionMap(MARK_DURATION_MS);
return GENERIC_EXIT_OK;
}
void registerMarkupUtils(UtilMap &utilMap)
{
utilMap["gencutlist"] = &CopySkipListToCutList;
utilMap["getcutlist"] = &GetCutList;
utilMap["setcutlist"] = &SetCutList;
utilMap["clearcutlist"] = &ClearCutList;
utilMap["getskiplist"] = &GetSkipList;
utilMap["setskiplist"] = &SetSkipList;
utilMap["clearskiplist"] = &ClearSkipList;
utilMap["clearseektable"] = &ClearSeekTable;
}
/* vim: set expandtab tabstop=4 shiftwidth=4: */