]> git.vomp.tv Git - jsonserver.git/commitdiff
Add download-all-EPG call
authorChris Tallon <chris@vomp.tv>
Sun, 2 Jul 2017 19:39:45 +0000 (20:39 +0100)
committerChris Tallon <chris@vomp.tv>
Sun, 2 Jul 2017 19:39:45 +0000 (20:39 +0100)
handler.c
handler.h

index 1876f41912c4b31bad0b29f86d14dbdc77a08330..cb2acce343aa01fb33834d95425713ceca52954c 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -88,6 +88,7 @@ int jsonserver_request_handler(struct mg_connection *conn)
   else if (!strcmp(wvrequest, "timeredit")) success = jsonserver_timeredit(js, postData);
   else if (!strcmp(wvrequest, "tunersstatus")) success = jsonserver_tunersstatus(js, postData);
   else if (!strcmp(wvrequest, "epgsearchsame")) success = jsonserver_epgsearchsame(js, postData);
+  else if (!strcmp(wvrequest, "epgdownload")) success = jsonserver_epgdownload(js, postData);
 
   if (!success) return 0; // the specific handler failed badly
 
@@ -1699,3 +1700,50 @@ bool jsonserver_epgsearchsame(Json::Value& js, const char* postData)
   js["Result"] = true;
   return true;
 }
+
+bool jsonserver_epgdownload(Json::Value& js, const char* postData)
+{
+  Log* log = Log::getInstance();
+  log->log("JSONServer", Log::DEBUG, "channelschedule '%s'", postData);
+
+  cSchedulesLock MutexLock;
+  const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
+
+  if (!Schedules)
+  {
+    log->log("JSONServer", Log::ERR, "Could not get Schedules object");
+    js["Result"] = false;
+    js["Error"] = "Internal schedules error (1)";
+    return true;
+  }
+
+  Json::Value jsevents(Json::arrayValue);
+
+  for (cChannel* channel = Channels.First(); channel; channel = Channels.Next(channel))
+  {
+    if (channel->GroupSep()) continue;
+
+    const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
+    if (!Schedule) continue;
+
+
+    for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
+    {
+      Json::Value oneEvent;
+      oneEvent["ChannelNumber"] = channel->Number();
+      oneEvent["ChannelID"] = (const char*)event->ChannelID().ToString();
+      oneEvent["ID"] = event->EventID();
+      oneEvent["Time"] = (Json::UInt)event->StartTime();
+      oneEvent["Duration"] = event->Duration();
+      oneEvent["Title"] = event->Title() ? event->Title() : "";
+      oneEvent["ShortText"] = event->ShortText() ? event->ShortText() : "";
+      oneEvent["HasTimer"] = event->HasTimer();
+      oneEvent["Description"] = event->Description() ? event->Description() : "";
+      jsevents.append(oneEvent);
+    }
+  }
+
+  js["Result"] = true;
+  js["Events"] = jsevents;
+  return true;
+}
index f7e1f57b3d02e9ba0f82731556636236f66c35a4..c7836b85f74b0105e522da62425f029e1de577b1 100644 (file)
--- a/handler.h
+++ b/handler.h
@@ -29,6 +29,7 @@ bool jsonserver_timerisrecording(Json::Value& js, const char* postData);
 bool jsonserver_timeredit(Json::Value& js, const char* postData);
 bool jsonserver_tunersstatus(Json::Value& js, const char* postData);
 bool jsonserver_epgsearchsame(Json::Value& js, const char* postData);
+bool jsonserver_epgdownload(Json::Value& js, const char* postData);
 
 const cEvent* jsonserver_getEvent(Json::Value& js, int channelNumber, int eventID, int aroundTime);
 cTimer* jsonserver_findTimer(const char* rChannelID, const char* rName, const char* rStartTime, const char* rStopTime, const char* rWeekDays);