33 #include <QTemporaryFile>
40 #include "libmythbase/mythversion.h"
76 qRegisterMetaType<V2ChannelInfoList*>(
"V2ChannelInfoList");
77 qRegisterMetaType<V2ChannelInfo*>(
"V2ChannelInfo");
78 qRegisterMetaType<V2VideoSourceList*>(
"V2VideoSourceList");
79 qRegisterMetaType<V2VideoSource*>(
"V2VideoSource");
80 qRegisterMetaType<V2LineupList*>(
"V2LineupList");
81 qRegisterMetaType<V2Lineup*>(
"V2Lineup");
82 qRegisterMetaType<V2VideoMultiplexList*>(
"V2VideoMultiplexList");
83 qRegisterMetaType<V2VideoMultiplex*>(
"V2VideoMultiplex");
84 qRegisterMetaType<V2Program*>(
"V2Program");
85 qRegisterMetaType<V2RecordingInfo*>(
"V2RecordingInfo");
86 qRegisterMetaType<V2ArtworkInfoList*>(
"V2ArtworkInfoList");
87 qRegisterMetaType<V2ArtworkInfo*>(
"V2ArtworkInfo");
88 qRegisterMetaType<V2CastMemberList*>(
"V2CastMemberList");
89 qRegisterMetaType<V2CastMember*>(
"V2CastMember");
90 qRegisterMetaType<V2Grabber*>(
"V2Grabber");
91 qRegisterMetaType<V2GrabberList*>(
"V2GrabberList");
92 qRegisterMetaType<V2FreqTableList*>(
"V2FreqTableList");
93 qRegisterMetaType<V2CommMethodList*>(
"V2CommMethodList");
94 qRegisterMetaType<V2CommMethod*>(
"V2CommMethod");
95 qRegisterMetaType<V2ScanStatus*>(
"V2ScanStatus");
96 qRegisterMetaType<V2Scan*>(
"V2Scan");
97 qRegisterMetaType<V2ScanList*>(
"V2ScanList");
98 qRegisterMetaType<V2ChannelRestore*>(
"V2ChannelRestore");
108 uint nChannelGroupID,
114 bool bGroupByCallsign,
119 uint nTotalAvailable = 0;
124 nSourceID, nChannelGroupID,
false,
"",
133 nStartIndex = (nStartIndex > 0) ? std::min( nStartIndex, nTotalAvailable ) : 0;
134 nCount = (nCount > 0) ? std::min(nCount, (nTotalAvailable - nStartIndex)) :
135 (nTotalAvailable - nStartIndex);
137 ChannelInfoList::iterator chanIt;
138 auto chanItBegin = chanList.begin() + nStartIndex;
139 auto chanItEnd = chanItBegin + nCount;
141 for( chanIt = chanItBegin; chanIt < chanItEnd; ++chanIt )
143 V2ChannelInfo *pChannelInfo = pChannelInfos->AddNewChannelInfo();
150 delete pChannelInfos;
151 throw( QString(
"V2Channel ID appears invalid."));
160 nTotalPages = (int)std::ceil((
float)nTotalAvailable / nCount);
162 if (nTotalPages == 1)
166 nCurPage = (int)std::ceil((
float)nStartIndex / nCount) + 1;
169 pChannelInfos->setStartIndex ( nStartIndex );
170 pChannelInfos->setCount ( nCount );
171 pChannelInfos->setCurrentPage ( nCurPage );
172 pChannelInfos->setTotalPages ( nTotalPages );
173 pChannelInfos->setTotalAvailable( nTotalAvailable );
175 pChannelInfos->setVersion ( MYTH_BINARY_VERSION );
176 pChannelInfos->setProtoVer ( MYTH_PROTO_VERSION );
178 return pChannelInfos;
188 throw( QString(
"V2Channel ID appears invalid."));
205 const QString &CallSign,
206 const QString &ChannelName,
207 const QString &ChannelNumber,
209 uint ATSCMajorChannel,
210 uint ATSCMinorChannel,
213 const QString &ExtendedVisible,
214 const QString &FrequencyID,
217 const QString &XMLTVID,
218 const QString &DefaultAuthority,
225 throw QString(
"ChannelId is required");
228 throw QString(
"Nothing to update");
232 throw QString(
"ChannelId %1 doesn't exist");
241 channel.
m_name = ChannelName;
265 throw QString(
"Can't override Always/NeverVisible");
298 QDateTime(),
"UpdateDBChannel");
307 query.
prepare(
"SELECT MAX(chanid) FROM channel");
311 throw( QString(
"Database Error executing query." ));
314 chanId = query.
value(0).toUInt() + 1;
315 chanId = std::max<uint>(chanId, 1000);
322 const QString &CallSign,
323 const QString &ChannelName,
324 const QString &ChannelNumber,
326 uint ATSCMajorChannel,
327 uint ATSCMinorChannel,
330 const QString &ExtendedVisible,
331 const QString &FrequencyID,
334 const QString &XMLTVID,
335 const QString &DefaultAuthority,
348 CallSign, ChannelName, ChannelNumber,
349 ServiceID, ATSCMajorChannel, ATSCMinorChannel,
350 UseEIT, chan_visible, FrequencyID,
376 pCommMethod->setCommMethod(pref);
392 throw( QString(
"Database not open while trying to list "
395 query.
prepare(
"SELECT sourceid, name, xmltvgrabber, userid, "
396 "freqtable, lineupid, password, useeit, configpath, "
397 "dvb_nit_id, bouquet_id, region_id, scanfrequency, "
398 "lcnoffset FROM videosource "
399 "ORDER BY sourceid" );
405 throw( QString(
"Database Error executing query." ));
419 pVideoSource->setId ( query.
value(0).toInt() );
420 pVideoSource->setSourceName ( query.
value(1).toString() );
421 pVideoSource->setGrabber ( query.
value(2).toString() );
422 pVideoSource->setUserId ( query.
value(3).toString() );
423 pVideoSource->setFreqTable ( query.
value(4).toString() );
424 pVideoSource->setLineupId ( query.
value(5).toString() );
425 pVideoSource->setPassword ( query.
value(6).toString() );
426 pVideoSource->setUseEIT ( query.
value(7).toBool() );
427 pVideoSource->setConfigPath ( query.
value(8).toString() );
428 pVideoSource->setNITId ( query.
value(9).toInt() );
429 pVideoSource->setBouquetId ( query.
value(10).toUInt() );
430 pVideoSource->setRegionId ( query.
value(11).toUInt() );
431 pVideoSource->setScanFrequency ( query.
value(12).toUInt() );
432 pVideoSource->setLCNOffset ( query.
value(13).toUInt() );
436 pList->setVersion ( MYTH_BINARY_VERSION );
437 pList->setProtoVer ( MYTH_PROTO_VERSION );
451 throw( QString(
"Database not open while trying to list "
454 query.
prepare(
"SELECT name, xmltvgrabber, userid, "
455 "freqtable, lineupid, password, useeit, configpath, "
456 "dvb_nit_id, bouquet_id, region_id, scanfrequency, "
458 "FROM videosource WHERE sourceid = :SOURCEID "
459 "ORDER BY sourceid" );
466 throw( QString(
"Database Error executing query." ));
477 pVideoSource->setId ( nSourceID );
478 pVideoSource->setSourceName ( query.
value(0).toString() );
479 pVideoSource->setGrabber ( query.
value(1).toString() );
480 pVideoSource->setUserId ( query.
value(2).toString() );
481 pVideoSource->setFreqTable ( query.
value(3).toString() );
482 pVideoSource->setLineupId ( query.
value(4).toString() );
483 pVideoSource->setPassword ( query.
value(5).toString() );
484 pVideoSource->setUseEIT ( query.
value(6).toBool() );
485 pVideoSource->setConfigPath ( query.
value(7).toString() );
486 pVideoSource->setNITId ( query.
value(8).toInt() );
487 pVideoSource->setBouquetId ( query.
value(9).toUInt() );
488 pVideoSource->setRegionId ( query.
value(10).toUInt() );
489 pVideoSource->setScanFrequency ( query.
value(11).toUInt() );
490 pVideoSource->setLCNOffset ( query.
value(12).toUInt() );
501 const QString &sSourceName,
502 const QString &sGrabber,
503 const QString &sUserId,
504 const QString &sFreqTable,
505 const QString &sLineupId,
506 const QString &sPassword,
508 const QString &sConfigPath,
518 LOG(VB_GENERAL, LOG_ERR,
"SourceId is required");
524 LOG(VB_GENERAL, LOG_ERR, QString(
"SourceId %1 doesn't exist")
531 LOG(VB_GENERAL, LOG_ERR, QString(
"SourceId=%1 was the only parameter")
537 MSqlBindings::const_iterator it;
541 ADD_SQLv2(settings, bindings,
"name",
"SourceName", sSourceName);
544 ADD_SQLv2(settings, bindings,
"xmltvgrabber",
"Grabber", sGrabber);
547 ADD_SQLv2(settings, bindings,
"userid",
"UserId", sUserId);
550 ADD_SQLv2(settings, bindings,
"freqtable",
"FreqTable", sFreqTable);
553 ADD_SQLv2(settings, bindings,
"lineupid",
"LineupId", sLineupId);
556 ADD_SQLv2(settings, bindings,
"password",
"Password", sPassword);
559 ADD_SQLv2(settings, bindings,
"useeit",
"UseEIT", bUseEIT);
563 if (sConfigPath.isEmpty())
564 settings +=
"configpath=NULL, ";
566 ADD_SQLv2(settings, bindings,
"configpath",
"ConfigPath", sConfigPath);
570 ADD_SQLv2(settings, bindings,
"dvb_nit_id",
"NITId", nNITId);
573 ADD_SQLv2(settings, bindings,
"bouquet_id",
"BouquetId", nBouquetId);
576 ADD_SQLv2(settings, bindings,
"region_id",
"RegionId", nRegionId);
579 ADD_SQLv2(settings, bindings,
"scanfrequency",
"ScanFrequency", nScanFrequency);
582 ADD_SQLv2(settings, bindings,
"lcnoffset",
"LCNOffset", nLCNOffset);
584 if ( settings.isEmpty() )
586 LOG(VB_GENERAL, LOG_ERR,
"No valid parameters were passed");
594 query.
prepare(QString(
"UPDATE videosource SET %1 WHERE sourceid=:SOURCEID")
596 bindings[
":SOURCEID"] = nSourceId;
598 for (it = bindings.cbegin(); it != bindings.cend(); ++it)
605 throw( QString(
"Database Error executing query." ));
616 const QString &sGrabber,
617 const QString &sUserId,
618 const QString &sFreqTable,
619 const QString &sLineupId,
620 const QString &sPassword,
622 const QString &sConfigPath,
630 sLineupId, sPassword, bUseEIT, sConfigPath,
631 nNITId, nBouquetId, nRegionId, nScanFrequency,
673 bool bWaitForFinish )
675 if ( nSourceId < 1 || nCardId < 1)
676 throw( QString(
"A source ID and card ID are both required."));
709 throw( QString(
"Database not open while trying to list "
713 where =
"WHERE sourceid = :SOURCEID";
714 QString sql = QString(
"SELECT mplexid, sourceid, transportid, networkid, "
715 "frequency, inversion, symbolrate, fec, polarity, "
716 "modulation, bandwidth, lp_code_rate, transmission_mode, "
717 "guard_interval, visible, constellation, hierarchy, hp_code_rate, "
718 "mod_sys, rolloff, sistandard, serviceversion, updatetimestamp, "
719 "default_authority FROM dtv_multiplex %1 "
720 "ORDER BY mplexid").arg(where);
730 throw( QString(
"Database Error executing query." ));
741 nStartIndex = (nStartIndex > 0) ? std::min( nStartIndex, muxCount ) : 0;
742 nCount = (nCount > 0) ? std::min( nCount, muxCount ) : muxCount;
743 int nEndIndex = std::min((nStartIndex + nCount), muxCount );
745 for(
int n = nStartIndex; n < nEndIndex; n++)
749 V2VideoMultiplex *pVideoMultiplex = pVideoMultiplexes->AddNewVideoMultiplex();
751 pVideoMultiplex->setMplexId( query.
value(0).toInt() );
752 pVideoMultiplex->setSourceId( query.
value(1).toInt() );
753 pVideoMultiplex->setTransportId( query.
value(2).toInt() );
754 pVideoMultiplex->setNetworkId( query.
value(3).toInt() );
755 pVideoMultiplex->setFrequency( query.
value(4).toLongLong() );
756 pVideoMultiplex->setInversion( query.
value(5).toString() );
757 pVideoMultiplex->setSymbolRate( query.
value(6).toLongLong() );
758 pVideoMultiplex->setFEC( query.
value(7).toString() );
759 pVideoMultiplex->setPolarity( query.
value(8).toString() );
760 pVideoMultiplex->setModulation( query.
value(9).toString() );
761 pVideoMultiplex->setBandwidth( query.
value(10).toString() );
762 pVideoMultiplex->setLPCodeRate( query.
value(11).toString() );
763 pVideoMultiplex->setTransmissionMode( query.
value(12).toString() );
764 pVideoMultiplex->setGuardInterval( query.
value(13).toString() );
765 pVideoMultiplex->setVisible( query.
value(14).toBool() );
766 pVideoMultiplex->setConstellation( query.
value(15).toString() );
767 pVideoMultiplex->setHierarchy( query.
value(16).toString() );
768 pVideoMultiplex->setHPCodeRate( query.
value(17).toString() );
769 pVideoMultiplex->setModulationSystem( query.
value(18).toString() );
770 pVideoMultiplex->setRollOff( query.
value(19).toString() );
771 pVideoMultiplex->setSIStandard( query.
value(20).toString() );
772 pVideoMultiplex->setServiceVersion( query.
value(21).toInt() );
773 pVideoMultiplex->setUpdateTimeStamp(
775 pVideoMultiplex->setDefaultAuthority( query.
value(23).toString() );
779 if (query.
value(9).toString() ==
"8vsb")
781 QString ChannelNumber =
783 QString(
"Freq %1").arg(query.
value(4).toInt());
784 int findFrequency = (query.
value(4).toInt() / 1000) - 1750;
787 if ((list.freq <= findFrequency + 200) &&
788 (list.freq >= findFrequency - 200))
790 ChannelNumber = QString(
"%1").arg(list.name);
794 DisplayText = tr(
"ATSC Channel %1").arg(ChannelNumber);
798 DisplayText = QString(
"%1 Hz (%2) (%3) (%4)")
799 .arg(query.
value(4).toString(),
800 query.
value(6).toString(),
801 query.
value(3).toString(),
802 query.
value(2).toString());
804 pVideoMultiplex->setDescription(DisplayText);
813 totalPages = (int)std::ceil((
float)muxCount / nCount);
819 curPage = (int)std::ceil((
float)nStartIndex / nCount) + 1;
822 pVideoMultiplexes->setStartIndex ( nStartIndex );
823 pVideoMultiplexes->setCount ( nCount );
824 pVideoMultiplexes->setCurrentPage ( curPage );
825 pVideoMultiplexes->setTotalPages ( totalPages );
826 pVideoMultiplexes->setTotalAvailable( muxCount );
828 pVideoMultiplexes->setVersion ( MYTH_BINARY_VERSION );
829 pVideoMultiplexes->setProtoVer ( MYTH_PROTO_VERSION );
831 return pVideoMultiplexes;
839 throw( QString(
"Database not open while trying to list "
840 "Video Multiplex."));
842 query.
prepare(
"SELECT sourceid, transportid, networkid, "
843 "frequency, inversion, symbolrate, fec, polarity, "
844 "modulation, bandwidth, lp_code_rate, transmission_mode, "
845 "guard_interval, visible, constellation, hierarchy, hp_code_rate, "
846 "mod_sys, rolloff, sistandard, serviceversion, updatetimestamp, "
847 "default_authority FROM dtv_multiplex WHERE mplexid = :MPLEXID "
848 "ORDER BY mplexid" );
855 throw( QString(
"Database Error executing query." ));
862 pVideoMultiplex->setMplexId( nMplexID );
863 pVideoMultiplex->setSourceId( query.
value(0).toInt() );
864 pVideoMultiplex->setTransportId( query.
value(1).toInt() );
865 pVideoMultiplex->setNetworkId( query.
value(2).toInt() );
866 pVideoMultiplex->setFrequency( query.
value(3).toLongLong() );
867 pVideoMultiplex->setInversion( query.
value(4).toString() );
868 pVideoMultiplex->setSymbolRate( query.
value(5).toLongLong() );
869 pVideoMultiplex->setFEC( query.
value(6).toString() );
870 pVideoMultiplex->setPolarity( query.
value(7).toString() );
871 pVideoMultiplex->setModulation( query.
value(8).toString() );
872 pVideoMultiplex->setBandwidth( query.
value(9).toString() );
873 pVideoMultiplex->setLPCodeRate( query.
value(10).toString() );
874 pVideoMultiplex->setTransmissionMode( query.
value(11).toString() );
875 pVideoMultiplex->setGuardInterval( query.
value(12).toString() );
876 pVideoMultiplex->setVisible( query.
value(13).toBool() );
877 pVideoMultiplex->setConstellation( query.
value(14).toString() );
878 pVideoMultiplex->setHierarchy( query.
value(15).toString() );
879 pVideoMultiplex->setHPCodeRate( query.
value(16).toString() );
880 pVideoMultiplex->setModulationSystem( query.
value(17).toString() );
881 pVideoMultiplex->setRollOff( query.
value(18).toString() );
882 pVideoMultiplex->setSIStandard( query.
value(19).toString() );
883 pVideoMultiplex->setServiceVersion( query.
value(20).toInt() );
884 pVideoMultiplex->setUpdateTimeStamp(
886 pVideoMultiplex->setDefaultAuthority( query.
value(22).toString() );
889 return pVideoMultiplex;
901 throw( QString(
"Database not open while trying to get source name."));
903 query.
prepare(
"SELECT name FROM videosource WHERE sourceid = :SOURCEID ");
910 throw( QString(
"Database Error executing query." ));
917 QString sourceName = query.
value(0).toString();
919 QString xmltvFile =
GetConfDir() +
'/' + sourceName +
".xmltv";
923 QFile
file(xmltvFile);
924 if (!
file.open(QIODevice::ReadOnly | QIODevice::Text))
927 while (!
file.atEnd())
929 QByteArray line =
file.readLine();
931 if (line.startsWith(
"channel="))
933 QString
id = line.mid(8, -1).trimmed();
943 throw(QString(
"SourceID (%1) not found").arg(
SourceID));
963 V2Grabber *pGrabber = pGrabberList->AddNewGrabber();
964 pGrabber->setProgram(
"eitonly");
965 pGrabber->setDisplayName(QObject::tr(
"Transmitted guide only (EIT)"));
966 pGrabber = pGrabberList->AddNewGrabber();
967 pGrabber->setProgram(
"/bin/true");
968 pGrabber->setDisplayName(QObject::tr(
"No grabber"));
975 find_grabber_proc.
Run(25s);
976 LOG(VB_GENERAL, LOG_INFO,
977 "Running 'tv_find_grabbers " +
args.join(
" ") +
"'.");
978 uint status = find_grabber_proc.
Wait();
982 QTextStream ostream(find_grabber_proc.
ReadAll());
983 while (!ostream.atEnd())
985 QString grabber_list(ostream.readLine());
986 QStringList grabber_split =
987 grabber_list.split(
"|", Qt::SkipEmptyParts);
988 const QString& grabber_name = grabber_split[1];
989 QFileInfo grabber_file(grabber_split[0]);
990 QString program = grabber_file.fileName();
992 if (!pGrabberList->containsProgram(program))
994 pGrabber = pGrabberList->AddNewGrabber();
995 pGrabber->setProgram(program);
996 pGrabber->setDisplayName(grabber_name);
998 LOG(VB_GENERAL, LOG_DEBUG,
"Found " + grabber_split[0]);
1000 LOG(VB_GENERAL, LOG_INFO,
"Finished running tv_find_grabbers");
1004 LOG(VB_GENERAL, LOG_ERR,
"Failed to run tv_find_grabbers");
1007 return pGrabberList;
1013 QStringList freqList;
1014 freqList.append(
"default");
1017 freqList.append(freqEntry.name);
1031 bool TestDecryptable,
1032 const QString &ScanType,
1035 const QString &FirstChan,
1036 const QString &LastChan,
1042 const QString &Bandwidth,
1043 const QString &Polarity,
1044 const QString &SymbolRate,
1045 const QString &Inversion,
1046 const QString &Constellation,
1047 const QString &ModSys,
1048 const QString &CodeRateLP,
1049 const QString &CodeRateHP,
1051 const QString &TransmissionMode,
1052 const QString &GuardInterval,
1053 const QString &Hierarchy,
1057 if (pScanner->
m_status ==
"RUNNING")
1099 pStatus->setCardId(pScanner->
m_cardid);
1100 pStatus->setStatus(pScanner->
m_status);
1108 pStatus->setDialogMsg(pScanner->
m_dlgMsg);
1131 auto *pItem = pResult->AddNewScan();
1132 pItem->setScanId (
scan.m_scanid);
1133 pItem->setCardId (
scan.m_cardid);
1134 pItem->setSourceId (
scan.m_sourceid);
1135 pItem->setProcessed (
scan.m_processed);
1136 pItem->setScanDate (
scan.m_scandate);
1142 const QString &DialogString,
1167 if (result.isEmpty())
1168 throw( QString(
"GetRestoreData failed."));
1179 bool result = rd->
doSave();
1187 QString
filename = Url.section(
'/', -1);
1190 QDir configDir(dirpath);
1191 if (!configDir.exists() && !configDir.mkdir(dirpath))
1193 LOG(VB_GENERAL, LOG_ERR, QString(
"Could not create %1").arg(dirpath));
1196 QString channelDir = QString(
"%1/%2").arg(configDir.absolutePath(),
1198 QDir strChannelDir(channelDir);
1199 if (!strChannelDir.exists() && !strChannelDir.mkdir(channelDir))
1201 LOG(VB_GENERAL, LOG_ERR,
1202 QString(
"Could not create %1").arg(channelDir));
1206 QString filePath = channelDir +
filename;
1212 QTemporaryFile tmpFile(filePath);
1213 if (!tmpFile.open())
1215 LOG(VB_GENERAL, LOG_INFO,
"Icon Download: Couldn't create temporary file");
1223 LOG(VB_GENERAL, LOG_INFO,
1224 QString(
"Download for icon %1 failed").arg(
filename));
1228 QImage icon(tmpFile.fileName());
1231 LOG(VB_GENERAL, LOG_INFO,
1232 QString(
"Downloaded icon for %1 isn't a valid image").arg(
filename));
1237 QFile
file(filePath);
1241 tmpFile.rename(filePath);
1242 tmpFile.setAutoRemove(
false);
1245 QString qstr =
"UPDATE channel SET icon = :ICON "
1246 "WHERE chanid = :CHANID";