8 #include <QRegularExpression>
24 #if QT_VERSION < QT_VERSION_CHECK(5,15,2)
25 #define capturedView capturedRef
37 if (!match.hasMatch())
40 major = match.capturedView(1).toInt();
41 minor = match.capturedView(2).toInt();
50 "WHERE sourceid = :SOURCEID");
54 query.
value(0).toString() ==
"HDTV")
65 bool isEncoder =
false;
66 bool isUnscanable =
false;
78 insert_channels = (isCableCard || isEncoder || isUnscanable);
81 return insert_channels;
86 ChannelInfoList::iterator chaninfo,
unsigned int chanid)
const
88 (*chaninfo).m_name =
getResponse(QObject::tr(
"Choose a channel name (any string, "
89 "long version) "),(*chaninfo).m_name);
90 (*chaninfo).m_callSign =
getResponse(QObject::tr(
"Choose a channel callsign (any string, "
91 "short version) "),(*chaninfo).m_callSign);
95 (*chaninfo).m_chanNum =
getResponse(QObject::tr(
"Choose a channel preset (0..999) "),
96 (*chaninfo).m_chanNum);
97 (*chaninfo).m_freqId =
getResponse(QObject::tr(
"Choose a frequency id "),
98 (*chaninfo).m_freqId);
102 (*chaninfo).m_chanNum =
getResponse(QObject::tr(
"Choose a channel number "),
103 (*chaninfo).m_chanNum);
104 (*chaninfo).m_freqId = (*chaninfo).m_chanNum;
107 (*chaninfo).m_fineTune =
getResponse(QObject::tr(
"Choose a channel fine tune offset "),
108 QString::number((*chaninfo).m_fineTune)).toInt();
110 (*chaninfo).m_tvFormat =
getResponse(QObject::tr(
"Choose a TV format "
111 "(PAL/SECAM/NTSC/ATSC/Default) "),
112 (*chaninfo).m_tvFormat);
114 (*chaninfo).m_icon =
getResponse(QObject::tr(
"Choose a channel icon image "
115 "(relative path to icon storage group) "),
123 QString result = chanName;
126 result = result.toLower();
128 result = result.replace(
" ",
"");
147 QString chanName = channel.m_name;
149 retList.insert(key, channel);
158 ChannelList::iterator it;
159 for (it = existingChannels.begin(); it != existingChannels.end(); ++it)
161 if ((*it).m_xmltvId == chanInfo.
m_xmltvId)
166 ChannelInfo existChan = existingChannels.value(searchKey);
172 if (match.hasMatch())
175 uint major = match.capturedView(1).toUInt();
176 uint minor = match.capturedView(2).toUInt();
178 for (it = existingChannels.begin();
179 it != existingChannels.end(); ++it)
181 if ((*it).m_atscMajorChan == major &&
182 (*it).m_atscMinorChan ==
minor)
195 LOG(VB_GENERAL, LOG_NOTICE,
"Skipping Channel Updates");
202 QDir::setCurrent(fileprefix);
208 auto i = chanlist->begin();
209 for (; i != chanlist->end(); ++i)
211 if ((*i).m_xmltvId.isEmpty())
216 if (!(*i).m_icon.isEmpty())
218 QDir remotefile = QDir((*i).m_icon);
219 QString
filename = remotefile.dirName();
222 QFile actualfile(localfile);
223 if (!actualfile.exists() &&
226 LOG(VB_GENERAL, LOG_ERR,
227 QString(
"Failed to fetch icon from '%1'")
236 if (!(*i).m_oldXmltvId.isEmpty())
241 "WHERE xmltvid = :XMLTVID");
242 query.
bindValue(
":XMLTVID", (*i).m_oldXmltvId);
248 else if (query.
next())
250 LOG(VB_GENERAL, LOG_INFO,
251 QString(
"Converting old xmltvid (%1) to new (%2)")
252 .arg((*i).m_oldXmltvId, (*i).m_xmltvId));
254 query.
prepare(
"UPDATE channel "
255 "SET xmltvid = :NEWXMLTVID"
256 "WHERE xmltvid = :OLDXMLTVID");
257 query.
bindValue(
":NEWXMLTVID", (*i).m_xmltvId);
258 query.
bindValue(
":OLDXMLTVID", (*i).m_oldXmltvId);
270 LOG(VB_XMLTV, LOG_DEBUG,
271 QString(
"Match found for xmltvid %1 to channel %2 (%3)")
272 .arg((*i).m_xmltvId, dbChan.
m_name, QString::number(dbChan.
m_chanId)));
276 std::cout <<
"### " << std::endl;
277 std::cout <<
"### Existing channel found" << std::endl;
278 std::cout <<
"### " << std::endl;
279 std::cout <<
"### xmltvid = "
280 << (*i).m_xmltvId.toLocal8Bit().constData() << std::endl;
281 std::cout <<
"### chanid = "
283 std::cout <<
"### name = "
284 << dbChan.
m_name.toLocal8Bit().constData() << std::endl;
285 std::cout <<
"### callsign = "
286 << dbChan.
m_callSign.toLocal8Bit().constData() << std::endl;
287 std::cout <<
"### channum = "
288 << dbChan.
m_chanNum.toLocal8Bit().constData() << std::endl;
291 std::cout <<
"### freqid = "
292 << dbChan.
m_freqId.toLocal8Bit().constData() << std::endl;
294 std::cout <<
"### finetune = "
296 std::cout <<
"### tvformat = "
297 << dbChan.
m_tvFormat.toLocal8Bit().constData() << std::endl;
298 std::cout <<
"### icon = "
299 << dbChan.
m_icon.toLocal8Bit().constData() << std::endl;
300 std::cout <<
"### " << std::endl;
303 (*i).m_name = dbChan.
m_name;
312 if ((*i).m_callSign.isEmpty())
313 (*i).m_callSign = dbChan.
m_name;
315 if (dbChan.
m_name != (*i).m_name ||
320 dbChan.
m_icon != localfile ||
324 subquery.
prepare(
"UPDATE channel SET chanid = :CHANID, "
325 "name = :NAME, callsign = :CALLSIGN, "
326 "channum = :CHANNUM, finetune = :FINE, "
327 "icon = :ICON, freqid = :FREQID, "
328 "tvformat = :TVFORMAT "
329 " WHERE xmltvid = :XMLTVID "
330 "AND sourceid = :SOURCEID;");
332 subquery.
bindValue(
":NAME", (*i).m_name);
333 subquery.
bindValue(
":CALLSIGN", (*i).m_callSign);
334 subquery.
bindValue(
":CHANNUM", (*i).m_chanNum);
335 subquery.
bindValue(
":FINE", (*i).m_fineTune);
337 subquery.
bindValue(
":FREQID", (*i).m_freqId);
338 subquery.
bindValue(
":TVFORMAT", (*i).m_tvFormat);
339 subquery.
bindValue(
":XMLTVID", (*i).m_xmltvId);
342 if (!subquery.
exec())
348 std::cout <<
"### " << std::endl;
349 std::cout <<
"### Change performed" << std::endl;
350 std::cout <<
"### " << std::endl;
355 std::cout <<
"### " << std::endl;
356 std::cout <<
"### Nothing changed" << std::endl;
357 std::cout <<
"### " << std::endl;
360 else if ((dbChan.
m_icon != localfile) ||
363 LOG(VB_XMLTV, LOG_NOTICE, QString(
"Updating channel %1 (%2)")
366 if (localfile.isEmpty())
367 localfile = dbChan.
m_icon;
373 subquery.
prepare(
"UPDATE channel SET icon = :ICON "
374 ", xmltvid:= :XMLTVID WHERE "
375 "chanid = :CHANID;");
377 subquery.
bindValue(
":XMLTVID", (*i).m_xmltvId);
380 if (!subquery.
exec())
386 subquery.
prepare(
"UPDATE channel SET icon = :ICON WHERE "
387 "chanid = :CHANID;");
391 if (!subquery.
exec())
406 std::cout <<
"### " << std::endl;
407 std::cout <<
"### New channel found" << std::endl;
408 std::cout <<
"### " << std::endl;
409 std::cout <<
"### name = "
410 << (*i).m_name.toLocal8Bit().constData() << std::endl;
411 std::cout <<
"### callsign = "
412 << (*i).m_callSign.toLocal8Bit().constData() << std::endl;
413 std::cout <<
"### channum = "
414 << (*i).m_chanNum.toLocal8Bit().constData() << std::endl;
417 std::cout <<
"### freqid = "
418 << (*i).m_freqId.toLocal8Bit().constData() << std::endl;
420 std::cout <<
"### finetune = "
421 << (*i).m_fineTune << std::endl;
422 std::cout <<
"### tvformat = "
423 << (*i).m_tvFormat.toLocal8Bit().constData() << std::endl;
424 std::cout <<
"### icon = "
425 << localfile.toLocal8Bit().constData() << std::endl;
426 std::cout <<
"### " << std::endl;
430 if ((*i).m_callSign.isEmpty())
431 (*i).m_callSign = QString::number(chanid);
434 if ((chanid > 0) && (
minor > 0))
438 if (((mplexid > 0) || ((
minor == 0) && (chanid > 0))) &&
441 (*i).m_callSign, (*i).m_name, (*i).m_chanNum,
444 (*i).m_freqId, localfile, (*i).m_tvFormat,
447 std::cout <<
"### " << std::endl;
448 std::cout <<
"### Channel inserted" << std::endl;
449 std::cout <<
"### " << std::endl;
453 std::cout <<
"### " << std::endl;
454 std::cout <<
"### Channel skipped" << std::endl;
455 std::cout <<
"### " << std::endl;
467 id,
"atsc",
freq,
"8vsb");
470 if ((mplexid > 0) || (
minor == 0))
473 if ((*i).m_callSign.isEmpty())
475 QStringList words = (*i).m_name.simplified().toUpper()
477 QString callsign =
"";
478 QString w1 = !words.empty() ? words[0] : QString();
479 QString w2 = words.size() > 1 ? words[1] : QString();
481 callsign = QString::number(chanid);
482 else if (w2.isEmpty())
483 callsign = words[0].left(5);
486 callsign = w1.left(w2.length() == 1 ? 4:3);
487 callsign += w2.left(5 - callsign.length());
489 (*i).m_callSign = callsign;
494 QString cstr = (*i).m_chanNum;
496 cstr = QString::number(chanid % 1000);
513 std::cout <<
"Channel " << chanid <<
" creation failed"