forked from rofafor/vdr-plugin-iptv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.cpp
283 lines (227 loc) · 8.06 KB
/
source.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
* source.c: IPTV plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include <cctype>
#include "common.h"
#include "log.h"
#include "source.h"
// --- cIptvTransponderParameters --------------------------------------------
cIptvTransponderParameters::cIptvTransponderParameters(const char *parametersP)
: sidScanM(0),
pidScanM(0),
protocolM(eProtocolUDP),
parameterM(0),
useYtdlp(0),
handlerType('F') {
debug1("%s (%s)", __PRETTY_FUNCTION__, parametersP);
memset(&addressM, 0, sizeof(addressM));
Parse(parametersP);
}
std::string cIptvTransponderParameters::ToString(char typeP) const {
debug1("%s (%c)", __PRETTY_FUNCTION__, typeP);
std::string tostr;
tostr.append("S=").append(std::to_string(sidScanM));
tostr.append("|P=").append(std::to_string(pidScanM));
tostr.append("|F=").append(ProtocolToStr(protocolM));
tostr.append("|U=").append(addressM);
tostr.append("|A=").append(std::to_string(parameterM));
if (useYtdlp > 0) {
tostr.append("|Y=").append(std::to_string(useYtdlp));
}
tostr.append("|H=").append(std::string(1 , handlerType));
if (!xmltvId.empty()) {
tostr.append("|X=").append(xmltvId);
}
return { tostr };
}
int cIptvTransponderParameters::StrToProtocol(const char *prot) {
int protocolM = -1;
if (strstr(prot, "UDP")) {
protocolM = eProtocolUDP;
} else if (strstr(prot, "CURL")) {
protocolM = eProtocolCURL;
} else if (strstr(prot, "HTTP")) {
protocolM = eProtocolHTTP;
} else if (strstr(prot, "FILE")) {
protocolM = eProtocolFILE;
} else if (strstr(prot, "EXTT")) {
protocolM = eProtocolEXTT;
} else if (strstr(prot, "EXT")) {
protocolM = eProtocolEXT;
} else if (strstr(prot, "M3US")) {
protocolM = eProtocolM3US;
} else if (strstr(prot, "M3U")) {
protocolM = eProtocolM3U;
} else if (strstr(prot, "RADIO")) {
protocolM = eProtocolRadio;
} else if (strstr(prot, "STREAM")) {
protocolM = eProtocolStream;
} else if (strstr(prot, "YT")) {
protocolM = eProtocolYT;
}
return protocolM;
}
std::string cIptvTransponderParameters::ProtocolToStr(int prot) {
std::string protocolstr;
switch (prot) {
case eProtocolEXT:
protocolstr = "EXT";
break;
case eProtocolEXTT:
protocolstr = "EXTT";
break;
case eProtocolCURL:
protocolstr = "CURL";
break;
case eProtocolHTTP:
protocolstr = "HTTP";
break;
case eProtocolFILE:
protocolstr = "FILE";
break;
case eProtocolM3U:
protocolstr = "M3U";
break;
case eProtocolM3US:
protocolstr = "M3US";
break;
case eProtocolRadio:
protocolstr = "RADIO";
break;
case eProtocolStream:
protocolstr = "STREAM";
break;
case eProtocolYT:
protocolstr = "YT";
break;
default:
case eProtocolUDP:
protocolstr = "UDP";
break;
}
return protocolstr;
}
bool cIptvTransponderParameters::Parse(const char *strP) {
debug1("%s (%s)", __PRETTY_FUNCTION__, strP);
bool result = false;
int tmpProto;
if (strP && *strP) {
const char *delim = "|";
char *str = strdup(strP);
char *p = str;
char *saveptr = nullptr;
char *token = nullptr;
bool found_s = false;
bool found_p = false;
bool found_f = false;
bool found_u = false;
bool found_a = false;
while ((token = strtok_r(str, delim, &saveptr))!=nullptr) {
char *data = token;
++data;
if (data && (*data=='=')) {
++data;
switch (toupper(*token)) {
case 'S':
sidScanM = (int) strtol(data, (char **) nullptr, 10);
found_s = true;
break;
case 'P':
pidScanM = (int) strtol(data, (char **) nullptr, 10);
found_p = true;
break;
case 'F':
tmpProto = StrToProtocol(data);
if (tmpProto != -1) {
protocolM = tmpProto;
found_f = true;
}
break;
case 'U':
strn0cpy(addressM, data, sizeof(addressM));
found_u = true;
break;
case 'A':
parameterM = (int) strtol(data, (char **) nullptr, 10);
found_a = true;
break;
case 'Y':
useYtdlp = (int) strtol(data, (char **) nullptr, 10);
break;
case 'H':
if (data[0] == 'F' || data[0] == 'V' || data[0] == 'E') {
handlerType = data[0];
}
break;
case 'X':
xmltvId = std::string(data);
break;
default:
break;
}
}
str = nullptr;
}
// Y is optional and therefore not recognized
if (found_s && found_p && found_f && found_u && found_a) {
result = true;
} else {
error("Invalid channel parameters: %s", p);
}
free(p);
}
return (result);
}
// --- cIptvSourceParam ------------------------------------------------------
const char *cIptvSourceParam::allowedProtocolCharsS = " abcdefghijklmnopqrstuvwxyz0123456789-.,#~\\^$[]()*+?{}/%@&=";
cIptvSourceParam::cIptvSourceParam(char sourceP, const char *descriptionP)
: cSourceParam(sourceP, descriptionP),
paramM(0),
ridM(0),
dataM(),
itpM() {
debug1("%s (%c, %s)", __PRETTY_FUNCTION__, sourceP, descriptionP);
protocolsM[cIptvTransponderParameters::eProtocolUDP] = tr("UDP");
protocolsM[cIptvTransponderParameters::eProtocolCURL] = tr("CURL");
protocolsM[cIptvTransponderParameters::eProtocolHTTP] = tr("HTTP");
protocolsM[cIptvTransponderParameters::eProtocolFILE] = tr("FILE");
protocolsM[cIptvTransponderParameters::eProtocolEXT] = tr("EXT");
protocolsM[cIptvTransponderParameters::eProtocolEXTT] = tr("EXTT");
protocolsM[cIptvTransponderParameters::eProtocolM3U] = tr("M3U");
protocolsM[cIptvTransponderParameters::eProtocolM3US] = tr("M3US");
protocolsM[cIptvTransponderParameters::eProtocolRadio] = tr("RADIO");
protocolsM[cIptvTransponderParameters::eProtocolStream] = tr("STREAM");
protocolsM[cIptvTransponderParameters::eProtocolYT] = tr("YT");
}
void cIptvSourceParam::SetData(cChannel *channelP) {
debug1("%s (%s)", __PRETTY_FUNCTION__, channelP->Parameters());
dataM = *channelP;
ridM = dataM.Rid();
itpM.Parse(dataM.Parameters());
paramM = 0;
}
void cIptvSourceParam::GetData(cChannel *channelP) {
debug1("%s (%s)", __PRETTY_FUNCTION__, channelP->Parameters());
channelP->SetTransponderData(channelP->Source(),
channelP->Frequency(),
dataM.Srate(),
itpM.ToString(Source()).c_str(),
true);
channelP->SetId(nullptr, channelP->Nid(), channelP->Tid(), channelP->Sid(), ridM);
}
cOsdItem *cIptvSourceParam::GetOsdItem() {
debug1("%s", __PRETTY_FUNCTION__);
switch (paramM++) {
case 0: return new cMenuEditIntItem(tr("Rid"), &ridM, 0);
case 1: return new cMenuEditBoolItem(tr("Scan section ids"), &itpM.sidScanM);
case 2: return new cMenuEditBoolItem(tr("Scan pids"), &itpM.pidScanM);
case 3: return new cMenuEditStraItem(tr("Protocol"), &itpM.protocolM, ELEMENTS(protocolsM), protocolsM);
case 4: return new cMenuEditStrItem(tr("Address"), itpM.addressM, sizeof(itpM.addressM), allowedProtocolCharsS);
case 5: return new cMenuEditIntItem(tr("Parameter"), &itpM.parameterM, 0, 0xFFFF);
default:
return nullptr;
}
}