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 CEpgContainer::UpdateEntry(const CEpg &entry, bool bUpdateDatabase /* = false */) { CEpg *epg(NULL); bool bReturn(false); WaitForUpdateFinish(true); CSingleLock lock(m_critSection); epg = entry.EpgID() > 0 ? GetById(entry.EpgID()) : NULL; if (!epg) { /* table does not exist yet, create a new one */ unsigned int iEpgId = m_bIgnoreDbForClient || entry.EpgID() <= 0 ? NextEpgId() : entry.EpgID(); epg = CreateEpg(iEpgId); if (epg) { bReturn = epg->UpdateMetadata(entry, bUpdateDatabase); m_epgs.insert(make_pair((unsigned int)epg->EpgID(), epg)); } } else { bReturn = epg->UpdateMetadata(entry, bUpdateDatabase); } m_bPreventUpdates = false; CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(m_iNextEpgUpdate); return bReturn; }
bool CEpgContainer::UpdateEntry(const CEpg &entry, bool bUpdateDatabase /* = false */) { bool bReturn = false; CSingleLock lock(m_critSection); /* make sure the update thread is stopped */ bool bThreadRunning = !m_bStop && m_bDatabaseLoaded; if (bThreadRunning && !Stop()) return bReturn; CEpg *epg = GetById(entry.EpgID()); if (!epg) { epg = CreateEpg(entry.EpgID()); if (epg) push_back(epg); } bReturn = epg ? epg->Update(entry, bUpdateDatabase) : false; lock.Leave(); if (bThreadRunning) Start(); return bReturn; }
bool CEpgDatabase::Delete(const CEpg &table) { /* invalid channel */ if (table.EpgID() <= 0) { CLog::Log(LOGERROR, "EpgDB - %s - invalid channel id: %d", __FUNCTION__, table.EpgID()); return false; } Filter filter; filter.AppendWhere(PrepareSQL("idEpg = %u", table.EpgID())); return DeleteValues("epg", filter); }
int CEpgDatabase::Get(CEpg &epg) { int iReturn(-1); std::string strQuery = PrepareSQL("SELECT * FROM epgtags WHERE idEpg = %u;", epg.EpgID()); if (ResultQuery(strQuery)) { iReturn = 0; try { while (!m_pDS->eof()) { CEpgInfoTagPtr newTag(new CEpgInfoTag()); 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_genre = StringUtils::Split(m_pDS->fv("sGenre").get_asString().c_str(), g_advancedSettings.m_videoItemSeparator); 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_iEpisodeNumber = 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_iSeriesNumber = m_pDS->fv("iSeriesId").get_asInt(); newTag->m_strRecordingId = m_pDS->fv("sRecordingId").get_asString().c_str(); newTag->m_strIconPath = m_pDS->fv("sIconPath").get_asString().c_str(); 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; }
int CEpgDatabase::Get(CEpg &epg) { int iReturn(-1); CSingleLock lock(m_critSection); CStdString strQuery = FormatSQL("SELECT * FROM epgtags WHERE idEpg = %u;", epg.EpgID()); 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_strGenre = m_pDS->fv("sGenre").get_asString().c_str(); 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_iEpisodeNumber = 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_iSeriesNumber = 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; }
bool CEpgContainer::DeleteEpg(const CEpg &epg, bool bDeleteFromDatabase /* = false */) { if (epg.EpgID() < 0) return false; CSingleLock lock(m_critSection); map<unsigned int, CEpg *>::iterator it = m_epgs.find((unsigned int)epg.EpgID()); if (it == m_epgs.end()) return false; if (bDeleteFromDatabase && !m_bIgnoreDbForClient && m_database.IsOpen()) m_database.Delete(*it->second); delete it->second; m_epgs.erase(it); return true; }
bool CEpgContainer::DeleteEpg(const CEpg &epg, bool bDeleteFromDatabase /* = false */) { if (epg.EpgID() < 0) return false; CSingleLock lock(m_critSection); const auto &epgEntry = m_epgs.find((unsigned int)epg.EpgID()); if (epgEntry == m_epgs.end()) return false; CLog::Log(LOGDEBUG, "deleting EPG table %s (%d)", epg.Name().c_str(), epg.EpgID()); if (bDeleteFromDatabase && !m_bIgnoreDbForClient && m_database.IsOpen()) m_database.Delete(*epgEntry->second); epgEntry->second->UnregisterObserver(this); m_epgs.erase(epgEntry); return true; }
void CPVRChannelGroupInternal::CreateChannelEpg(CPVRChannelPtr channel, bool bForce /* = false */) { if (!channel) return; CSingleLock lock(channel->m_critSection); if (!channel->m_bEPGCreated || bForce) { CEpg *epg = g_EpgContainer.CreateChannelEpg(channel); if (epg) { channel->m_bEPGCreated = true; if (epg->EpgID() != channel->m_iEpgId) { channel->m_iEpgId = epg->EpgID(); channel->m_bChanged = true; } } } }
int CEpgDatabase::Persist(const CEpg &epg, bool bQueueWrite /* = false */) { int iReturn = -1; CStdString strQuery; if (epg.EpgID() > 0) { strQuery = FormatSQL("REPLACE INTO epg (idEpg, sName, sScraperName) " "VALUES (%u, '%s', '%s');", epg.EpgID(), epg.Name().c_str(), epg.ScraperName().c_str()); } else { strQuery = FormatSQL("REPLACE INTO epg (sName, sScraperName) " "VALUES ('%s', '%s');", epg.Name().c_str(), epg.ScraperName().c_str()); } if (bQueueWrite) { if (QueueInsertQuery(strQuery)) iReturn = epg.EpgID() <= 0 ? 0 : epg.EpgID(); } else { if (ExecuteQuery(strQuery)) iReturn = epg.EpgID() <= 0 ? (int) m_pDS->lastinsertid() : epg.EpgID(); } return iReturn; }
bool CEpgDatabase::Delete(const CEpg &table, const time_t start /* = 0 */, const time_t end /* = 0 */) { /* invalid channel */ if (table.EpgID() <= 0) { CLog::Log(LOGERROR, "EpgDB - %s - invalid channel id: %d", __FUNCTION__, table.EpgID()); return false; } CStdString strWhereClause; strWhereClause = FormatSQL("idEpg = %u", table.EpgID()); if (start != 0) strWhereClause.append(FormatSQL(" AND iStartTime >= %u", start).c_str()); if (end != 0) strWhereClause.append(FormatSQL(" AND iEndTime <= %u", end).c_str()); CSingleLock lock(m_critSection); return DeleteValues("epgtags", strWhereClause); }
bool CPVRChannel::CreateEPG(bool bForce /* = false */) { CSingleLock lock(m_critSection); if (!m_bEPGCreated || bForce) { CEpg epgTmp(this, false); if (g_EpgContainer.UpdateEntry(epgTmp)) { CEpg *epg = g_EpgContainer.GetByChannel(*this); if (epg) { m_bEPGCreated = true; if (epg->EpgID() != m_iEpgId) { m_iEpgId = epg->EpgID(); m_bChanged = true; } } } } return m_bEPGCreated; }
bool CEpgContainer::UpdateEntry(const CEpg &entry, bool bUpdateDatabase /* = false */) { CEpg *epg(NULL); bool bReturn(false); WaitForUpdateFinish(true); CSingleLock lock(m_critSection); epg = entry.EpgID() > 0 ? GetById(entry.EpgID()) : NULL; if (!epg) { /* table does not exist yet, create a new one */ unsigned int iEpgId = !m_bIgnoreDbForClient ? entry.EpgID() : NextEpgId(); epg = CreateEpg(iEpgId); if (epg) InsertEpg(epg); } bReturn = epg ? epg->UpdateMetadata(entry, bUpdateDatabase) : false; m_bPreventUpdates = false; CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(m_iNextEpgUpdate); lock.Leave(); return bReturn; }
bool CEpgContainer::DeleteEpg(const CEpg &epg, bool bDeleteFromDatabase /* = false */) { bool bReturn = false; CSingleLock lock(m_critSection); for (unsigned int iEpgPtr = 0; iEpgPtr < m_epgs.size(); iEpgPtr++) { if (m_epgs[iEpgPtr]->EpgID() == epg.EpgID()) { if (bDeleteFromDatabase && !m_bIgnoreDbForClient && m_database.Open()) { m_database.Delete(*m_epgs[iEpgPtr]); m_database.Close(); } delete m_epgs[iEpgPtr]; m_epgs.erase(m_epgs.begin() + iEpgPtr); bReturn = true; break; } } return bReturn; }
bool CEpgContainer::UpdateEPG(bool bOnlyPending /* = false */) { bool bInterrupted(false); unsigned int iUpdatedTables(0); bool bShowProgress(false); /* set start and end time */ time_t start; time_t end; CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(start); end = start + m_iDisplayTime; start -= g_advancedSettings.m_iEpgLingerTime * 60; bShowProgress = g_advancedSettings.m_bEpgDisplayUpdatePopup && (m_bIsInitialising || g_advancedSettings.m_bEpgDisplayIncrementalUpdatePopup); { CSingleLock lock(m_critSection); if (m_bIsUpdating || InterruptUpdate()) return false; m_bIsUpdating = true; } if (bShowProgress && !bOnlyPending) ShowProgressDialog(); if (!m_bIgnoreDbForClient && !m_database.IsOpen()) { CLog::Log(LOGERROR, "EpgContainer - %s - could not open the database", __FUNCTION__); CSingleLock lock(m_critSection); m_bIsUpdating = false; m_updateEvent.Set(); if (bShowProgress && !bOnlyPending) CloseProgressDialog(); return false; } vector<CEpg*> invalidTables; /* load or update all EPG tables */ CEpg *epg; unsigned int iCounter(0); for (map<unsigned int, CEpg *>::iterator it = m_epgs.begin(); it != m_epgs.end(); it++) { if (InterruptUpdate()) { bInterrupted = true; break; } epg = it->second; if (!epg) continue; if (bShowProgress && !bOnlyPending) UpdateProgressDialog(++iCounter, m_epgs.size(), epg->Name()); // we currently only support update via pvr add-ons. skip update when the pvr manager isn't started if (!g_PVRManager.IsStarted()) continue; // check the pvr manager when the channel pointer isn't set if (!epg->Channel()) { CPVRChannelPtr channel = g_PVRChannelGroups->GetChannelByEpgId(epg->EpgID()); if (channel) epg->SetChannel(channel); } if ((!bOnlyPending || epg->UpdatePending()) && epg->Update(start, end, m_iUpdateTime, bOnlyPending)) iUpdatedTables++; else if (!epg->IsValid()) invalidTables.push_back(epg); } for (vector<CEpg*>::iterator it = invalidTables.begin(); it != invalidTables.end(); it++) DeleteEpg(**it, true); if (bInterrupted) { /* the update has been interrupted. try again later */ time_t iNow; CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(iNow); m_iNextEpgUpdate = iNow + g_advancedSettings.m_iEpgRetryInterruptedUpdateInterval; } else { CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(m_iNextEpgUpdate); m_iNextEpgUpdate += g_advancedSettings.m_iEpgUpdateCheckInterval; m_bHasPendingUpdates = false; } if (bShowProgress && !bOnlyPending) CloseProgressDialog(); /* notify observers */ if (iUpdatedTables > 0) { SetChanged(); NotifyObservers(ObservableMessageEpgContainer); } CSingleLock lock(m_critSection); m_bIsUpdating = false; m_updateEvent.Set(); return !bInterrupted; }