diff --git a/src/PVRFreeboxData.cpp b/src/PVRFreeboxData.cpp index 8a41ebf..8393c78 100644 --- a/src/PVRFreeboxData.cpp +++ b/src/PVRFreeboxData.cpp @@ -254,10 +254,10 @@ bool PVRFreeboxData::ReadJSON (Document * doc, const string & url) return false; } -PVRFreeboxData::Event::Event (const Value & e, unsigned int channel) : +PVRFreeboxData::Event::Event (const Value & e, unsigned int channel, time_t date) : channel (channel), uuid (JSON (e, "id")), - date (JSON (e, "date")), + date (JSON (e, "date", date)), duration (JSON (e, "duration")), title (JSON (e, "title")), subtitle (JSON (e, "sub_title")), @@ -307,8 +307,8 @@ bool PVRFreeboxData::ProcessChannels () Conflict c (uuid, major, minor, i); - channels_by_uuid [uuid] .push_back (c); - channels_by_major[major].push_back (c); + conflicts_by_uuid [uuid] .push_back (c); + conflicts_by_major[major].push_back (c); } static const ConflictComparator comparator; @@ -383,7 +383,6 @@ PVRFreeboxData::PVRFreeboxData (const string & path, m_tv_quality (Quality (quality)), m_epg_queries (), m_epg_cache (), - m_epg_events (), m_epg_days (0), m_epg_last (0), m_epg_extended (extended) @@ -486,43 +485,21 @@ void PVRFreeboxData::ProcessEvent (const Event & e, EPG_EVENT_STATE state) PVR->EpgEventStateChange (&tag, state); } -void PVRFreeboxData::ProcessEvent (const Value & event, unsigned int channel, EPG_EVENT_STATE state) +void PVRFreeboxData::ProcessEvent (const Value & event, unsigned int channel, time_t date, EPG_EVENT_STATE state) { - switch (state) - { - case EPG_EVENT_CREATED: - { - Event e (event, channel); - { - P8PLATFORM::CLockObject lock (m_mutex); - if (m_epg_extended) - { - string query = "/api/v5/tv/epg/programs/" + e.uuid; - m_epg_events.insert (make_pair (e.uuid, e)); - m_epg_queries.push (Query (EVENT, URL (query), channel)); - //XBMC->Log (LOG_INFO, "Queued: '%s'", query.c_str ()); - } - } - ProcessEvent (e, EPG_EVENT_CREATED); - break; - } + Event e (event, channel, date); - case EPG_EVENT_UPDATED: + if (state == EPG_EVENT_CREATED) + { + P8PLATFORM::CLockObject lock (m_mutex); + if (m_epg_extended) { - Event e (event, channel); - { - P8PLATFORM::CLockObject lock (m_mutex); - auto f = m_epg_events.find (e.uuid); - if (f != m_epg_events.end ()) - { - e.date = f->second.date; // !!! - m_epg_events.erase (f); - } - } - ProcessEvent (e, EPG_EVENT_UPDATED); - break; + string query = "/api/v5/tv/epg/programs/" + e.uuid; + m_epg_queries.push (Query (EVENT, URL (query), channel, date)); } } + + ProcessEvent (e, state); } void PVRFreeboxData::ProcessChannel (const Value & epg, unsigned int channel) @@ -530,7 +507,9 @@ void PVRFreeboxData::ProcessChannel (const Value & epg, unsigned int channel) for (auto i = epg.MemberBegin (); i != epg.MemberEnd (); ++i) { const Value & event = i->value; + string uuid = JSON (event, "id"); + time_t date = JSON (event, "date"); static const string PREFIX = "pluri_"; if (uuid.find (PREFIX) != 0) continue; @@ -542,7 +521,7 @@ void PVRFreeboxData::ProcessChannel (const Value & epg, unsigned int channel) if (m_epg_cache.count (query) > 0) continue; } - ProcessEvent (event, channel, EPG_EVENT_CREATED); + ProcessEvent (event, channel, date, EPG_EVENT_CREATED); { P8PLATFORM::CLockObject lock (m_mutex); @@ -614,11 +593,16 @@ void * PVRFreeboxData::Process () { case FULL : ProcessFull (r); break; case CHANNEL : ProcessChannel (r, q.channel); break; - case EVENT : ProcessEvent (r, q.channel, EPG_EVENT_UPDATED); break; + case EVENT : ProcessEvent (r, q.channel, q.date, EPG_EVENT_UPDATED); break; } } } } + else + { + P8PLATFORM::CLockObject lock (m_mutex); + m_epg_cache.clear (); + } Sleep (delay * 1000); } diff --git a/src/PVRFreeboxData.h b/src/PVRFreeboxData.h index 757aebc..4451a24 100644 --- a/src/PVRFreeboxData.h +++ b/src/PVRFreeboxData.h @@ -93,12 +93,21 @@ class PVRFreeboxData : QueryType type; std::string query; unsigned int channel; + time_t date; public: Query () : type (NONE) {} - Query (QueryType t, const std::string & q, unsigned int c = 0) : - type (t), query (q), channel (c) {} + Query (QueryType t, + const std::string & q, + unsigned int c = 0, + time_t d = 0) : + type (t), + query (q), + channel (c), + date (d) + { + } }; // EPG events. @@ -119,7 +128,7 @@ class PVRFreeboxData : std::string outline; public: - Event (const rapidjson::Value &, unsigned int channel); + Event (const rapidjson::Value &, unsigned int channel, time_t date); }; public: @@ -154,7 +163,7 @@ class PVRFreeboxData : // Process JSON EPG. void ProcessFull (const rapidjson::Value & epg); void ProcessChannel (const rapidjson::Value & epg, unsigned int channel); - void ProcessEvent (const rapidjson::Value & epg, unsigned int channel, EPG_EVENT_STATE); + void ProcessEvent (const rapidjson::Value & epg, unsigned int channel, time_t, EPG_EVENT_STATE); // If /api/v5/tv/epg/programs/* queries had a "date", things would be *way* easier! void ProcessEvent (const Event &, EPG_EVENT_STATE); @@ -181,7 +190,6 @@ class PVRFreeboxData : enum Quality m_tv_quality; std::queue m_epg_queries; std::set m_epg_cache; - std::map m_epg_events; int m_epg_days; time_t m_epg_last; bool m_epg_extended;