33 #include <QTemporaryFile>
42 #include "libmythbase/mythversion.h"
77 qRegisterMetaType<V2ChannelInfoList*>(
"V2ChannelInfoList");
78 qRegisterMetaType<V2ChannelInfo*>(
"V2ChannelInfo");
79 qRegisterMetaType<V2VideoSourceList*>(
"V2VideoSourceList");
80 qRegisterMetaType<V2VideoSource*>(
"V2VideoSource");
81 qRegisterMetaType<V2LineupList*>(
"V2LineupList");
82 qRegisterMetaType<V2Lineup*>(
"V2Lineup");
83 qRegisterMetaType<V2VideoMultiplexList*>(
"V2VideoMultiplexList");
84 qRegisterMetaType<V2VideoMultiplex*>(
"V2VideoMultiplex");
85 qRegisterMetaType<V2Program*>(
"V2Program");
86 qRegisterMetaType<V2RecordingInfo*>(
"V2RecordingInfo");
87 qRegisterMetaType<V2ArtworkInfoList*>(
"V2ArtworkInfoList");
88 qRegisterMetaType<V2ArtworkInfo*>(
"V2ArtworkInfo");
89 qRegisterMetaType<V2CastMemberList*>(
"V2CastMemberList");
90 qRegisterMetaType<V2CastMember*>(
"V2CastMember");
91 qRegisterMetaType<V2Grabber*>(
"V2Grabber");
92 qRegisterMetaType<V2GrabberList*>(
"V2GrabberList");
93 qRegisterMetaType<V2FreqTableList*>(
"V2FreqTableList");
94 qRegisterMetaType<V2CommMethodList*>(
"V2CommMethodList");
95 qRegisterMetaType<V2CommMethod*>(
"V2CommMethod");
96 qRegisterMetaType<V2ScanStatus*>(
"V2ScanStatus");
97 qRegisterMetaType<V2Scan*>(
"V2Scan");
98 qRegisterMetaType<V2ScanList*>(
"V2ScanList");
99 qRegisterMetaType<V2ChannelRestore*>(
"V2ChannelRestore");
109 uint nChannelGroupID,
115 bool bGroupByCallsign,
120 uint nTotalAvailable = 0;
125 nSourceID, nChannelGroupID,
false,
"",
134 nStartIndex = (nStartIndex > 0) ? std::min( nStartIndex, nTotalAvailable ) : 0;
135 nCount = (nCount > 0) ? std::min(nCount, (nTotalAvailable - nStartIndex)) :
136 (nTotalAvailable - nStartIndex);
138 ChannelInfoList::iterator chanIt;
139 auto chanItBegin = chanList.begin() + nStartIndex;
140 auto chanItEnd = chanItBegin + nCount;
142 for( chanIt = chanItBegin; chanIt < chanItEnd; ++chanIt )
144 V2ChannelInfo *pChannelInfo = pChannelInfos->AddNewChannelInfo();
151 delete pChannelInfos;
152 throw( QString(
"V2Channel ID appears invalid."));
161 nTotalPages = (int)std::ceil((
float)nTotalAvailable / nCount);
163 if (nTotalPages == 1)
167 nCurPage = (int)std::ceil((
float)nStartIndex / nCount) + 1;
170 pChannelInfos->setStartIndex ( nStartIndex );
171 pChannelInfos->setCount ( nCount );
172 pChannelInfos->setCurrentPage ( nCurPage );
173 pChannelInfos->setTotalPages ( nTotalPages );
174 pChannelInfos->setTotalAvailable( nTotalAvailable );
176 pChannelInfos->setVersion ( MYTH_BINARY_VERSION );
177 pChannelInfos->setProtoVer ( MYTH_PROTO_VERSION );
179 return pChannelInfos;
189 throw( QString(
"V2Channel ID appears invalid."));
206 const QString &CallSign,
207 const QString &ChannelName,
208 const QString &ChannelNumber,
210 uint ATSCMajorChannel,
211 uint ATSCMinorChannel,
214 const QString &ExtendedVisible,
215 const QString &FrequencyID,
218 const QString &XMLTVID,
219 const QString &DefaultAuthority,
226 throw QString(
"ChannelId is required");
229 throw QString(
"Nothing to update");
233 throw QString(
"ChannelId %1 doesn't exist");
242 channel.
m_name = ChannelName;
266 throw QString(
"Can't override Always/NeverVisible");
299 QDateTime(),
"UpdateDBChannel");
308 query.
prepare(
"SELECT MAX(chanid) FROM channel");
312 throw( QString(
"Database Error executing query." ));
315 chanId = query.
value(0).toUInt() + 1;
316 chanId = std::max<uint>(chanId, 1000);
323 const QString &CallSign,
324 const QString &ChannelName,
325 const QString &ChannelNumber,
327 uint ATSCMajorChannel,
328 uint ATSCMinorChannel,
331 const QString &ExtendedVisible,
332 const QString &FrequencyID,
335 const QString &XMLTVID,
336 const QString &DefaultAuthority,
349 CallSign, ChannelName, ChannelNumber,
350 ServiceID, ATSCMajorChannel, ATSCMinorChannel,
351 UseEIT, chan_visible, FrequencyID,
377 pCommMethod->setCommMethod(pref);
393 throw( QString(
"Database not open while trying to list "
396 query.
prepare(
"SELECT sourceid, name, xmltvgrabber, userid, "
397 "freqtable, lineupid, password, useeit, configpath, "
398 "dvb_nit_id, bouquet_id, region_id, scanfrequency, "
399 "lcnoffset FROM videosource "
400 "ORDER BY sourceid" );
406 throw( QString(
"Database Error executing query." ));
420 pVideoSource->setId ( query.
value(0).toInt() );
421 pVideoSource->setSourceName ( query.
value(1).toString() );
422 pVideoSource->setGrabber ( query.
value(2).toString() );
423 pVideoSource->setUserId ( query.
value(3).toString() );
424 pVideoSource->setFreqTable ( query.
value(4).toString() );
425 pVideoSource->setLineupId ( query.
value(5).toString() );
426 pVideoSource->setPassword ( query.
value(6).toString() );
427 pVideoSource->setUseEIT ( query.
value(7).toBool() );
428 pVideoSource->setConfigPath ( query.
value(8).toString() );
429 pVideoSource->setNITId ( query.
value(9).toInt() );
430 pVideoSource->setBouquetId ( query.
value(10).toUInt() );
431 pVideoSource->setRegionId ( query.
value(11).toUInt() );
432 pVideoSource->setScanFrequency ( query.
value(12).toUInt() );
433 pVideoSource->setLCNOffset ( query.
value(13).toUInt() );
437 pList->setVersion ( MYTH_BINARY_VERSION );
438 pList->setProtoVer ( MYTH_PROTO_VERSION );
452 throw( QString(
"Database not open while trying to list "
455 query.
prepare(
"SELECT name, xmltvgrabber, userid, "
456 "freqtable, lineupid, password, useeit, configpath, "
457 "dvb_nit_id, bouquet_id, region_id, scanfrequency, "
459 "FROM videosource WHERE sourceid = :SOURCEID "
460 "ORDER BY sourceid" );
467 throw( QString(
"Database Error executing query." ));
478 pVideoSource->setId ( nSourceID );
479 pVideoSource->setSourceName ( query.
value(0).toString() );
480 pVideoSource->setGrabber ( query.
value(1).toString() );
481 pVideoSource->setUserId ( query.
value(2).toString() );
482 pVideoSource->setFreqTable ( query.
value(3).toString() );
483 pVideoSource->setLineupId ( query.
value(4).toString() );
484 pVideoSource->setPassword ( query.
value(5).toString() );
485 pVideoSource->setUseEIT ( query.
value(6).toBool() );
486 pVideoSource->setConfigPath ( query.
value(7).toString() );
487 pVideoSource->setNITId ( query.
value(8).toInt() );
488 pVideoSource->setBouquetId ( query.
value(9).toUInt() );
489 pVideoSource->setRegionId ( query.
value(10).toUInt() );
490 pVideoSource->setScanFrequency ( query.
value(11).toUInt() );
491 pVideoSource->setLCNOffset ( query.
value(12).toUInt() );
502 const QString &sSourceName,
503 const QString &sGrabber,
504 const QString &sUserId,
505 const QString &sFreqTable,
506 const QString &sLineupId,
507 const QString &sPassword,
509 const QString &sConfigPath,
519 LOG(VB_GENERAL, LOG_ERR,
"SourceId is required");
525 LOG(VB_GENERAL, LOG_ERR, QString(
"SourceId %1 doesn't exist")
532 LOG(VB_GENERAL, LOG_ERR, QString(
"SourceId=%1 was the only parameter")
538 MSqlBindings::const_iterator it;
542 ADD_SQLv2(settings, bindings,
"name",
"SourceName", sSourceName);
545 ADD_SQLv2(settings, bindings,
"xmltvgrabber",
"Grabber", sGrabber);
548 ADD_SQLv2(settings, bindings,
"userid",
"UserId", sUserId);
551 ADD_SQLv2(settings, bindings,
"freqtable",
"FreqTable", sFreqTable);
554 ADD_SQLv2(settings, bindings,
"lineupid",
"LineupId", sLineupId);
557 ADD_SQLv2(settings, bindings,
"password",
"Password", sPassword);
560 ADD_SQLv2(settings, bindings,
"useeit",
"UseEIT", bUseEIT);
564 if (sConfigPath.isEmpty())
565 settings +=
"configpath=NULL, ";
567 ADD_SQLv2(settings, bindings,
"configpath",
"ConfigPath", sConfigPath);
571 ADD_SQLv2(settings, bindings,
"dvb_nit_id",
"NITId", nNITId);
574 ADD_SQLv2(settings, bindings,
"bouquet_id",
"BouquetId", nBouquetId);
577 ADD_SQLv2(settings, bindings,
"region_id",
"RegionId", nRegionId);
580 ADD_SQLv2(settings, bindings,
"scanfrequency",
"ScanFrequency", nScanFrequency);
583 ADD_SQLv2(settings, bindings,
"lcnoffset",
"LCNOffset", nLCNOffset);
585 if ( settings.isEmpty() )
587 LOG(VB_GENERAL, LOG_ERR,
"No valid parameters were passed");
595 query.
prepare(QString(
"UPDATE videosource SET %1 WHERE sourceid=:SOURCEID")
597 bindings[
":SOURCEID"] = nSourceId;
599 for (it = bindings.cbegin(); it != bindings.cend(); ++it)
606 throw( QString(
"Database Error executing query." ));
617 const QString &sGrabber,
618 const QString &sUserId,
619 const QString &sFreqTable,
620 const QString &sLineupId,
621 const QString &sPassword,
623 const QString &sConfigPath,
631 sLineupId, sPassword, bUseEIT, sConfigPath,
632 nNITId, nBouquetId, nRegionId, nScanFrequency,
674 bool bWaitForFinish )
676 if ( nSourceId < 1 || nCardId < 1)
677 throw( QString(
"A source ID and card ID are both required."));
710 throw( QString(
"Database not open while trying to list "
714 where =
"WHERE sourceid = :SOURCEID";
715 QString sql = QString(
"SELECT mplexid, sourceid, transportid, networkid, "
716 "frequency, inversion, symbolrate, fec, polarity, "
717 "modulation, bandwidth, lp_code_rate, transmission_mode, "
718 "guard_interval, visible, constellation, hierarchy, hp_code_rate, "
719 "mod_sys, rolloff, sistandard, serviceversion, updatetimestamp, "
720 "default_authority FROM dtv_multiplex %1 "
721 "ORDER BY mplexid").arg(where);
731 throw( QString(
"Database Error executing query." ));
742 nStartIndex = (nStartIndex > 0) ? std::min( nStartIndex, muxCount ) : 0;
743 nCount = (nCount > 0) ? std::min( nCount, muxCount ) : muxCount;
744 int nEndIndex = std::min((nStartIndex + nCount), muxCount );
746 for(
int n = nStartIndex; n < nEndIndex; n++)
750 V2VideoMultiplex *pVideoMultiplex = pVideoMultiplexes->AddNewVideoMultiplex();
752 pVideoMultiplex->setMplexId( query.
value(0).toInt() );
753 pVideoMultiplex->setSourceId( query.
value(1).toInt() );
754 pVideoMultiplex->setTransportId( query.
value(2).toInt() );
755 pVideoMultiplex->setNetworkId( query.
value(3).toInt() );
756 pVideoMultiplex->setFrequency( query.
value(4).toLongLong() );
757 pVideoMultiplex->setInversion( query.
value(5).toString() );
758 pVideoMultiplex->setSymbolRate( query.
value(6).toLongLong() );
759 pVideoMultiplex->setFEC( query.
value(7).toString() );
760 pVideoMultiplex->setPolarity( query.
value(8).toString() );
761 pVideoMultiplex->setModulation( query.
value(9).toString() );
762 pVideoMultiplex->setBandwidth( query.
value(10).toString() );
763 pVideoMultiplex->setLPCodeRate( query.
value(11).toString() );
764 pVideoMultiplex->setTransmissionMode( query.
value(12).toString() );
765 pVideoMultiplex->setGuardInterval( query.
value(13).toString() );
766 pVideoMultiplex->setVisible( query.
value(14).toBool() );
767 pVideoMultiplex->setConstellation( query.
value(15).toString() );
768 pVideoMultiplex->setHierarchy( query.
value(16).toString() );
769 pVideoMultiplex->setHPCodeRate( query.
value(17).toString() );
770 pVideoMultiplex->setModulationSystem( query.
value(18).toString() );
771 pVideoMultiplex->setRollOff( query.
value(19).toString() );
772 pVideoMultiplex->setSIStandard( query.
value(20).toString() );
773 pVideoMultiplex->setServiceVersion( query.
value(21).toInt() );
774 pVideoMultiplex->setUpdateTimeStamp(
776 pVideoMultiplex->setDefaultAuthority( query.
value(23).toString() );
780 if (query.
value(9).toString() ==
"8vsb")
782 QString ChannelNumber =
784 QString(
"Freq %1").arg(query.
value(4).toInt());
785 int findFrequency = (query.
value(4).toInt() / 1000) - 1750;
788 if ((list.freq <= findFrequency + 200) &&
789 (list.freq >= findFrequency - 200))
791 ChannelNumber = QString(
"%1").arg(list.name);
795 DisplayText = tr(
"ATSC Channel %1").arg(ChannelNumber);
799 DisplayText = QString(
"%1 Hz (%2) (%3) (%4)")
800 .arg(query.
value(4).toString(),
801 query.
value(6).toString(),
802 query.
value(3).toString(),
803 query.
value(2).toString());
805 pVideoMultiplex->setDescription(DisplayText);
814 totalPages = (int)std::ceil((
float)muxCount / nCount);
820 curPage = (int)std::ceil((
float)nStartIndex / nCount) + 1;
823 pVideoMultiplexes->setStartIndex ( nStartIndex );
824 pVideoMultiplexes->setCount ( nCount );
825 pVideoMultiplexes->setCurrentPage ( curPage );
826 pVideoMultiplexes->setTotalPages ( totalPages );
827 pVideoMultiplexes->setTotalAvailable( muxCount );
829 pVideoMultiplexes->setVersion ( MYTH_BINARY_VERSION );
830 pVideoMultiplexes->setProtoVer ( MYTH_PROTO_VERSION );
832 return pVideoMultiplexes;
840 throw( QString(
"Database not open while trying to list "
841 "Video Multiplex."));
843 query.
prepare(
"SELECT sourceid, transportid, networkid, "
844 "frequency, inversion, symbolrate, fec, polarity, "
845 "modulation, bandwidth, lp_code_rate, transmission_mode, "
846 "guard_interval, visible, constellation, hierarchy, hp_code_rate, "
847 "mod_sys, rolloff, sistandard, serviceversion, updatetimestamp, "
848 "default_authority FROM dtv_multiplex WHERE mplexid = :MPLEXID "
849 "ORDER BY mplexid" );
856 throw( QString(
"Database Error executing query." ));
863 pVideoMultiplex->setMplexId( nMplexID );
864 pVideoMultiplex->setSourceId( query.
value(0).toInt() );
865 pVideoMultiplex->setTransportId( query.
value(1).toInt() );
866 pVideoMultiplex->setNetworkId( query.
value(2).toInt() );
867 pVideoMultiplex->setFrequency( query.
value(3).toLongLong() );
868 pVideoMultiplex->setInversion( query.
value(4).toString() );
869 pVideoMultiplex->setSymbolRate( query.
value(5).toLongLong() );
870 pVideoMultiplex->setFEC( query.
value(6).toString() );
871 pVideoMultiplex->setPolarity( query.
value(7).toString() );
872 pVideoMultiplex->setModulation( query.
value(8).toString() );
873 pVideoMultiplex->setBandwidth( query.
value(9).toString() );
874 pVideoMultiplex->setLPCodeRate( query.
value(10).toString() );
875 pVideoMultiplex->setTransmissionMode( query.
value(11).toString() );
876 pVideoMultiplex->setGuardInterval( query.
value(12).toString() );
877 pVideoMultiplex->setVisible( query.
value(13).toBool() );
878 pVideoMultiplex->setConstellation( query.
value(14).toString() );
879 pVideoMultiplex->setHierarchy( query.
value(15).toString() );
880 pVideoMultiplex->setHPCodeRate( query.
value(16).toString() );
881 pVideoMultiplex->setModulationSystem( query.
value(17).toString() );
882 pVideoMultiplex->setRollOff( query.
value(18).toString() );
883 pVideoMultiplex->setSIStandard( query.
value(19).toString() );
884 pVideoMultiplex->setServiceVersion( query.
value(20).toInt() );
885 pVideoMultiplex->setUpdateTimeStamp(
887 pVideoMultiplex->setDefaultAuthority( query.
value(22).toString() );
890 return pVideoMultiplex;
902 throw( QString(
"Database not open while trying to get source name."));
904 query.
prepare(
"SELECT name FROM videosource WHERE sourceid = :SOURCEID ");
911 throw( QString(
"Database Error executing query." ));
918 QString sourceName = query.
value(0).toString();
920 QString xmltvFile =
GetConfDir() +
'/' + sourceName +
".xmltv";
924 QFile
file(xmltvFile);
925 if (!
file.open(QIODevice::ReadOnly | QIODevice::Text))
928 while (!
file.atEnd())
930 QByteArray line =
file.readLine();
932 if (line.startsWith(
"channel="))
934 QString
id = line.mid(8, -1).trimmed();
944 throw(QString(
"SourceID (%1) not found").arg(
SourceID));
964 V2Grabber *pGrabber = pGrabberList->AddNewGrabber();
965 pGrabber->setProgram(
"eitonly");
966 pGrabber->setDisplayName(QObject::tr(
"Transmitted guide only (EIT)"));
967 pGrabber = pGrabberList->AddNewGrabber();
968 pGrabber->setProgram(
"/bin/true");
969 pGrabber->setDisplayName(QObject::tr(
"No grabber"));
976 find_grabber_proc.
Run(25s);
977 LOG(VB_GENERAL, LOG_INFO,
978 "Running 'tv_find_grabbers " +
args.join(
" ") +
"'.");
979 uint status = find_grabber_proc.
Wait();
983 QTextStream ostream(find_grabber_proc.
ReadAll());
984 while (!ostream.atEnd())
986 QString grabber_list(ostream.readLine());
987 QStringList grabber_split =
988 grabber_list.split(
"|", Qt::SkipEmptyParts);
989 const QString& grabber_name = grabber_split[1];
990 QFileInfo grabber_file(grabber_split[0]);
991 QString program = grabber_file.fileName();
993 if (!pGrabberList->containsProgram(program))
995 pGrabber = pGrabberList->AddNewGrabber();
996 pGrabber->setProgram(program);
997 pGrabber->setDisplayName(grabber_name);
999 LOG(VB_GENERAL, LOG_DEBUG,
"Found " + grabber_split[0]);
1001 LOG(VB_GENERAL, LOG_INFO,
"Finished running tv_find_grabbers");
1005 LOG(VB_GENERAL, LOG_ERR,
"Failed to run tv_find_grabbers");
1008 return pGrabberList;
1014 QStringList freqList;
1015 freqList.append(
"default");
1018 freqList.append(freqEntry.name);
1032 bool TestDecryptable,
1033 const QString &ScanType,
1036 const QString &FirstChan,
1037 const QString &LastChan,
1043 const QString &Bandwidth,
1044 const QString &Polarity,
1045 const QString &SymbolRate,
1046 const QString &Inversion,
1047 const QString &Constellation,
1048 const QString &ModSys,
1049 const QString &CodeRateLP,
1050 const QString &CodeRateHP,
1052 const QString &TransmissionMode,
1053 const QString &GuardInterval,
1054 const QString &Hierarchy,
1058 if (pScanner->
m_status ==
"RUNNING")
1100 pStatus->setCardId(pScanner->
m_cardid);
1101 pStatus->setStatus(pScanner->
m_status);
1109 pStatus->setDialogMsg(pScanner->
m_dlgMsg);
1132 auto *pItem = pResult->AddNewScan();
1133 pItem->setScanId (
scan.m_scanid);
1134 pItem->setCardId (
scan.m_cardid);
1135 pItem->setSourceId (
scan.m_sourceid);
1136 pItem->setProcessed (
scan.m_processed);
1137 pItem->setScanDate (
scan.m_scandate);
1143 const QString &DialogString,
1168 if (result.isEmpty())
1169 throw( QString(
"GetRestoreData failed."));
1180 bool result = rd->
doSave();
1188 QString
filename = Url.section(
'/', -1);
1191 QDir configDir(dirpath);
1192 if (!configDir.exists() && !configDir.mkdir(dirpath))
1194 LOG(VB_GENERAL, LOG_ERR, QString(
"Could not create %1").arg(dirpath));
1197 QString channelDir = QString(
"%1/%2").arg(configDir.absolutePath(),
1199 QDir strChannelDir(channelDir);
1200 if (!strChannelDir.exists() && !strChannelDir.mkdir(channelDir))
1202 LOG(VB_GENERAL, LOG_ERR,
1203 QString(
"Could not create %1").arg(channelDir));
1207 QString filePath = channelDir +
filename;
1213 QTemporaryFile tmpFile(filePath);
1214 if (!tmpFile.open())
1216 LOG(VB_GENERAL, LOG_INFO,
"Icon Download: Couldn't create temporary file");
1224 LOG(VB_GENERAL, LOG_INFO,
1225 QString(
"Download for icon %1 failed").arg(
filename));
1229 QImage icon(tmpFile.fileName());
1232 LOG(VB_GENERAL, LOG_INFO,
1233 QString(
"Downloaded icon for %1 isn't a valid image").arg(
filename));
1238 QFile
file(filePath);
1242 tmpFile.rename(filePath);
1243 tmpFile.setAutoRemove(
false);
1246 QString qstr =
"UPDATE channel SET icon = :ICON "
1247 "WHERE chanid = :CHANID";