39 #include "libmythbase/mythversion.h"
59 bool bGroupByCallsign,
64 uint nTotalAvailable = 0;
69 nSourceID, nChannelGroupID,
false,
"",
78 nStartIndex = (nStartIndex > 0) ? std::min( nStartIndex, nTotalAvailable ) : 0;
79 nCount = (nCount > 0) ? std::min(nCount, (nTotalAvailable - nStartIndex)) :
80 (nTotalAvailable - nStartIndex);
82 ChannelInfoList::iterator chanIt;
83 auto chanItBegin = chanList.begin() + nStartIndex;
84 auto chanItEnd = chanItBegin + nCount;
86 for( chanIt = chanItBegin; chanIt < chanItEnd; ++chanIt )
96 throw( QString(
"Channel ID appears invalid."));
105 nTotalPages = (int)std::ceil((
float)nTotalAvailable / nCount);
107 if (nTotalPages == 1)
111 nCurPage = (int)std::ceil((
float)nStartIndex / nCount) + 1;
114 pChannelInfos->setStartIndex ( nStartIndex );
115 pChannelInfos->setCount ( nCount );
116 pChannelInfos->setCurrentPage ( nCurPage );
117 pChannelInfos->setTotalPages ( nTotalPages );
118 pChannelInfos->setTotalAvailable( nTotalAvailable );
120 pChannelInfos->setVersion ( MYTH_BINARY_VERSION );
121 pChannelInfos->setProtoVer ( MYTH_PROTO_VERSION );
123 return pChannelInfos;
133 throw( QString(
"Channel ID appears invalid."));
150 const QString &CallSign,
151 const QString &ChannelName,
152 const QString &ChannelNumber,
154 uint ATSCMajorChannel,
155 uint ATSCMinorChannel,
158 [[maybe_unused]]
const QString &ExtendedVisible,
159 const QString &FrequencyID,
162 const QString &XMLTVID,
163 const QString &DefaultAuthority,
167 throw QString(
"ChannelId is required");
170 throw QString(
"Nothing to update");
174 throw QString(
"ChannelId %1 doesn't exist");
183 channel.
m_name = ChannelName;
197 #ifndef _WIN32 // TODO Does not compile on Windows
212 throw QString(
"Can't override Always/NeverVisible");
243 const QString &CallSign,
244 const QString &ChannelName,
245 const QString &ChannelNumber,
247 uint ATSCMajorChannel,
248 uint ATSCMinorChannel,
251 [[maybe_unused]]
const QString &ExtendedVisible,
252 const QString &FrequencyID,
255 const QString &XMLTVID,
256 const QString &DefaultAuthority,
261 #ifdef _WIN32 // TODO Needs fixing for Windows
272 CallSign, ChannelName, ChannelNumber,
273 ServiceID, ATSCMajorChannel, ATSCMinorChannel,
274 UseEIT, chan_visible, FrequencyID,
297 throw( QString(
"Database not open while trying to list "
300 query.
prepare(
"SELECT sourceid, name, xmltvgrabber, userid, "
301 "freqtable, lineupid, password, useeit, configpath, "
302 "dvb_nit_id, bouquet_id, region_id, scanfrequency, "
303 "lcnoffset FROM videosource "
304 "ORDER BY sourceid" );
310 throw( QString(
"Database Error executing query." ));
324 pVideoSource->setId ( query.
value(0).toInt() );
325 pVideoSource->setSourceName ( query.
value(1).toString() );
326 pVideoSource->setGrabber ( query.
value(2).toString() );
327 pVideoSource->setUserId ( query.
value(3).toString() );
328 pVideoSource->setFreqTable ( query.
value(4).toString() );
329 pVideoSource->setLineupId ( query.
value(5).toString() );
330 pVideoSource->setPassword ( query.
value(6).toString() );
331 pVideoSource->setUseEIT ( query.
value(7).toBool() );
332 pVideoSource->setConfigPath ( query.
value(8).toString() );
333 pVideoSource->setNITId ( query.
value(9).toInt() );
334 pVideoSource->setBouquetId ( query.
value(10).toUInt() );
335 pVideoSource->setRegionId ( query.
value(11).toUInt() );
336 pVideoSource->setScanFrequency ( query.
value(12).toUInt() );
337 pVideoSource->setLCNOffset ( query.
value(13).toUInt() );
341 pList->setVersion ( MYTH_BINARY_VERSION );
342 pList->setProtoVer ( MYTH_PROTO_VERSION );
356 throw( QString(
"Database not open while trying to list "
359 query.
prepare(
"SELECT name, xmltvgrabber, userid, "
360 "freqtable, lineupid, password, useeit, configpath, "
361 "dvb_nit_id, bouquet_id, region_id, scanfrequency, "
363 "FROM videosource WHERE sourceid = :SOURCEID "
364 "ORDER BY sourceid" );
371 throw( QString(
"Database Error executing query." ));
382 pVideoSource->setId ( nSourceID );
383 pVideoSource->setSourceName ( query.
value(0).toString() );
384 pVideoSource->setGrabber ( query.
value(1).toString() );
385 pVideoSource->setUserId ( query.
value(2).toString() );
386 pVideoSource->setFreqTable ( query.
value(3).toString() );
387 pVideoSource->setLineupId ( query.
value(4).toString() );
388 pVideoSource->setPassword ( query.
value(5).toString() );
389 pVideoSource->setUseEIT ( query.
value(6).toBool() );
390 pVideoSource->setConfigPath ( query.
value(7).toString() );
391 pVideoSource->setNITId ( query.
value(8).toInt() );
392 pVideoSource->setBouquetId ( query.
value(9).toUInt() );
393 pVideoSource->setRegionId ( query.
value(10).toUInt() );
394 pVideoSource->setScanFrequency ( query.
value(11).toUInt() );
395 pVideoSource->setLCNOffset ( query.
value(12).toUInt() );
406 const QString &sSourceName,
407 const QString &sGrabber,
408 const QString &sUserId,
409 const QString &sFreqTable,
410 const QString &sLineupId,
411 const QString &sPassword,
413 const QString &sConfigPath,
423 LOG(VB_GENERAL, LOG_ERR,
"SourceId is required");
429 LOG(VB_GENERAL, LOG_ERR, QString(
"SourceId %1 doesn't exist")
436 LOG(VB_GENERAL, LOG_ERR, QString(
"SourceId=%1 was the only parameter")
442 MSqlBindings::const_iterator it;
446 ADD_SQL(settings, bindings,
"name",
"SourceName", sSourceName);
449 ADD_SQL(settings, bindings,
"xmltvgrabber",
"Grabber", sGrabber);
452 ADD_SQL(settings, bindings,
"userid",
"UserId", sUserId);
455 ADD_SQL(settings, bindings,
"freqtable",
"FreqTable", sFreqTable);
458 ADD_SQL(settings, bindings,
"lineupid",
"LineupId", sLineupId);
461 ADD_SQL(settings, bindings,
"password",
"Password", sPassword);
464 ADD_SQL(settings, bindings,
"useeit",
"UseEIT", bUseEIT);
468 if (sConfigPath.isEmpty())
469 settings +=
"configpath=NULL, ";
471 ADD_SQL(settings, bindings,
"configpath",
"ConfigPath", sConfigPath);
475 ADD_SQL(settings, bindings,
"dvb_nit_id",
"NITId", nNITId);
478 ADD_SQL(settings, bindings,
"bouquet_id",
"BouquetId", nBouquetId);
481 ADD_SQL(settings, bindings,
"region_id",
"RegionId", nRegionId);
484 ADD_SQL(settings, bindings,
"scanfrequency",
"ScanFrequency", nScanFrequency);
487 ADD_SQL(settings, bindings,
"lcnoffset",
"LCNOffset", nLCNOffset);
489 if ( settings.isEmpty() )
491 LOG(VB_GENERAL, LOG_ERR,
"No valid parameters were passed");
499 query.
prepare(QString(
"UPDATE videosource SET %1 WHERE sourceid=:SOURCEID")
501 bindings[
":SOURCEID"] = nSourceId;
503 for (it = bindings.cbegin(); it != bindings.cend(); ++it)
510 throw( QString(
"Database Error executing query." ));
521 const QString &sGrabber,
522 const QString &sUserId,
523 const QString &sFreqTable,
524 const QString &sLineupId,
525 const QString &sPassword,
527 const QString &sConfigPath,
535 sLineupId, sPassword, bUseEIT, sConfigPath,
536 nNITId, nBouquetId, nRegionId, nScanFrequency,
571 bool bWaitForFinish )
573 if ( nSourceId < 1 || nCardId < 1)
574 throw( QString(
"A source ID and card ID are both required."));
583 throw( QString(
"This device is incompatible with channel fetching.") );
605 throw( QString(
"Database not open while trying to list "
608 query.
prepare(
"SELECT mplexid, sourceid, transportid, networkid, "
609 "frequency, inversion, symbolrate, fec, polarity, "
610 "modulation, bandwidth, lp_code_rate, transmission_mode, "
611 "guard_interval, visible, constellation, hierarchy, hp_code_rate, "
612 "mod_sys, rolloff, sistandard, serviceversion, updatetimestamp, "
613 "default_authority FROM dtv_multiplex WHERE sourceid = :SOURCEID "
614 "ORDER BY mplexid" );
621 throw( QString(
"Database Error executing query." ));
632 nStartIndex = (nStartIndex > 0) ? std::min( nStartIndex, muxCount ) : 0;
633 nCount = (nCount > 0) ? std::min( nCount, muxCount ) : muxCount;
634 int nEndIndex = std::min((nStartIndex + nCount), muxCount );
636 for(
int n = nStartIndex; n < nEndIndex; n++)
642 pVideoMultiplex->setMplexId( query.
value(0).toInt() );
643 pVideoMultiplex->setSourceId( query.
value(1).toInt() );
644 pVideoMultiplex->setTransportId( query.
value(2).toInt() );
645 pVideoMultiplex->setNetworkId( query.
value(3).toInt() );
646 pVideoMultiplex->setFrequency( query.
value(4).toLongLong() );
647 pVideoMultiplex->setInversion( query.
value(5).toString() );
648 pVideoMultiplex->setSymbolRate( query.
value(6).toLongLong() );
649 pVideoMultiplex->setFEC( query.
value(7).toString() );
650 pVideoMultiplex->setPolarity( query.
value(8).toString() );
651 pVideoMultiplex->setModulation( query.
value(9).toString() );
652 pVideoMultiplex->setBandwidth( query.
value(10).toString() );
653 pVideoMultiplex->setLPCodeRate( query.
value(11).toString() );
654 pVideoMultiplex->setTransmissionMode( query.
value(12).toString() );
655 pVideoMultiplex->setGuardInterval( query.
value(13).toString() );
656 pVideoMultiplex->setVisible( query.
value(14).toBool() );
657 pVideoMultiplex->setConstellation( query.
value(15).toString() );
658 pVideoMultiplex->setHierarchy( query.
value(16).toString() );
659 pVideoMultiplex->setHPCodeRate( query.
value(17).toString() );
660 pVideoMultiplex->setModulationSystem( query.
value(18).toString() );
661 pVideoMultiplex->setRollOff( query.
value(19).toString() );
662 pVideoMultiplex->setSIStandard( query.
value(20).toString() );
663 pVideoMultiplex->setServiceVersion( query.
value(21).toInt() );
664 pVideoMultiplex->setUpdateTimeStamp(
666 pVideoMultiplex->setDefaultAuthority( query.
value(23).toString() );
675 totalPages = (int)std::ceil((
float)muxCount / nCount);
681 curPage = (int)std::ceil((
float)nStartIndex / nCount) + 1;
684 pVideoMultiplexes->setStartIndex ( nStartIndex );
685 pVideoMultiplexes->setCount ( nCount );
686 pVideoMultiplexes->setCurrentPage ( curPage );
687 pVideoMultiplexes->setTotalPages ( totalPages );
688 pVideoMultiplexes->setTotalAvailable( muxCount );
690 pVideoMultiplexes->setVersion ( MYTH_BINARY_VERSION );
691 pVideoMultiplexes->setProtoVer ( MYTH_PROTO_VERSION );
693 return pVideoMultiplexes;
701 throw( QString(
"Database not open while trying to list "
702 "Video Multiplex."));
704 query.
prepare(
"SELECT sourceid, transportid, networkid, "
705 "frequency, inversion, symbolrate, fec, polarity, "
706 "modulation, bandwidth, lp_code_rate, transmission_mode, "
707 "guard_interval, visible, constellation, hierarchy, hp_code_rate, "
708 "mod_sys, rolloff, sistandard, serviceversion, updatetimestamp, "
709 "default_authority FROM dtv_multiplex WHERE mplexid = :MPLEXID "
710 "ORDER BY mplexid" );
717 throw( QString(
"Database Error executing query." ));
724 pVideoMultiplex->setMplexId( nMplexID );
725 pVideoMultiplex->setSourceId( query.
value(0).toInt() );
726 pVideoMultiplex->setTransportId( query.
value(1).toInt() );
727 pVideoMultiplex->setNetworkId( query.
value(2).toInt() );
728 pVideoMultiplex->setFrequency( query.
value(3).toLongLong() );
729 pVideoMultiplex->setInversion( query.
value(4).toString() );
730 pVideoMultiplex->setSymbolRate( query.
value(5).toLongLong() );
731 pVideoMultiplex->setFEC( query.
value(6).toString() );
732 pVideoMultiplex->setPolarity( query.
value(7).toString() );
733 pVideoMultiplex->setModulation( query.
value(8).toString() );
734 pVideoMultiplex->setBandwidth( query.
value(9).toString() );
735 pVideoMultiplex->setLPCodeRate( query.
value(10).toString() );
736 pVideoMultiplex->setTransmissionMode( query.
value(11).toString() );
737 pVideoMultiplex->setGuardInterval( query.
value(12).toString() );
738 pVideoMultiplex->setVisible( query.
value(13).toBool() );
739 pVideoMultiplex->setConstellation( query.
value(14).toString() );
740 pVideoMultiplex->setHierarchy( query.
value(15).toString() );
741 pVideoMultiplex->setHPCodeRate( query.
value(16).toString() );
742 pVideoMultiplex->setModulationSystem( query.
value(17).toString() );
743 pVideoMultiplex->setRollOff( query.
value(18).toString() );
744 pVideoMultiplex->setSIStandard( query.
value(19).toString() );
745 pVideoMultiplex->setServiceVersion( query.
value(20).toInt() );
746 pVideoMultiplex->setUpdateTimeStamp(
748 pVideoMultiplex->setDefaultAuthority( query.
value(22).toString() );
751 return pVideoMultiplex;
763 throw( QString(
"Database not open while trying to get source name."));
765 query.
prepare(
"SELECT name FROM videosource WHERE sourceid = :SOURCEID ");
772 throw( QString(
"Database Error executing query." ));
779 QString sourceName = query.
value(0).toString();
781 QString xmltvFile =
GetConfDir() +
'/' + sourceName +
".xmltv";
785 QFile
file(xmltvFile);
786 if (!
file.open(QIODevice::ReadOnly | QIODevice::Text))
789 while (!
file.atEnd())
791 QByteArray line =
file.readLine();
793 if (line.startsWith(
"channel="))
795 QString
id = line.mid(8, -1).trimmed();
805 throw(QString(
"SourceID (%1) not found").arg(
SourceID));