8 #include <QRegularExpression>
33 if (!match.hasMatch())
36 major = match.capturedView(1).toInt();
37 minor = match.capturedView(2).toInt();
46 "WHERE sourceid = :SOURCEID");
50 query.
value(0).toString() ==
"HDTV")
61 bool isEncoder =
false;
62 bool isUnscanable =
false;
74 insert_channels = (isCableCard || isEncoder || isUnscanable);
77 return insert_channels;
82 ChannelInfoList::iterator chaninfo,
unsigned int chanid)
const
84 (*chaninfo).m_name =
getResponse(QObject::tr(
"Choose a channel name (any string, "
85 "long version) "),(*chaninfo).m_name);
86 (*chaninfo).m_callSign =
getResponse(QObject::tr(
"Choose a channel callsign (any string, "
87 "short version) "),(*chaninfo).m_callSign);
91 (*chaninfo).m_chanNum =
getResponse(QObject::tr(
"Choose a channel preset (0..999) "),
92 (*chaninfo).m_chanNum);
93 (*chaninfo).m_freqId =
getResponse(QObject::tr(
"Choose a frequency id "),
94 (*chaninfo).m_freqId);
98 (*chaninfo).m_chanNum =
getResponse(QObject::tr(
"Choose a channel number "),
99 (*chaninfo).m_chanNum);
100 (*chaninfo).m_freqId = (*chaninfo).m_chanNum;
103 (*chaninfo).m_fineTune =
getResponse(QObject::tr(
"Choose a channel fine tune offset "),
104 QString::number((*chaninfo).m_fineTune)).toInt();
106 (*chaninfo).m_tvFormat =
getResponse(QObject::tr(
"Choose a TV format "
107 "(PAL/SECAM/NTSC/ATSC/Default) "),
108 (*chaninfo).m_tvFormat);
110 (*chaninfo).m_icon =
getResponse(QObject::tr(
"Choose a channel icon image "
111 "(relative path to icon storage group) "),
119 QString result = chanName;
122 result = result.toLower();
124 result = result.replace(
" ",
"");
143 QString chanName = channel.m_name;
145 retList.insert(key, channel);
154 ChannelList::iterator it;
155 for (it = existingChannels.begin(); it != existingChannels.end(); ++it)
157 if ((*it).m_xmltvId == chanInfo.
m_xmltvId)
162 ChannelInfo existChan = existingChannels.value(searchKey);
168 if (match.hasMatch())
171 uint major = match.capturedView(1).toUInt();
172 uint minor = match.capturedView(2).toUInt();
174 for (it = existingChannels.begin();
175 it != existingChannels.end(); ++it)
177 if ((*it).m_atscMajorChan == major &&
178 (*it).m_atscMinorChan ==
minor)
191 LOG(VB_GENERAL, LOG_NOTICE,
"Skipping Channel Updates");
198 QDir::setCurrent(fileprefix);
204 auto i = chanlist->begin();
205 for (; i != chanlist->end(); ++i)
207 if ((*i).m_xmltvId.isEmpty())
212 if (!(*i).m_icon.isEmpty())
214 QDir remotefile = QDir((*i).m_icon);
215 QString
filename = remotefile.dirName();
218 QFile actualfile(localfile);
219 if (!actualfile.exists() &&
222 LOG(VB_GENERAL, LOG_ERR,
223 QString(
"Failed to fetch icon from '%1'")
232 if (!(*i).m_oldXmltvId.isEmpty())
237 "WHERE xmltvid = :XMLTVID");
238 query.
bindValue(
":XMLTVID", (*i).m_oldXmltvId);
244 else if (query.
next())
246 LOG(VB_GENERAL, LOG_INFO,
247 QString(
"Converting old xmltvid (%1) to new (%2)")
248 .arg((*i).m_oldXmltvId, (*i).m_xmltvId));
250 query.
prepare(
"UPDATE channel "
251 "SET xmltvid = :NEWXMLTVID"
252 "WHERE xmltvid = :OLDXMLTVID");
253 query.
bindValue(
":NEWXMLTVID", (*i).m_xmltvId);
254 query.
bindValue(
":OLDXMLTVID", (*i).m_oldXmltvId);
266 LOG(VB_XMLTV, LOG_DEBUG,
267 QString(
"Match found for xmltvid %1 to channel %2 (%3)")
268 .arg((*i).m_xmltvId, dbChan.
m_name, QString::number(dbChan.
m_chanId)));
272 std::cout <<
"### " << std::endl;
273 std::cout <<
"### Existing channel found" << std::endl;
274 std::cout <<
"### " << std::endl;
275 std::cout <<
"### xmltvid = "
276 << (*i).m_xmltvId.toLocal8Bit().constData() << std::endl;
277 std::cout <<
"### chanid = "
279 std::cout <<
"### name = "
280 << dbChan.
m_name.toLocal8Bit().constData() << std::endl;
281 std::cout <<
"### callsign = "
282 << dbChan.
m_callSign.toLocal8Bit().constData() << std::endl;
283 std::cout <<
"### channum = "
284 << dbChan.
m_chanNum.toLocal8Bit().constData() << std::endl;
287 std::cout <<
"### freqid = "
288 << dbChan.
m_freqId.toLocal8Bit().constData() << std::endl;
290 std::cout <<
"### finetune = "
292 std::cout <<
"### tvformat = "
293 << dbChan.
m_tvFormat.toLocal8Bit().constData() << std::endl;
294 std::cout <<
"### icon = "
295 << dbChan.
m_icon.toLocal8Bit().constData() << std::endl;
296 std::cout <<
"### " << std::endl;
299 (*i).m_name = dbChan.
m_name;
308 if ((*i).m_callSign.isEmpty())
309 (*i).m_callSign = dbChan.
m_name;
311 if (dbChan.
m_name != (*i).m_name ||
316 dbChan.
m_icon != localfile ||
320 subquery.
prepare(
"UPDATE channel SET chanid = :CHANID, "
321 "name = :NAME, callsign = :CALLSIGN, "
322 "channum = :CHANNUM, finetune = :FINE, "
323 "icon = :ICON, freqid = :FREQID, "
324 "tvformat = :TVFORMAT "
325 " WHERE xmltvid = :XMLTVID "
326 "AND sourceid = :SOURCEID;");
328 subquery.
bindValue(
":NAME", (*i).m_name);
329 subquery.
bindValue(
":CALLSIGN", (*i).m_callSign);
330 subquery.
bindValue(
":CHANNUM", (*i).m_chanNum);
331 subquery.
bindValue(
":FINE", (*i).m_fineTune);
333 subquery.
bindValue(
":FREQID", (*i).m_freqId);
334 subquery.
bindValue(
":TVFORMAT", (*i).m_tvFormat);
335 subquery.
bindValue(
":XMLTVID", (*i).m_xmltvId);
338 if (!subquery.
exec())
344 std::cout <<
"### " << std::endl;
345 std::cout <<
"### Change performed" << std::endl;
346 std::cout <<
"### " << std::endl;
351 std::cout <<
"### " << std::endl;
352 std::cout <<
"### Nothing changed" << std::endl;
353 std::cout <<
"### " << std::endl;
356 else if ((dbChan.
m_icon != localfile) ||
359 LOG(VB_XMLTV, LOG_NOTICE, QString(
"Updating channel %1 (%2)")
362 if (localfile.isEmpty())
363 localfile = dbChan.
m_icon;
369 subquery.
prepare(
"UPDATE channel SET icon = :ICON "
370 ", xmltvid:= :XMLTVID WHERE "
371 "chanid = :CHANID;");
373 subquery.
bindValue(
":XMLTVID", (*i).m_xmltvId);
376 if (!subquery.
exec())
382 subquery.
prepare(
"UPDATE channel SET icon = :ICON WHERE "
383 "chanid = :CHANID;");
387 if (!subquery.
exec())
402 std::cout <<
"### " << std::endl;
403 std::cout <<
"### New channel found" << std::endl;
404 std::cout <<
"### " << std::endl;
405 std::cout <<
"### name = "
406 << (*i).m_name.toLocal8Bit().constData() << std::endl;
407 std::cout <<
"### callsign = "
408 << (*i).m_callSign.toLocal8Bit().constData() << std::endl;
409 std::cout <<
"### channum = "
410 << (*i).m_chanNum.toLocal8Bit().constData() << std::endl;
413 std::cout <<
"### freqid = "
414 << (*i).m_freqId.toLocal8Bit().constData() << std::endl;
416 std::cout <<
"### finetune = "
417 << (*i).m_fineTune << std::endl;
418 std::cout <<
"### tvformat = "
419 << (*i).m_tvFormat.toLocal8Bit().constData() << std::endl;
420 std::cout <<
"### icon = "
421 << localfile.toLocal8Bit().constData() << std::endl;
422 std::cout <<
"### " << std::endl;
426 if ((*i).m_callSign.isEmpty())
427 (*i).m_callSign = QString::number(chanid);
430 if ((chanid > 0) && (
minor > 0))
434 if (((mplexid > 0) || ((
minor == 0) && (chanid > 0))) &&
437 (*i).m_callSign, (*i).m_name, (*i).m_chanNum,
440 (*i).m_freqId, localfile, (*i).m_tvFormat,
443 std::cout <<
"### " << std::endl;
444 std::cout <<
"### Channel inserted" << std::endl;
445 std::cout <<
"### " << std::endl;
449 std::cout <<
"### " << std::endl;
450 std::cout <<
"### Channel skipped" << std::endl;
451 std::cout <<
"### " << std::endl;
463 id,
"atsc",
freq,
"8vsb");
466 if ((mplexid > 0) || (
minor == 0))
469 if ((*i).m_callSign.isEmpty())
471 QStringList words = (*i).m_name.simplified().toUpper()
473 QString callsign =
"";
474 QString w1 = !words.empty() ? words[0] : QString();
475 QString w2 = words.size() > 1 ? words[1] : QString();
477 callsign = QString::number(chanid);
478 else if (w2.isEmpty())
479 callsign = words[0].left(5);
482 callsign = w1.left(w2.length() == 1 ? 4:3);
483 callsign += w2.left(5 - callsign.length());
485 (*i).m_callSign = callsign;
490 QString cstr = (*i).m_chanNum;
492 cstr = QString::number(chanid % 1000);
509 std::cout <<
"Channel " << chanid <<
" creation failed"