]> git.vomp.tv Git - jsonserver.git/commitdiff
Fill out get rec info call
authorChris Tallon <chris@vomp.tv>
Wed, 3 Apr 2013 18:41:34 +0000 (19:41 +0100)
committerChris Tallon <chris@vomp.tv>
Wed, 3 Apr 2013 18:41:34 +0000 (19:41 +0100)
handler.c

index 6076d6c2a7286c4fe54e1acdc1223c8082bb8396..973dbf95e3693e14b3aa6ee5c69c7484a06eda7b 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -60,6 +60,7 @@ int jsonserver_request_handler(struct mg_connection *conn)
         log->log("JSONServer", Log::DEBUG, "Could not read up to contentLength");
         return 0;
       }
+      postData[contentLengthI] = '\0';
     }
   }
 
@@ -155,8 +156,6 @@ bool jsonserver_reclist(Json::Value& js)
 
 bool jsonserver_recinfo(Json::Value& js, const char* postData)
 {
-  // For now this returns just the string summary of the recording
-
   Log* log = Log::getInstance();
   log->log("JSONServer", Log::DEBUG, "recinfo");
 
@@ -176,21 +175,69 @@ bool jsonserver_recinfo(Json::Value& js, const char* postData)
   Recordings.Load(); // probably have to do this
   cRecording *recording = Recordings.GetByName(reqfilename);
 
-  if (recording)
-  {
-    const cRecordingInfo *Info = recording->Info();
-    char* summary = (char*)Info->ShortText();
-    if (isempty(summary)) summary = (char*)Info->Description();
-    js["Result"] = true;
-    js["Summary"] = summary;
-  }
-  else
+  if (!recording)
   {
     log->log("JSONServer", Log::ERR, "recinfo found no recording");
     js["Result"] = false;
-    js["Summary"] = "";
-  }  
+    return true;
+  }
+
+  js["IsNew"] = recording->IsNew();
+  js["LengthInSeconds"] = recording->LengthInSeconds();
+  js["FileSizeMB"] = recording->FileSizeMB();
+  js["Name"] = recording->Name() ? recording->Name() : Json::Value::null;
+  js["Priority"] = recording->Priority();
+  js["LifeTime"] = recording->Lifetime();
+  js["Start"] = (Json::UInt)recording->Start();
+
+  js["ResumePoint"] = 0;
+  cResumeFile ResumeFile(recording->FileName(), recording->IsPesRecording());
+  if (ResumeFile.Read() >= 0) js["ResumePoint"] = ResumeFile.Read();
+
+  js["CurrentlyRecordingStart"] = 0;
+  js["CurrentlyRecordingStop"] = 0;
+  cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
+  if (rc)
+  {
+    js["CurrentlyRecordingStart"] = (Json::UInt)rc->Timer()->StartTime();
+    js["CurrentlyRecordingStop"] = (Json::UInt)rc->Timer()->StopTime();
+  }
 
+  const cRecordingInfo *info = recording->Info();
+  if (info)
+  {
+    js["ChannelName"] = info->ChannelName() ? info->ChannelName() : Json::Value::null;
+    js["Title"] = info->Title() ? info->Title() : Json::Value::null;
+    js["ShortText"] = info->ShortText() ? info->ShortText() : Json::Value::null;
+    js["Description"] = info->Description() ? info->Description() : Json::Value::null;
+
+    const cComponents* components = info->Components();
+    if (!components)
+    {
+      js["Components"] = Json::Value::null;
+    }
+    else
+    {
+      Json::Value jscomponents;
+
+      tComponent* component;
+      for (int i = 0; i < components->NumComponents(); i++)
+      {
+        component = components->Component(i);
+
+        Json::Value oneComponent;
+        oneComponent["Stream"] = component->stream;
+        oneComponent["Type"] = component->type;
+        oneComponent["Language"] = component->language ? component->language : Json::Value::null;
+        oneComponent["Description"] = component->description ? component->description : Json::Value::null;
+        jscomponents.append(oneComponent);
+      }
+
+      js["Components"] = jscomponents;
+    }
+  }
+
+  js["Result"] = true;
   return true;
 }