Esempio n. 1
0
bool CEpg::FixOverlappingEvents(bool bStore /* = true */)
{
  bool bReturn = false;
  CEpgDatabase *database = NULL;

  if (bStore)
  {
    database = g_EpgContainer.GetDatabase();

    if (!database || !database->Open())
    {
      CLog::Log(LOGERROR, "EPG - %s - could not open the database", __FUNCTION__);
      return bReturn;
    }
  }

  bReturn = true;
  CEpgInfoTag *previousTag = NULL;

  CSingleLock lock(m_critSection);

  for (unsigned int ptr = 0; ptr < size(); ptr++)
  {
    /* skip the first entry or if previousTag is NULL */
    if (previousTag == NULL)
    {
      previousTag = at(ptr);
      continue;
    }

    CEpgInfoTag *currentTag = at(ptr);

    /* the previous tag ends after the current tag starts.
     * the start time of the current tag is leading, so change the time of the previous tag
     */
    if (previousTag->End() > currentTag->Start())
    {
      CLog::Log(LOGDEBUG, "EPG - %s - event '%s' ends after event '%s' starts. changing the end time of '%s' to the start time of '%s': '%s'",
          __FUNCTION__, previousTag->Title().c_str(), currentTag->Title().c_str(),
          previousTag->Title().c_str(), currentTag->Title().c_str(),
          currentTag->Start().GetAsLocalizedDateTime(false, false).c_str());

      previousTag->SetEnd(currentTag->Start());

      if (bStore)
        bReturn = previousTag->Persist(false, false) && bReturn;
    }

    previousTag = at(ptr);
  }

  return bReturn;
}
Esempio n. 2
0
void CEpg::Cleanup(const CDateTime &Time)
{
  CSingleLock lock(m_critSection);

  unsigned int iSize = size();
  for (unsigned int iTagPtr = 0; iTagPtr < iSize; iTagPtr++)
  {
    CEpgInfoTag *tag = at(iTagPtr);
    if ( tag && /* valid tag */
        (tag->End() + CDateTimeSpan(0, g_advancedSettings.m_iEpgLingerTime / 60, g_advancedSettings.m_iEpgLingerTime % 60, 0) < Time))
    {
      erase(begin() + iTagPtr);
      --iSize;
      --iTagPtr;
    }
  }
}
Esempio n. 3
0
const CEpgInfoTag *CEpg::InfoTagAround(CDateTime Time) const
{
  CEpgInfoTag *returnTag = NULL;

  CSingleLock lock(m_critSection);

  for (unsigned int iTagPtr = 0; iTagPtr < size(); iTagPtr++)
  {
    CEpgInfoTag *tag = at(iTagPtr);
    if ((tag->Start() <= Time) && (tag->End() >= Time))
    {
      returnTag = tag;
      break;
    }
  }

  return returnTag;
}
Esempio n. 4
0
const CEpgInfoTag *CEpg::InfoTagBetween(CDateTime BeginTime, CDateTime EndTime) const
{
  CEpgInfoTag *returnTag = NULL;

  CSingleLock lock(m_critSection);

  for (unsigned int iTagPtr = 0; iTagPtr < size(); iTagPtr++)
  {
    CEpgInfoTag *tag = at(iTagPtr);
    if (tag->Start() >= BeginTime && tag->End() <= EndTime)
    {
      returnTag = tag;
      break;
    }
  }

  return returnTag;
}
Esempio n. 5
0
const CEpgInfoTag *CEpg::InfoTagNow(void) const
{
  CSingleLock lock(m_critSection);

  if (!m_nowActive || !m_nowActive->IsActive())
  {
    CDateTime now = CDateTime::GetCurrentDateTime();
    /* one of the first items will always match if the list is sorted */
    for (unsigned int iTagPtr = 0; iTagPtr < size(); iTagPtr++)
    {
      CEpgInfoTag *tag = at(iTagPtr);
      if (tag->Start() <= now && tag->End() > now)
      {
        m_nowActive = tag;
        break;
      }
    }
  }

  return m_nowActive;
}
Esempio n. 6
0
int CEpgDatabase::Persist(const CEpgInfoTag &tag, bool bSingleUpdate /* = true */, bool bLastUpdate /* = false */)
{
  int iReturn = -1;

  const CEpg *epg = tag.GetTable();
  if (!epg || epg->EpgID() <= 0)
  {
    CLog::Log(LOGERROR, "%s - tag '%s' does not have a valid table", __FUNCTION__, tag.Title().c_str());
    return iReturn;
  }

  time_t iStartTime, iEndTime, iFirstAired;
  tag.Start().GetAsTime(iStartTime);
  tag.End().GetAsTime(iEndTime);
  tag.FirstAired().GetAsTime(iFirstAired);
  int iEpgId = epg->EpgID();

  int iBroadcastId = tag.BroadcastId();
  if (iBroadcastId <= 0)
  {
    CStdString strWhereClause;
    if (tag.UniqueBroadcastID() > 0)
    {
      strWhereClause = FormatSQL("(iBroadcastUid = '%u' OR iStartTime = %u) AND idEpg = %u",
          tag.UniqueBroadcastID(), iStartTime, iEpgId);
    }
    else
    {
      strWhereClause = FormatSQL("iStartTime = %u AND idEpg = '%u'",
          iStartTime, iEpgId);
    }
    CStdString strValue = GetSingleValue("epgtags", "idBroadcast", strWhereClause);

    if (!strValue.IsEmpty())
      iBroadcastId = atoi(strValue);
  }

  CStdString strQuery;

  if (iBroadcastId < 0)
  {
    strQuery = FormatSQL("INSERT INTO epgtags (idEpg, iStartTime, "
        "iEndTime, sTitle, sPlotOutline, sPlot, iGenreType, iGenreSubType, "
        "iFirstAired, iParentalRating, iStarRating, bNotify, iSeriesId, "
        "iEpisodeId, iEpisodePart, sEpisodeName, iBroadcastUid) "
        "VALUES (%u, %u, %u, '%s', '%s', '%s', %i, %i, %u, %i, %i, %i, %i, %i, %i, '%s', %i);",
        iEpgId, iStartTime, iEndTime,
        tag.Title().c_str(), tag.PlotOutline().c_str(), tag.Plot().c_str(), tag.GenreType(), tag.GenreSubType(),
        iFirstAired, tag.ParentalRating(), tag.StarRating(), tag.Notify(),
        tag.SeriesNum(), tag.EpisodeNum(), tag.EpisodePart(), tag.EpisodeName().c_str(),
        tag.UniqueBroadcastID());
  }
  else
  {
    strQuery = FormatSQL("REPLACE INTO epgtags (idEpg, iStartTime, "
        "iEndTime, sTitle, sPlotOutline, sPlot, iGenreType, iGenreSubType, "
        "iFirstAired, iParentalRating, iStarRating, bNotify, iSeriesId, "
        "iEpisodeId, iEpisodePart, sEpisodeName, iBroadcastUid, idBroadcast) "
        "VALUES (%u, %u, %u, '%s', '%s', '%s', %i, %i, %u, %i, %i, %i, %i, %i, %i, '%s', %i, %i);",
        iEpgId, iStartTime, iEndTime,
        tag.Title().c_str(), tag.PlotOutline().c_str(), tag.Plot().c_str(), tag.GenreType(), tag.GenreSubType(),
        tag.FirstAired().GetAsDBDateTime().c_str(), tag.ParentalRating(), tag.StarRating(), tag.Notify(),
        tag.SeriesNum(), tag.EpisodeNum(), tag.EpisodePart(), tag.EpisodeName().c_str(),
        tag.UniqueBroadcastID(), iBroadcastId);
  }

  if (bSingleUpdate)
  {
    if (ExecuteQuery(strQuery))
      iReturn = m_pDS->lastinsertid();
  }
  else
  {
    QueueInsertQuery(strQuery);

    if (bLastUpdate)
      CommitInsertQueries();

    iReturn = 0;
  }

  return iReturn;
}