From 6f14ddae8a91feed5272cd475f320bf9a9ca9214 Mon Sep 17 00:00:00 2001 From: kamel5 Date: Mon, 13 Jul 2020 11:49:21 +0200 Subject: Refactor reruns --- coreengine/viewdetail.c | 117 +++++++++++++++++++++++------------------------- coreengine/viewdetail.h | 3 +- 2 files changed, 56 insertions(+), 64 deletions(-) (limited to 'coreengine') diff --git a/coreengine/viewdetail.c b/coreengine/viewdetail.c index 0bb8555..db9cbc1 100644 --- a/coreengine/viewdetail.c +++ b/coreengine/viewdetail.c @@ -353,13 +353,15 @@ bool cViewDetailEpg::Parse(bool forced) { tokenContainer->AddIntToken((int)eDmDetailedEpgIT::year, sStartTime->tm_year + 1900); tokenContainer->AddIntToken((int)eDmDetailedEpgIT::daynumeric, sStartTime->tm_mday); tokenContainer->AddIntToken((int)eDmDetailedEpgIT::month, sStartTime->tm_mon+1); + const cChannel* channel = NULL; #if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + { LOCK_CHANNELS_READ; - const cChannels* channels = Channels; + channel = Channels->GetByChannelID(event->ChannelID()); + } #else - cChannels* channels = &Channels; + channel = Channels.GetByChannelID(event->ChannelID()); #endif - const cChannel *channel = channels->GetByChannelID(event->ChannelID()); if (channel) { tokenContainer->AddStringToken((int)eDmDetailedEpgST::channelname, channel->Name()); tokenContainer->AddIntToken((int)eDmDetailedEpgIT::channelnumber, channel->Number()); @@ -385,7 +387,10 @@ bool cViewDetailEpg::Parse(bool forced) { tokenContainer->AddStringToken((int)eDmDetailedEpgST::vps, *event->GetVpsString()); cList *reruns = LoadReruns(); - int numReruns = NumReruns(reruns); + int numReruns = 0; + if (reruns && reruns->Count() > 0) + numReruns = reruns->Count(); + vector loopInfo; //num reruns loopInfo.push_back(numReruns); @@ -395,7 +400,7 @@ bool cViewDetailEpg::Parse(bool forced) { loopInfo.push_back(numActors); tokenContainer->CreateLoopTokenContainer(&loopInfo); if (numReruns > 0) { - tokenContainer->AddIntToken((int)eDmDetailedEpgIT::hasreruns, 1); + tokenContainer->AddIntToken((int)eDmDetailedEpgIT::hasreruns, numReruns); SetReruns(reruns); } if (scrapInfoAvailable) { @@ -411,88 +416,75 @@ cList *cViewDetailEpg::LoadR if (!epgSearchPlugin) return NULL; - if (isempty(event->Title())) + if (!event || isempty(event->Title())) return NULL; Epgsearch_searchresults_v1_0 data; - data.query = (char*)event->Title(); + std::string strQuery = event->Title(); + + if (config.useSubtitleRerun && !isempty(event->ShortText())) { + strQuery += "~"; + strQuery += event->ShortText(); + } + + data.query = (char *)strQuery.c_str(); data.mode = 0; data.channelNr = 0; data.useTitle = true; data.useSubTitle = true; data.useDescription = false; - cList *result = NULL; - if (epgSearchPlugin->Service("Epgsearch-searchresults-v1.0", &data)) - result = data.pResultList; - return result; -} - -int cViewDetailEpg::NumReruns(cList *reruns) { - if (!reruns || reruns->Count() < 2) - return 0; - int maxNumReruns = config.rerunAmount; int rerunDistance = config.rerunDistance * 3600; int rerunMaxChannel = config.rerunMaxChannel; int i = 0; - for (Epgsearch_searchresults_v1_0::cServiceSearchResult *r = reruns->First(); r && i < maxNumReruns; r = reruns->Next(r)) { - time_t eventStart = event->StartTime(); - time_t rerunStart = r->event->StartTime(); + + cList *reruns = NULL; + if (epgSearchPlugin->Service("Epgsearch-searchresults-v1.0", &data)) { + cList *result = data.pResultList; + if (result) { + for (Epgsearch_searchresults_v1_0::cServiceSearchResult *r = result->First(); r && i < maxNumReruns; r = result->Next(r)) { + time_t eventStart = event->StartTime(); + time_t rerunStart = r->event->StartTime(); #if defined (APIVERSNUM) && (APIVERSNUM >= 20301) - LOCK_CHANNELS_READ; - const cChannels* channels = Channels; + LOCK_CHANNELS_READ; + const cChannel *channel = Channels->GetByChannelID(r->event->ChannelID(), true, true); #else - cChannels* channels = &Channels; + const cChannel *channel = Channels.GetByChannelID(r->event->ChannelID(), true, true); #endif - const cChannel *channel = channels->GetByChannelID(r->event->ChannelID(), true, true); - //check for identical event - if ((event->ChannelID() == r->event->ChannelID()) && (eventStart == rerunStart)) - continue; - //check for timely distance - if (rerunDistance > 0) - if (rerunStart - eventStart < rerunDistance) - continue; - //check for maxchannel - if (rerunMaxChannel > 0) - if (channel && channel->Number() > rerunMaxChannel) - continue; - i++; + //check for identical event + if ((event->ChannelID() == r->event->ChannelID()) && (eventStart == rerunStart)) + continue; + //check for timely distance + if (rerunDistance > 0) + if (rerunStart - eventStart < rerunDistance) + continue; + //check for maxchannel + if (rerunMaxChannel > 0) + if (channel && channel->Number() > rerunMaxChannel) + continue; + if (!reruns) reruns = new cList; + reruns->Add(r); + i++; + } + } } - return i; + return reruns; } void cViewDetailEpg::SetReruns(cList *reruns) { - if (!reruns || reruns->Count() < 2) + if (!reruns || reruns->Count() < 1) return; - int maxNumReruns = config.rerunAmount; - int rerunDistance = config.rerunDistance * 3600; - int rerunMaxChannel = config.rerunMaxChannel; - int i = 0; - for (Epgsearch_searchresults_v1_0::cServiceSearchResult *r = reruns->First(); r && i < maxNumReruns; r = reruns->Next(r)) { - time_t eventStart = event->StartTime(); - time_t rerunStart = r->event->StartTime(); + for (Epgsearch_searchresults_v1_0::cServiceSearchResult *r = reruns->First(); r; r = reruns->Next(r)) { #if defined (APIVERSNUM) && (APIVERSNUM >= 20301) LOCK_CHANNELS_READ; - const cChannels* channels = Channels; + const cChannel *channel = Channels->GetByChannelID(r->event->ChannelID(), true, true); #else - cChannels* channels = &Channels; + const cChannel *channel = Channels.GetByChannelID(r->event->ChannelID(), true, true); #endif - const cChannel *channel = channels->GetByChannelID(r->event->ChannelID(), true, true); - //check for identical event - if ((event->ChannelID() == r->event->ChannelID()) && (eventStart == rerunStart)) - continue; - //check for timely distance - if (rerunDistance > 0) - if (rerunStart - eventStart < rerunDistance) - continue; - //check for maxchannel - if (rerunMaxChannel > 0) - if (channel && channel->Number() > rerunMaxChannel) - continue; tokenContainer->AddLoopToken(rerunsIndex, i, (int)eRerunsLT::title, r->event->Title()); tokenContainer->AddLoopToken(rerunsIndex, i, (int)eRerunsLT::shorttext, r->event->ShortText()); tokenContainer->AddLoopToken(rerunsIndex, i, (int)eRerunsLT::start, *(r->event->GetTimeString())); @@ -511,6 +503,8 @@ void cViewDetailEpg::SetReruns(cListAddLoopToken(rerunsIndex, i, (int)eRerunsLT::channelname, ""); tokenContainer->AddLoopToken(rerunsIndex, i, (int)eRerunsLT::channelnumber, ""); } + if (r == reruns->Last()) + break; i++; } } @@ -812,11 +806,10 @@ void cViewDetailRec::SetRecInfos(void) { if (info) { #if defined (APIVERSNUM) && (APIVERSNUM >= 20301) LOCK_CHANNELS_READ; - const cChannels* channels = Channels; + const cChannel *channel = Channels->GetByChannelID(info->ChannelID()); #else - cChannels* channels = &Channels; + const cChannel *channel = Channels.GetByChannelID(info->ChannelID()); #endif - const cChannel *channel = channels->GetByChannelID(info->ChannelID()); if (channel) { tokenContainer->AddStringToken((int)eDmDetailedRecST::recchannelname, channel->Name()); tokenContainer->AddStringToken((int)eDmDetailedRecST::recchannelid, *channel->GetChannelID().ToString()); diff --git a/coreengine/viewdetail.h b/coreengine/viewdetail.h index 0d53a5a..25e558b 100644 --- a/coreengine/viewdetail.h +++ b/coreengine/viewdetail.h @@ -44,7 +44,6 @@ protected: int rerunsIndex; int actorsIndex; cList *LoadReruns(void); - int NumReruns(cList *reruns); void SetReruns(cList *reruns); void SetEpgPictures(int eventId); public: @@ -112,4 +111,4 @@ public: void Set(skindesignerapi::cTokenContainer *tk); bool Parse(bool forced = false); }; -#endif //__VIEWDETAIL_H \ No newline at end of file +#endif //__VIEWDETAIL_H -- cgit v1.2.3