bool CEpgDatabase::Delete(const CEpg &table, const CDateTime &start /* = NULL */, const CDateTime &end /* = NULL */) { /* invalid channel */ if (table.EpgID() <= 0) { CLog::Log(LOGERROR, "EpgDB - %s - invalid channel id: %d", __FUNCTION__, table.EpgID()); return false; } CLog::Log(LOGDEBUG, "EpgDB - %s - clearing the EPG '%d'", __FUNCTION__, table.EpgID()); CStdString strWhereClause; strWhereClause = FormatSQL("idEpg = %u", table.EpgID()); if (start != NULL) { time_t iStartTime; start.GetAsTime(iStartTime); strWhereClause.append(FormatSQL(" AND iStartTime < %u", iStartTime).c_str()); } if (end != NULL) { time_t iEndTime; end.GetAsTime(iEndTime); strWhereClause.append(FormatSQL(" AND iEndTime > %u", iEndTime).c_str()); } return DeleteValues("epgtags", strWhereClause); }
bool CPVRManager::SetWakeupCommand(void) { #if !defined(TARGET_DARWIN_IOS) && !defined(TARGET_WINDOWS_STORE) if (!m_settings.GetBoolValue(CSettings::SETTING_PVRPOWERMANAGEMENT_ENABLED)) return false; const std::string strWakeupCommand(m_settings.GetStringValue(CSettings::SETTING_PVRPOWERMANAGEMENT_SETWAKEUPCMD)); if (!strWakeupCommand.empty() && m_timers) { time_t iWakeupTime; const CDateTime nextEvent = m_timers->GetNextEventTime(); if (nextEvent.IsValid()) { nextEvent.GetAsTime(iWakeupTime); std::string strExecCommand = StringUtils::Format("%s %ld", strWakeupCommand.c_str(), iWakeupTime); const int iReturn = system(strExecCommand.c_str()); if (iReturn != 0) CLog::LogF(LOGERROR, "PVR Manager failed to execute wakeup command '%s': %s (%d)", strExecCommand.c_str(), strerror(iReturn), iReturn); return iReturn == 0; } } #endif return false; }
int CGUIDialogPVRTimerSettings::GetDateAsIndex(const CDateTime &datetime) { const CDateTime date(datetime.GetYear(), datetime.GetMonth(), datetime.GetDay(), 0, 0, 0); time_t t(0); date.GetAsTime(t); return static_cast<int>(t); }
bool CPVRManager::SetWakeupCommand(void) { if (!g_guiSettings.GetBool("pvrpowermanagement.enabled")) return false; const CStdString strWakeupCommand = g_guiSettings.GetString("pvrpowermanagement.setwakeupcmd", false); if (!strWakeupCommand.IsEmpty() && m_timers) { time_t iWakeupTime; const CDateTime nextEvent = m_timers->GetNextEventTime(); if (nextEvent.IsValid()) { nextEvent.GetAsTime(iWakeupTime); CStdString strExecCommand; strExecCommand.Format("%s %d", strWakeupCommand, iWakeupTime); const int iReturn = system(strExecCommand.c_str()); if (iReturn != 0) CLog::Log(LOGERROR, "%s - failed to execute wakeup command '%s': %s (%d)", __FUNCTION__, strExecCommand.c_str(), strerror(iReturn), iReturn); return iReturn == 0; } } return false; }
bool CPVRManager::SetWakeupCommand(void) { if (!CSettings::GetInstance().GetBool(CSettings::SETTING_PVRPOWERMANAGEMENT_ENABLED)) return false; const std::string strWakeupCommand = CSettings::GetInstance().GetString(CSettings::SETTING_PVRPOWERMANAGEMENT_SETWAKEUPCMD); if (!strWakeupCommand.empty() && m_timers) { time_t iWakeupTime; const CDateTime nextEvent = m_timers->GetNextEventTime(); if (nextEvent.IsValid()) { nextEvent.GetAsTime(iWakeupTime); std::string strExecCommand = StringUtils::Format("%s %ld", strWakeupCommand.c_str(), iWakeupTime); const int iReturn = system(strExecCommand.c_str()); if (iReturn != 0) CLog::Log(LOGERROR, "%s - failed to execute wakeup command '%s': %s (%d)", __FUNCTION__, strExecCommand.c_str(), strerror(iReturn), iReturn); return iReturn == 0; } } return false; }
bool CEpgDatabase::DeleteOldEpgEntries(void) { time_t iYesterday; CDateTime yesterday = CDateTime::GetCurrentDateTime() - CDateTimeSpan(1, 0, 0, 0); yesterday.GetAsTime(iYesterday); CStdString strWhereClause = FormatSQL("iEndTime < %u", iYesterday); return DeleteValues("epgtags", strWhereClause); }
bool CPVREpgDatabase::DeleteEpgEntries(const CDateTime &maxEndTime) { time_t iMaxEndTime; maxEndTime.GetAsTime(iMaxEndTime); Filter filter; filter.AppendWhere(PrepareSQL("iEndTime < %u", iMaxEndTime)); return DeleteValues("epgtags", filter); }
bool CEpgDatabase::DeleteOldEpgEntries(void) { time_t iCleanupTime; CDateTime cleanupTime = CDateTime::GetCurrentDateTime().GetAsUTCDateTime() - CDateTimeSpan(0, g_advancedSettings.m_iEpgLingerTime / 60, g_advancedSettings.m_iEpgLingerTime % 60, 0); cleanupTime.GetAsTime(iCleanupTime); Filter filter; filter.AppendWhere(PrepareSQL("iEndTime < %u", iCleanupTime)); return DeleteValues("epgtags", filter); }
bool CEpgDatabase::DeleteOldEpgEntries(void) { time_t iCleanupTime; CDateTime cleanupTime = CDateTime::GetCurrentDateTime().GetAsUTCDateTime() - CDateTimeSpan(0, g_advancedSettings.m_iEpgLingerTime / 60, g_advancedSettings.m_iEpgLingerTime % 60, 0); cleanupTime.GetAsTime(iCleanupTime); CStdString strWhereClause = FormatSQL("iEndTime < %u", iCleanupTime); CSingleLock lock(m_critSection); return DeleteValues("epgtags", strWhereClause); }
bool CEpg::PersistTags(void) const { bool bReturn = false; CEpgDatabase *database = g_EpgContainer.GetDatabase(); if (!database || !database->IsOpen()) { CLog::Log(LOGERROR, "EPG - %s - could not load the database", __FUNCTION__); return bReturn; } CDateTime first = GetFirstDate(); CDateTime last = GetLastDate(); time_t iStart(0), iEnd(0); if (first.IsValid()) first.GetAsTime(iStart); if (last.IsValid()) last.GetAsTime(iEnd); database->Delete(*this, iStart, iEnd); if (m_tags.size() > 0) { for (map<CDateTime, CEpgInfoTag *>::const_iterator it = m_tags.begin(); it != m_tags.end(); it++) { if (!it->second->Persist()) { CLog::Log(LOGERROR, "failed to persist epg tag %d", it->second->UniqueBroadcastID()); bReturn = false; } } } else { /* Return true if we have no tags, so that no error is logged */ bReturn = true; } return bReturn; }
bool CEpg::Update(const time_t start, const time_t end, int iUpdateTime, bool bForceUpdate /* = false */) { bool bGrabSuccess(true); bool bUpdate(false); /* load the entries from the db first */ if (!m_bLoaded && !g_EpgContainer.IgnoreDB()) Load(); /* clean up if needed */ if (m_bLoaded) Cleanup(); /* get the last update time from the database */ CDateTime lastScanTime = GetLastScanTime(); /* enforce advanced settings update interval override for TV Channels with no EPG data */ if (m_tags.empty() && !bUpdate && ChannelID() > 0 && !Channel()->IsRadio()) iUpdateTime = g_advancedSettings.m_iEpgUpdateEmptyTagsInterval; if (!bForceUpdate) { /* check if we have to update */ time_t iNow = 0; time_t iLastUpdate = 0; CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(iNow); lastScanTime.GetAsTime(iLastUpdate); bUpdate = (iNow > iLastUpdate + iUpdateTime); } else bUpdate = true; if (bUpdate) bGrabSuccess = LoadFromClients(start, end); if (bGrabSuccess) { CPVRChannelPtr channel(g_PVRManager.GetCurrentChannel()); if (channel && channel->EpgID() == m_iEpgID) g_PVRManager.ResetPlayingTag(); m_bLoaded = true; } else CLog::Log(LOGERROR, "EPG - %s - failed to update table '%s'", __FUNCTION__, Name().c_str()); CSingleLock lock(m_critSection); m_bUpdatePending = false; return bGrabSuccess; }
void CPVRManager::UpdateLastWatched(const CPVRChannelPtr &channel, const CDateTime& time) { time_t iTime; time.GetAsTime(iTime); channel->SetLastWatched(iTime); // update last watched timestamp for group CPVRChannelGroupPtr group(GetPlayingGroup(channel->IsRadio())); group->SetLastWatched(iTime); /* update last played group */ m_channelGroups->SetLastPlayedGroup(group); }
bool CEpg::Update(const time_t start, const time_t end, int iUpdateTime, bool bForceUpdate /* = false */) { bool bGrabSuccess(true); bool bUpdate(false); /* load the entries from the db first */ if (!m_bLoaded && !g_EpgContainer.IgnoreDB()) Load(); /* clean up if needed */ if (m_bLoaded) Cleanup(); /* get the last update time from the database */ CDateTime lastScanTime = GetLastScanTime(); if (!bForceUpdate) { /* check if we have to update */ time_t iNow = 0; time_t iLastUpdate = 0; CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(iNow); lastScanTime.GetAsTime(iLastUpdate); bUpdate = (iNow > iLastUpdate + iUpdateTime); } else bUpdate = true; if (bUpdate) bGrabSuccess = LoadFromClients(start, end); if (bGrabSuccess) { CPVRChannel channel; if (g_PVRManager.GetCurrentChannel(channel)) if (channel.EpgID() == m_iEpgID) g_PVRManager.ResetPlayingTag(); m_bLoaded = true; } else CLog::Log(LOGERROR, "EPG - %s - failed to update table '%s'", __FUNCTION__, Name().c_str()); CSingleLock lock(m_critSection); m_bUpdatePending = false; return bGrabSuccess; }
bool CEpg::Update(const time_t start, const time_t end, int iUpdateTime) { bool bGrabSuccess(true); bool bUpdate(false); /* load the entries from the db first */ if (!m_bLoaded && !g_EpgContainer.IgnoreDB()) Load(); /* clean up if needed */ if (m_bLoaded) Cleanup(); /* get the last update time from the database */ CDateTime lastScanTime = GetLastScanTime(); /* check if we have to update */ time_t iNow = 0; time_t iLastUpdate = 0; CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(iNow); lastScanTime.GetAsTime(iLastUpdate); bUpdate = (iNow > iLastUpdate + iUpdateTime); if (bUpdate) bGrabSuccess = LoadFromClients(start, end); if (bGrabSuccess) { g_PVRManager.ResetPlayingTag(); m_bLoaded = true; } else CLog::Log(LOGERROR, "EPG - %s - failed to update table '%s'", __FUNCTION__, Name().c_str()); return bGrabSuccess; }
int CEpgDatabase::Get(CEpg *epg, const CDateTime &start /* = NULL */, const CDateTime &end /* = NULL */) { int iReturn = -1; CStdString strWhereClause; strWhereClause = FormatSQL("idEpg = %u", epg->EpgID()); if (start != NULL) { time_t iStartTime; start.GetAsTime(iStartTime); strWhereClause.append(FormatSQL(" AND iStartTime < %u", iStartTime).c_str()); } if (end != NULL) { time_t iEndTime; end.GetAsTime(iEndTime); strWhereClause.append(FormatSQL(" AND iEndTime > %u", iEndTime).c_str()); } CStdString strQuery; strQuery.Format("SELECT * FROM epgtags WHERE %s ORDER BY iStartTime ASC;", strWhereClause.c_str()); if (ResultQuery(strQuery)) { iReturn = 0; try { while (!m_pDS->eof()) { CEpgInfoTag newTag; time_t iStartTime, iEndTime, iFirstAired; iStartTime = (time_t) m_pDS->fv("iStartTime").get_asInt(); CDateTime startTime(iStartTime); newTag.m_startTime = startTime; iEndTime = (time_t) m_pDS->fv("iEndTime").get_asInt(); CDateTime endTime(iEndTime); newTag.m_endTime = endTime; iFirstAired = (time_t) m_pDS->fv("iFirstAired").get_asInt(); CDateTime firstAired(iFirstAired); newTag.m_firstAired = firstAired; newTag.m_iUniqueBroadcastID = m_pDS->fv("iBroadcastUid").get_asInt(); newTag.m_iBroadcastId = m_pDS->fv("idBroadcast").get_asInt(); newTag.m_strTitle = m_pDS->fv("sTitle").get_asString().c_str(); newTag.m_strPlotOutline = m_pDS->fv("sPlotOutline").get_asString().c_str(); newTag.m_strPlot = m_pDS->fv("sPlot").get_asString().c_str(); newTag.m_iGenreType = m_pDS->fv("iGenreType").get_asInt(); newTag.m_iGenreSubType = m_pDS->fv("iGenreSubType").get_asInt(); newTag.m_iParentalRating = m_pDS->fv("iParentalRating").get_asInt(); newTag.m_iStarRating = m_pDS->fv("iStarRating").get_asInt(); newTag.m_bNotify = m_pDS->fv("bNotify").get_asBool(); newTag.m_iEpisodeNum = m_pDS->fv("iEpisodeId").get_asInt(); newTag.m_iEpisodePart = m_pDS->fv("iEpisodePart").get_asInt(); newTag.m_strEpisodeName = m_pDS->fv("sEpisodeName").get_asString().c_str(); newTag.m_iSeriesNum = m_pDS->fv("iSeriesId").get_asInt(); epg->AddEntry(newTag); ++iReturn; m_pDS->next(); } m_pDS->close(); } catch (...) { CLog::Log(LOGERROR, "%s - couldn't load EPG data from the database", __FUNCTION__); } } return iReturn; }