17 #include <vdr/plugin.h>
18 #include <vdr/videodir.h>
19 #include <vdr/recording.h>
21 #include <vdr/timers.h>
22 #include <vdr/channels.h>
24 /* Locking information from VDR:
25 + If a plugin needs to access several of the global lists in parallel, locking must
26 always be done in the sequence Timers, Channels, Recordings, Schedules.
29 VDRClient::VDRClient(const std::string& _configDir)
30 : configDir(_configDir)
32 logger = spd::get("jsonserver_spdlog");
35 VDRClient::~VDRClient()
37 logger->debug("VDRClient destructor");
40 bool VDRClient::process(std::string& request, PFMap& postFields, std::string& returnString)
42 Json::Value returnJSON;
47 if (request == "gettime") success = gettime(postFields, returnJSON);
48 else if (request == "diskstats") success = diskstats(postFields, returnJSON);
49 else if (request == "channellist") success = channellist(postFields, returnJSON);
50 else if (request == "reclist") success = reclist(postFields, returnJSON);
51 else if (request == "timerlist") success = timerlist(postFields, returnJSON);
52 else if (request == "epgdownload") success = epgdownload(postFields, returnJSON);
53 else if (request == "tunersstatus") success = tunersstatus(postFields, returnJSON);
54 else if (request == "epgfilterget") success = epgfilterget(postFields, returnJSON);
56 else if (request == "channelschedule") success = channelschedule(postFields, returnJSON);
57 else if (request == "getscheduleevent") success = getscheduleevent(postFields, returnJSON);
58 else if (request == "epgsearch") success = epgsearch(postFields, returnJSON);
59 else if (request == "epgsearchsame") success = epgsearchsame(postFields, returnJSON);
60 else if (request == "epgsearchotherhalf")success = epgsearchotherhalf(postFields, returnJSON);
61 else if (request == "timerset") success = timerset(postFields, returnJSON);
62 else if (request == "recinfo") success = recinfo(postFields, returnJSON);
63 else if (request == "recstop") success = recstop(postFields, returnJSON);
64 else if (request == "recdel") success = recdel(postFields, returnJSON);
65 else if (request == "recrename") success = recrename(postFields, returnJSON);
66 else if (request == "recmove") success = recmove(postFields, returnJSON);
67 else if (request == "timersetactive") success = timersetactive(postFields, returnJSON);
68 else if (request == "timerdel") success = timerdel(postFields, returnJSON);
69 else if (request == "timerisrecording") success = timerisrecording(postFields, returnJSON);
70 else if (request == "recresetresume") success = recresetresume(postFields, returnJSON);
71 else if (request == "timeredit") success = timeredit(postFields, returnJSON);
72 else if (request == "epgfilteradd") success = epgfilteradd(postFields, returnJSON);
73 else if (request == "epgfilterdel") success = epgfilterdel(postFields, returnJSON);
75 catch (const BadParamException& e)
77 logger->error("Bad parameter in call, paramName: {}", e.param);
78 returnJSON["Result"] = false;
79 returnJSON["Error"] = "Bad request parameter";
80 returnJSON["Detail"] = e.param;
84 if (!success) return false;
86 Json::StyledWriter sw;
87 returnString = sw.write(returnJSON);
88 logger->debug("Done sw write");
92 bool VDRClient::gettime(PFMap& postFields, Json::Value& js)
94 logger->debug("get_time");
97 gettimeofday(&tv, NULL);
99 js["Time"] = (Json::UInt64)tv.tv_sec;
100 js["MTime"] = (Json::UInt)(tv.tv_usec/1000);
105 bool VDRClient::diskstats(PFMap& postFields, Json::Value& js)
107 logger->debug("diskstats");
111 int Percent = cVideoDirectory::VideoDiskSpace(&FreeMB, &UsedMB);
113 js["FreeMiB"] = FreeMB;
114 js["UsedMiB"] = UsedMB;
115 js["Percent"] = Percent;
120 bool VDRClient::channellist(PFMap& postFields, Json::Value& js)
122 logger->debug("channellist");
124 Json::Value jschannels(Json::arrayValue);
128 for (const cChannel *channel = Channels->First(); channel; channel = Channels->Next(channel))
130 if (!channel->GroupSep())
132 Json::Value oneChannel;
133 oneChannel["ID"] = (const char *)channel->GetChannelID().ToString();
134 oneChannel["Number"] = channel->Number();
135 oneChannel["Name"] = channel->Name();
136 jschannels.append(oneChannel);
139 js["Channels"] = jschannels;
144 bool VDRClient::reclist(PFMap& postFields, Json::Value& js)
146 logger->debug("reclist");
148 Json::Value jsrecordings(Json::arrayValue);
150 LOCK_RECORDINGS_READ;
152 for (const cRecording *recording = Recordings->First(); recording; recording = Recordings->Next(recording))
155 oneRec["StartTime"] = (Json::UInt)recording->Start();
156 oneRec["Length"] = (Json::UInt)recording->LengthInSeconds();
157 oneRec["IsNew"] = recording->IsNew();
158 oneRec["Name"] = recording->Name();
159 oneRec["Filename"] = recording->FileName();
160 oneRec["FileSizeMB"] = recording->FileSizeMB();
162 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
163 if (rc) oneRec["CurrentlyRecording"] = true;
164 else oneRec["CurrentlyRecording"] = false;
166 jsrecordings.append(oneRec);
168 js["Recordings"] = jsrecordings;
173 bool VDRClient::timerlist(PFMap& postFields, Json::Value& js)
175 logger->debug("timerlist");
177 Json::Value jstimers(Json::arrayValue);
185 int numTimers = Timers->Count();
187 for (int i = 0; i < numTimers; i++)
189 timer = Timers->Get(i);
190 Json::Value oneTimer;
191 oneTimer["Active"] = timer->HasFlags(tfActive);
192 oneTimer["Recording"] = timer->Recording();
193 oneTimer["Pending"] = timer->Pending();
194 oneTimer["Priority"] = timer->Priority();
195 oneTimer["Lifetime"] = timer->Lifetime();
196 oneTimer["ChannelNumber"] = timer->Channel()->Number();
197 oneTimer["ChannelID"] = (const char *)timer->Channel()->GetChannelID().ToString();
198 oneTimer["StartTime"] = (int)timer->StartTime();
199 oneTimer["StopTime"] = (int)timer->StopTime();
200 oneTimer["Day"] = (int)timer->Day();
201 oneTimer["WeekDays"] = timer->WeekDays();
202 oneTimer["Name"] = timer->File();
204 const cEvent* event = timer->Event();
207 oneTimer["EventID"] = event->EventID();
211 int channelNumber = timer->Channel()->Number();
212 int aroundTime = timer->StartTime() + 1;
213 const cEvent* eventAround = getEvent(Channels, Schedules, js, channelNumber, 0, aroundTime);
216 oneTimer["EventID"] = eventAround->EventID();
220 oneTimer["EventID"] = 0;
224 jstimers.append(oneTimer);
227 js["Timers"] = jstimers;
228 js["NumTuners"] = cDevice::NumDevices();
233 bool VDRClient::channelschedule(PFMap& postFields, Json::Value& js) // RETHROWS
235 logger->debug("channelschedule");
236 int channelNumber = getVarInt(postFields, "channelnumber");
237 int startTime = getVarInt(postFields, "starttime");
238 int duration = getVarInt(postFields, "duration");
240 Json::Value jsevents(Json::arrayValue);
244 const cChannel* channel = NULL;
245 for (channel = Channels->First(); channel; channel = Channels->Next(channel))
247 if (channel->GroupSep()) continue;
248 if (channel->Number() == channelNumber) break;
253 logger->error("channelschedule: Could not find requested channel: {}", channelNumber);
254 js["Result"] = false;
255 js["Error"] = "Could not find channel";
261 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
264 logger->error("channelschedule: Could not find requested channel: {}", channelNumber);
265 js["Result"] = false;
266 js["Error"] = "Internal schedules error (2)";
270 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
272 if ((event->StartTime() + event->Duration()) < time(NULL)) continue; //in the past filter
273 if ((event->StartTime() + event->Duration()) <= startTime) continue; //start time filter
274 if (event->StartTime() >= (startTime + duration)) continue; //duration filter
276 Json::Value oneEvent;
277 oneEvent["ID"] = event->EventID();
278 oneEvent["Time"] = (Json::UInt)event->StartTime();
279 oneEvent["Duration"] = event->Duration();
280 oneEvent["Title"] = event->Title() ? event->Title() : "";
281 oneEvent["ShortText"] = event->ShortText() ? event->ShortText() : "";
282 oneEvent["HasTimer"] = event->HasTimer();
283 jsevents.append(oneEvent);
287 js["Events"] = jsevents;
291 bool VDRClient::getscheduleevent(PFMap& postFields, Json::Value& js) // RETHROWS
293 logger->debug("getscheduleevent");
295 int channelNumber = getVarInt(postFields, "channelnumber");
296 int eventID = getVarInt(postFields, "eventid");
301 const cEvent* event = getEvent(Channels, Schedules, js, channelNumber, eventID, 0);
304 js["Result"] = false;
308 Json::Value oneEvent;
309 oneEvent["ID"] = event->EventID();
310 oneEvent["Time"] = (Json::UInt)event->StartTime();
311 oneEvent["Duration"] = event->Duration();
312 oneEvent["Title"] = event->Title() ? event->Title() : "";
313 oneEvent["ShortText"] = event->ShortText() ? event->ShortText() : "";
314 oneEvent["Description"] = event->Description() ? event->Description() : "";
315 oneEvent["HasTimer"] = event->HasTimer();
316 oneEvent["RunningStatus"] = event->RunningStatus();
319 js["Event"] = oneEvent;
323 bool VDRClient::epgdownload(PFMap& postFields, Json::Value& js)
325 logger->debug("epgdownload");
326 Json::Value jsevents(Json::arrayValue);
331 for (const cChannel* channel = Channels->First(); channel; channel = Channels->Next(channel))
333 if (channel->GroupSep()) continue;
335 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
336 if (!Schedule) continue;
338 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
340 Json::Value oneEvent;
341 oneEvent["ChannelNumber"] = channel->Number();
342 oneEvent["ChannelID"] = (const char*)event->ChannelID().ToString();
343 oneEvent["ID"] = event->EventID();
344 oneEvent["Time"] = (Json::UInt)event->StartTime();
345 oneEvent["Duration"] = event->Duration();
346 oneEvent["Title"] = event->Title() ? event->Title() : "";
347 oneEvent["ShortText"] = event->ShortText() ? event->ShortText() : "";
348 oneEvent["HasTimer"] = event->HasTimer();
349 oneEvent["Description"] = event->Description() ? event->Description() : "";
350 jsevents.append(oneEvent);
355 js["Events"] = jsevents;
359 bool VDRClient::epgsearch(PFMap& postFields, Json::Value& js) // RETHROWS
361 logger->debug("epgsearch");
363 std::string searchfor = getVarString(postFields, "searchfor");
364 logger->debug("epgsearch: search for: {}", searchfor);
366 Json::Value jsevents(Json::arrayValue);
371 for (const cChannel* channel = Channels->First(); channel; channel = Channels->Next(channel))
373 if (channel->GroupSep()) continue;
375 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
376 if (!Schedule) continue;
379 bool founddescription;
380 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
383 founddescription = false;
385 if (event->Title() && strcasestr(event->Title(), searchfor.c_str())) foundtitle = true;
387 if (!foundtitle && event->Description())
388 if (strcasestr(event->Description(), searchfor.c_str())) founddescription = true;
390 if (foundtitle || founddescription)
392 Json::Value oneEvent;
393 oneEvent["ChannelNumber"] = channel->Number();
394 oneEvent["ChannelID"] = (const char*)event->ChannelID().ToString();
395 oneEvent["ID"] = event->EventID();
396 oneEvent["Time"] = (Json::UInt)event->StartTime();
397 oneEvent["Duration"] = event->Duration();
398 oneEvent["Title"] = event->Title() ? event->Title() : "";
399 oneEvent["ShortText"] = event->ShortText() ? event->ShortText() : "";
400 oneEvent["HasTimer"] = event->HasTimer();
401 oneEvent["Description"] = event->Description() ? event->Description() : "";
402 if (founddescription)
403 oneEvent["FoundInDesc"] = true;
405 oneEvent["FoundInDesc"] = false;
406 jsevents.append(oneEvent);
412 js["Events"] = jsevents;
414 logger->debug("epgsearch: search for: {} done", searchfor);
419 bool VDRClient::epgsearchsame(PFMap& postFields, Json::Value& js) // RETHROWS
421 logger->debug("epgsearchsame");
423 int atTime = getVarInt(postFields, "time");
424 std::string sTitle = getVarString(postFields, "title");
426 logger->debug("epgsearchsame: request time: {}, title: {}", atTime, sTitle);
428 Json::Value jsevents(Json::arrayValue);
433 for (const cSchedule *schedule = Schedules->First(); (schedule != NULL); schedule = Schedules->Next(schedule))
435 event = schedule->GetEventAround(atTime);
436 if (!event) continue; // nothing found on this schedule(channel)
438 if (!strcmp(event->Title(), sTitle.c_str()))
440 Json::Value oneEvent;
441 oneEvent["ChannelID"] = (const char*)event->ChannelID().ToString();
442 oneEvent["ID"] = event->EventID();
443 oneEvent["Time"] = (Json::UInt)event->StartTime();
444 oneEvent["Duration"] = event->Duration();
445 oneEvent["Title"] = event->Title() ? event->Title() : "";
446 oneEvent["ShortText"] = event->ShortText() ? event->ShortText() : "";
447 oneEvent["HasTimer"] = event->HasTimer();
448 //oneEvent["Description"] = event->Description() ? event->Description() : "";
449 jsevents.append(oneEvent);
453 js["Events"] = jsevents;
458 bool VDRClient::epgsearchotherhalf(PFMap& postFields, Json::Value& js) // RETHROWS
460 logger->debug("epgsearchotherhalf");
461 int channelNumber = getVarInt(postFields, "channelnumber");
462 int eventID = getVarInt(postFields, "eventid");
463 const cChannel* channel = NULL;
467 for (channel = Channels->First(); channel; channel = Channels->Next(channel))
469 if (channel->GroupSep()) continue;
470 if (channel->Number() == channelNumber) break;
475 logger->error("epgsearchotherhalf: Could not find requested channel: {}", channelNumber);
476 js["Result"] = false;
477 js["Error"] = "Could not find channel";
483 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
486 logger->error("epgsearchotherhalf: Could not find requested channel: {}", channelNumber);
487 js["Result"] = false;
488 js["Error"] = "Internal schedules error (2)";
492 js["OtherEventFound"] = false;
494 const cEvent* eventM1 = NULL;
495 const cEvent* eventM2 = NULL;
496 const cEvent* otherEvent = NULL;
498 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
500 if (event->EventID() == (unsigned long)eventID)
502 if ((eventM2 != NULL) && (!strcmp(eventM2->Title(), event->Title())))
504 otherEvent = eventM2;
508 const cEvent* eventP1 = Schedule->Events()->Next(event);
511 const cEvent* eventP2 = Schedule->Events()->Next(eventP1);
513 if (eventP2 && (!strcmp(eventP2->Title(), event->Title())))
515 otherEvent = eventP2;
522 Json::Value oneEvent;
523 oneEvent["ID"] = otherEvent->EventID();
524 oneEvent["ChannelNumber"] = channel->Number();
525 oneEvent["Time"] = (Json::UInt)otherEvent->StartTime();
526 oneEvent["Duration"] = otherEvent->Duration();
527 oneEvent["Title"] = otherEvent->Title() ? otherEvent->Title() : "";
528 oneEvent["HasTimer"] = otherEvent->HasTimer();
529 js["Event"] = oneEvent;
530 js["OtherEventFound"] = true;
544 bool VDRClient::tunersstatus(PFMap& postFields, Json::Value& js)
546 logger->debug("tunerstatus");
548 js["NumDevices"] = cDevice::NumDevices();
550 Json::Value jsdevices(Json::arrayValue);
552 for (int i = 0; i < cDevice::NumDevices(); i++)
554 Json::Value oneDevice;
555 cDevice *d = cDevice::GetDevice(i);
556 oneDevice["Number"] = d->DeviceNumber();
557 oneDevice["Type"] = (const char*)d->DeviceType();
558 oneDevice["Name"] = (const char*)d->DeviceName();
559 oneDevice["IsPrimary"] = d->IsPrimaryDevice();
561 const cChannel* cchannel = d->GetCurrentlyTunedTransponder();
564 oneDevice["Frequency"] = cchannel->Frequency();
565 oneDevice["SignalStrength"] = d->SignalStrength();
566 oneDevice["SignalQuality"] = d->SignalQuality();
571 oneDevice["Frequency"] = 0;
572 oneDevice["SignalStrength"] = 0;
573 oneDevice["SignalQuality"] = 0;
576 jsdevices.append(oneDevice);
579 js["Devices"] = jsdevices;
582 Json::Value jstimers(Json::arrayValue);
585 LOCK_CHANNELS_READ; // Because this calls timer->Channel() .. necessary?
587 int numTimers = Timers->Count();
589 for (int i = 0; i < numTimers; i++)
591 timer = Timers->Get(i);
593 if (timer->Recording())
595 Json::Value oneTimer;
596 oneTimer["Recording"] = timer->Recording();
597 oneTimer["StartTime"] = (int)timer->StartTime();
598 oneTimer["StopTime"] = (int)timer->StopTime();
599 oneTimer["File"] = timer->File();
601 cRecordControl* crc = cRecordControls::GetRecordControl(timer);
604 cDevice* crcd = crc->Device();
605 oneTimer["DeviceNumber"] = crcd->DeviceNumber();
609 oneTimer["DeviceNumber"] = Json::Value::null;
612 const cChannel* channel = timer->Channel();
615 oneTimer["ChannelName"] = channel->Name();
619 oneTimer["ChannelName"] = Json::Value::null;
622 jstimers.append(oneTimer);
626 js["CurrentRecordings"] = jstimers;
633 bool VDRClient::timerset(PFMap& postFields, Json::Value& js) // RETHROWS
635 logger->debug("timerset");
637 std::string sTimerString = getVarString(postFields, "timerstring");
639 logger->debug("timerset: '{}'", sTimerString);
640 cTimer *timer = new cTimer;
641 if (!timer->Parse(sTimerString.c_str()))
644 js["Result"] = false;
645 js["Error"] = "Failed to parse timer request details";
650 Timers->SetExplicitModify();
652 cTimer *t = Timers->GetTimer(timer);
656 js["Result"] = false;
657 js["Error"] = "Timer already exists";
662 Timers->SetModified();
668 bool VDRClient::recinfo(PFMap& postFields, Json::Value& js) // RETHROWS
670 logger->debug("recinfo");
672 std::string reqfilename = getVarString(postFields, "filename");
673 logger->debug("recinfo: {}", reqfilename);
675 LOCK_RECORDINGS_READ;
677 const cRecording *recording = Recordings->GetByName(reqfilename.c_str());
681 logger->error("recinfo: recinfo found no recording");
682 js["Result"] = false;
686 js["IsNew"] = recording->IsNew();
687 js["LengthInSeconds"] = recording->LengthInSeconds();
688 js["FileSizeMB"] = recording->FileSizeMB();
689 js["Name"] = recording->Name() ? recording->Name() : Json::Value::null;
690 js["Priority"] = recording->Priority();
691 js["LifeTime"] = recording->Lifetime();
692 js["Start"] = (Json::UInt)recording->Start();
694 js["CurrentlyRecordingStart"] = 0;
695 js["CurrentlyRecordingStop"] = 0;
696 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
699 js["CurrentlyRecordingStart"] = (Json::UInt)rc->Timer()->StartTime();
700 js["CurrentlyRecordingStop"] = (Json::UInt)rc->Timer()->StopTime();
703 js["ResumePoint"] = 0;
705 const cRecordingInfo *info = recording->Info();
708 js["ChannelName"] = info->ChannelName() ? info->ChannelName() : Json::Value::null;
709 js["Title"] = info->Title() ? info->Title() : Json::Value::null;
710 js["ShortText"] = info->ShortText() ? info->ShortText() : Json::Value::null;
711 js["Description"] = info->Description() ? info->Description() : Json::Value::null;
713 const cComponents* components = info->Components();
716 js["Components"] = Json::Value::null;
720 Json::Value jscomponents;
722 tComponent* component;
723 for (int i = 0; i < components->NumComponents(); i++)
725 component = components->Component(i);
727 Json::Value oneComponent;
728 oneComponent["Stream"] = component->stream;
729 oneComponent["Type"] = component->type;
730 oneComponent["Language"] = component->language ? component->language : Json::Value::null;
731 oneComponent["Description"] = component->description ? component->description : Json::Value::null;
732 jscomponents.append(oneComponent);
735 js["Components"] = jscomponents;
738 cResumeFile ResumeFile(recording->FileName(), recording->IsPesRecording());
739 if (ResumeFile.Read() >= 0) js["ResumePoint"] = floor(ResumeFile.Read() / info->FramesPerSecond());
746 bool VDRClient::recstop(PFMap& postFields, Json::Value& js) // RETHROWS
748 logger->debug("recstop");
750 std::string reqfilename = getVarString(postFields, "filename");
751 logger->debug("recstop: {}", reqfilename);
754 LOCK_RECORDINGS_WRITE; // May not need write here, but to be safe..
756 cRecording *recording = Recordings->GetByName(reqfilename.c_str());
760 logger->error("recstop: recstop found no recording");
761 js["Result"] = false;
765 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
768 logger->error("recstop: not currently recording");
769 js["Result"] = false;
773 cTimer* timer = rc->Timer();
776 logger->error("recstop: timer not found");
777 js["Result"] = false;
781 timer->ClrFlags(tfActive);
788 bool VDRClient::recdel(PFMap& postFields, Json::Value& js) // RETHROWS
790 logger->debug("recdel");
792 std::string reqfilename = getVarString(postFields, "filename");
793 logger->debug("recdel: {}", reqfilename);
795 LOCK_RECORDINGS_WRITE;
797 cRecording *recording = Recordings->GetByName(reqfilename.c_str());
801 js["Result"] = false;
802 js["Error"] = "Could not find recording to delete";
806 logger->debug("recdel: Deleting recording: {}", recording->Name());
807 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
810 js["Result"] = false;
811 js["Error"] = "This recording is still recording.. ho ho";
815 if (recording->Delete())
817 Recordings->DelByName(recording->FileName());
822 js["Result"] = false;
823 js["Error"] = "Failed to delete recording";
829 void VDRClient::pathsForRecordingName(const cRecordings* Recordings, const std::string& recordingName,
830 std::string& dirNameSingleDate,
831 std::string& dirNameSingleTitle,
832 std::string& dirNameSingleFolder,
833 std::string& dirNameFullPathTitle,
834 std::string& dirNameFullPathDate) // throws int
838 const cRecording* recordingObj = Recordings->GetByName(recordingName.c_str());
839 if (!recordingObj) throw 2;
840 t = recordingObj->FileName();
842 cRecordControl *rc = cRecordControls::GetRecordControl(recordingObj->FileName());
845 logger->debug("paths: recording: {}", recordingObj->Name());
846 } // unlock recordings
848 logger->debug("paths: recording: {}", t);
850 dirNameFullPathDate = t;
853 // Find the datedirname
854 for(k = strlen(t) - 1; k >= 0; k--)
858 logger->debug("recmoverename: l1: {}", strlen(&t[k+1]) + 1);
859 dirNameSingleDate.assign(&t[k+1], strlen(t) - k - 1);
860 logger->debug("paths: dirNameSingleDate: '{}'", dirNameSingleDate);
865 // Find the titledirname
867 for(j = k-1; j >= 0; j--)
871 logger->debug("recmoverename: l2: {}", k - j);
872 dirNameSingleTitle.assign(&t[j+1], k - j - 1);
873 logger->debug("paths: dirNameSingleTitle: '{}'", dirNameSingleTitle);
878 // Find the foldername
880 const char* vidDirStr = cVideoDirectory::Name();
881 int vidDirStrLen = strlen(vidDirStr);
883 logger->debug("recmoverename: j = {}, strlenvd = {}", j, vidDirStrLen);
884 if (j > vidDirStrLen) // Rec is in a subfolder now
886 for(m = j-1; m >= 0; m--)
890 logger->debug("recmoverename: l3: {}", j - m);
891 dirNameSingleFolder.assign(&t[m+1], j - m - 1);
892 logger->debug("paths: dirNameSingleFolder: '{}'", dirNameSingleFolder);
898 dirNameFullPathTitle.assign(t, k);
899 logger->debug("paths: dirNameFullPathTitle: '{}'", dirNameFullPathTitle);
902 bool VDRClient::recrename(PFMap& postFields, Json::Value& js) // RETHROWS
904 logger->debug("recrename");
906 std::string fileNameToAffect = getVarString(postFields, "filename");
907 std::string requestedNewStr = getVarString(postFields, "newname");
909 std::string dirNameSingleDate;
910 std::string dirNameSingleTitle;
911 std::string dirNameSingleFolder;
912 std::string dirNameFullPathTitle;
913 std::string dirNameFullPathDate;
915 #warning Switch this to Recording->ChangeName ?
919 LOCK_RECORDINGS_WRITE;
921 pathsForRecordingName(Recordings,
922 fileNameToAffect, dirNameSingleDate,
923 dirNameSingleTitle, dirNameSingleFolder,
924 dirNameFullPathTitle, dirNameFullPathDate);
926 char* requestedNewSingleTitle = (char*)malloc(requestedNewStr.size() + 1);
927 strcpy(requestedNewSingleTitle, requestedNewStr.c_str());
928 logger->debug("recmoverename: to: {}", requestedNewSingleTitle);
930 requestedNewSingleTitle = ExchangeChars(requestedNewSingleTitle, true);
931 if (!strlen(requestedNewSingleTitle)) throw 9;
932 logger->debug("recmoverename: EC: {}", requestedNewSingleTitle);
934 const char* vidDirStr = cVideoDirectory::Name();
935 logger->debug("recmoverename: viddir: {}", vidDirStr);
937 // Could be a new path - construct that first and test
939 std::string newDirNameFullPathTitle = vidDirStr;
940 newDirNameFullPathTitle.append("/");
942 if (!dirNameSingleFolder.empty())
944 newDirNameFullPathTitle.append(dirNameSingleFolder);
945 newDirNameFullPathTitle.append("/");
948 newDirNameFullPathTitle.append(requestedNewSingleTitle);
949 free(requestedNewSingleTitle);
951 logger->debug("recrename: NPT2: {}", newDirNameFullPathTitle);
954 int statret = stat(newDirNameFullPathTitle.c_str(), &dstat);
955 if ((statret == -1) && (errno == ENOENT)) // Dir does not exist
957 logger->debug("recrename: new path does not exist (1)");
958 int mkdirret = mkdir(newDirNameFullPathTitle.c_str(), 0755);
959 if (mkdirret != 0) throw 4;
961 else if ((statret == 0) && (! (dstat.st_mode && S_IFDIR)))
963 // Something exists but it's not a dir
967 // New path now created or was there already
969 std::string newDirNameFullPathDate = newDirNameFullPathTitle + "/";
970 newDirNameFullPathDate.append(dirNameSingleDate);
972 logger->debug("recrename: doing rename '{}' '{}'", dirNameFullPathDate, newDirNameFullPathDate);
973 if (rename(dirNameFullPathDate.c_str(), newDirNameFullPathDate.c_str()) != 0) throw 8;
975 // Success. Test for remove old dir containter
976 rmdir(dirNameFullPathTitle.c_str()); // can't do anything about a fail result at this point.
978 Recordings->Update();
980 js["NewRecordingFileName"] = newDirNameFullPathDate;
984 js["Result"] = false;
987 logger->error("recrename: Bad parameters");
988 js["Error"] = "Bad request parameters";
992 logger->error("recrename: Could not find recording to move");
993 js["Error"] = "Bad filename";
997 logger->error("recrename: Could not move recording, it is still recording");
998 js["Error"] = "Cannot move recording in progress";
1002 logger->error("recrename: Failed to make new dir (1)");
1003 js["Error"] = "Failed to create new directory (1)";
1007 logger->error("recrename: Something already exists? (1)");
1008 js["Error"] = "Something already exists at the new path (1)";
1012 logger->error("recrename: Rename failed");
1013 js["Error"] = "Rename failed";
1017 logger->error("recrename: ExchangeChars lost our string");
1018 js["Error"] = "Rename failed";
1025 bool VDRClient::recmove(PFMap& postFields, Json::Value& js) // RETHROWS
1027 logger->debug("recmove");
1029 std::string fileNameToAffect = getVarString(postFields, "filename");
1030 std::string requestedNewStr = getVarString(postFields, "newpath");
1032 std::string dirNameSingleDate;
1033 std::string dirNameSingleTitle;
1034 std::string dirNameSingleFolder;
1035 std::string dirNameFullPathTitle;
1036 std::string dirNameFullPathDate;
1040 LOCK_RECORDINGS_WRITE;
1042 pathsForRecordingName(Recordings,
1043 fileNameToAffect, dirNameSingleDate,
1044 dirNameSingleTitle, dirNameSingleFolder,
1045 dirNameFullPathTitle, dirNameFullPathDate);
1047 char* requestedNewSinglePath = (char*)malloc(requestedNewStr.size() + 1);
1048 strcpy(requestedNewSinglePath, requestedNewStr.c_str());
1049 logger->debug("recmoverename: to: {}", requestedNewSinglePath);
1051 requestedNewSinglePath = ExchangeChars(requestedNewSinglePath, true);
1052 if (!strlen(requestedNewSinglePath)) throw 9;
1053 logger->debug("recmoverename: EC: {}", requestedNewSinglePath);
1055 const char* vidDirStr = cVideoDirectory::Name();
1056 logger->debug("recmoverename: viddir: {}", vidDirStr);
1058 // Could be a new path - construct that first and test
1060 std::string newDirNameFullPathTitle = vidDirStr;
1061 newDirNameFullPathTitle.append(requestedNewSinglePath);
1062 free(requestedNewSinglePath);
1064 logger->debug("recmove: NPT: {}", newDirNameFullPathTitle);
1067 int statret = stat(newDirNameFullPathTitle.c_str(), &dstat);
1068 if ((statret == -1) && (errno == ENOENT)) // Dir does not exist
1070 logger->debug("recmove: new path does not exist (1)");
1071 int mkdirret = mkdir(newDirNameFullPathTitle.c_str(), 0755);
1072 if (mkdirret != 0) throw 4;
1074 else if ((statret == 0) && (! (dstat.st_mode && S_IFDIR)))
1076 // Something exists but it's not a dir
1080 // New path now created or was there already
1082 newDirNameFullPathTitle.append(dirNameSingleTitle);
1083 logger->debug("recmove: {}", newDirNameFullPathTitle);
1085 statret = stat(newDirNameFullPathTitle.c_str(), &dstat);
1086 if ((statret == -1) && (errno == ENOENT)) // Dir does not exist
1088 logger->debug("recmove: new dir does not exist (2)");
1089 int mkdirret = mkdir(newDirNameFullPathTitle.c_str(), 0755);
1090 if (mkdirret != 0) throw 6;
1092 else if ((statret == 0) && (! (dstat.st_mode && S_IFDIR)))
1094 // Something exists but it's not a dir
1098 // Ok, the directory container has been made, or it pre-existed.
1100 std::string newDirNameFullPathDate = newDirNameFullPathTitle + "/";
1101 newDirNameFullPathDate.append(dirNameSingleDate);
1103 logger->debug("recmove: doing rename '{}' '{}'", dirNameFullPathDate, newDirNameFullPathDate);
1104 if (rename(dirNameFullPathDate.c_str(), newDirNameFullPathDate.c_str()) != 0) throw 8;
1106 // Success. Test for remove old dir containter
1107 rmdir(dirNameFullPathTitle.c_str()); // can't do anything about a fail result at this point.
1109 // Test for remove old foldername
1110 if (!dirNameSingleFolder.empty())
1112 std::string dirNameFullPathFolder = vidDirStr;
1113 dirNameFullPathFolder.append("/");
1114 dirNameFullPathFolder.append(dirNameSingleFolder);
1116 logger->debug("recmove: oldfoldername: {}", dirNameFullPathFolder);
1119 rmdir() deletes a directory, which must be empty.
1120 ENOTEMPTY - pathname contains entries other than . and ..
1121 So, should be safe to call rmdir on non-empty dir
1123 rmdir(dirNameFullPathFolder.c_str()); // can't do anything about a fail result at this point.
1126 Recordings->Update();
1127 js["Result"] = true;
1128 js["NewRecordingFileName"] = newDirNameFullPathDate;
1132 js["Result"] = false;
1135 logger->error("recmove: Bad parameters");
1136 js["Error"] = "Bad request parameters";
1140 logger->error("recmove: Could not find recording to move");
1141 js["Error"] = "Bad filename";
1145 logger->error("recmove: Could not move recording, it is still recording");
1146 js["Error"] = "Cannot move recording in progress";
1150 logger->error("recmove: Failed to make new dir (1)");
1151 js["Error"] = "Failed to create new directory (1)";
1155 logger->error("recmove: Something already exists? (1)");
1156 js["Error"] = "Something already exists at the new path (1)";
1160 logger->error("recmove: Failed to make new dir (2)");
1161 js["Error"] = "Failed to create new directory (2)";
1165 logger->error("recmove: Something already exists?");
1166 js["Error"] = "Something already exists at the new path";
1170 logger->error("recmove: Rename failed");
1171 js["Error"] = "Move failed";
1175 logger->error("recrename: ExchangeChars lost our string");
1176 js["Error"] = "Rename failed";
1183 bool VDRClient::timersetactive(PFMap& postFields, Json::Value& js) // RETHROWS
1185 logger->debug("timersetactive");
1187 std::string rChannelID = getVarString(postFields, "ChannelID");
1188 std::string rName = getVarString(postFields, "Name");
1189 std::string rStartTime = getVarString(postFields, "StartTime");
1190 std::string rStopTime = getVarString(postFields, "StopTime");
1191 std::string rWeekDays = getVarString(postFields, "WeekDays");
1192 std::string tNewActive = getVarString(postFields, "SetActive");
1194 logger->debug("timersetactive: {} {}:{}:{}:{}:{}", tNewActive, rChannelID, rName, rStartTime, rStopTime, rWeekDays);
1196 if ((tNewActive != "true") && (tNewActive != "false"))
1198 js["Result"] = false;
1199 js["Error"] = "Bad request parameters";
1205 Timers->SetExplicitModify();
1207 cTimer* timer = findTimer(Timers, rChannelID.c_str(), rName.c_str(), rStartTime.c_str(), rStopTime.c_str(), rWeekDays.c_str());
1210 if (tNewActive == "true") timer->SetFlags(tfActive);
1211 else timer->ClrFlags(tfActive);
1213 js["Result"] = true;
1214 Timers->SetModified();
1218 js["Result"] = false;
1219 js["Error"] = "Timer not found";
1223 bool VDRClient::timerdel(PFMap& postFields, Json::Value& js) // RETHROWS
1225 logger->debug("timerdel");
1227 std::string rChannelID = getVarString(postFields, "ChannelID");
1228 std::string rName = getVarString(postFields, "Name");
1229 std::string rStartTime = getVarString(postFields, "StartTime");
1230 std::string rStopTime = getVarString(postFields, "StopTime");
1231 std::string rWeekDays = getVarString(postFields, "WeekDays");
1233 logger->debug("timerdel: {}:{}:{}:{}:{}", rChannelID, rName, rStartTime, rStopTime, rWeekDays);
1236 Timers->SetExplicitModify();
1238 cTimer* timer = findTimer(Timers, rChannelID.c_str(), rName.c_str(), rStartTime.c_str(), rStopTime.c_str(), rWeekDays.c_str());
1241 if (timer->Recording())
1243 logger->debug("timerdel: Unable to delete timer - timer is running");
1244 js["Result"] = false;
1245 js["Error"] = "Timer is running";
1250 Timers->SetModified();
1251 js["Result"] = true;
1255 js["Result"] = false;
1256 js["Error"] = "Timer not found";
1260 bool VDRClient::timerisrecording(PFMap& postFields, Json::Value& js) // RETHROWS
1262 logger->debug("timerisrecording");
1264 std::string rChannelID = getVarString(postFields, "ChannelID");
1265 std::string rName = getVarString(postFields, "Name");
1266 std::string rStartTime = getVarString(postFields, "StartTime");
1267 std::string rStopTime = getVarString(postFields, "StopTime");
1268 std::string rWeekDays = getVarString(postFields, "WeekDays");
1270 logger->debug("timerisrecording: {}:{}:{}:{}:{}", rChannelID, rName, rStartTime, rStopTime, rWeekDays);
1274 const cTimer* timer = findTimer(Timers, rChannelID.c_str(), rName.c_str(), rStartTime.c_str(), rStopTime.c_str(), rWeekDays.c_str());
1277 js["Recording"] = timer->Recording();
1278 js["Pending"] = timer->Pending();
1279 js["Result"] = true;
1283 js["Result"] = false;
1284 js["Error"] = "Timer not found";
1288 bool VDRClient::recresetresume(PFMap& postFields, Json::Value& js) // RETHROWS
1290 logger->debug("recresetresume");
1292 std::string reqfilename = getVarString(postFields, "filename");
1293 logger->debug("recresetresume: {}", reqfilename);
1297 const cRecordings* Recordings = cRecordings::GetRecordingsRead(StateKey);
1299 const cRecording* recording = Recordings->GetByName(reqfilename.c_str());
1305 js["Result"] = false;
1306 js["Error"] = "Could not find recording to reset resume";
1310 logger->debug("recresetresume: Reset resume for: {}", recording->Name());
1312 cResumeFile ResumeFile(recording->FileName(), recording->IsPesRecording());
1316 if (ResumeFile.Read() >= 0)
1318 ResumeFile.Delete();
1319 js["Result"] = true;
1324 js["Result"] = false;
1325 js["Error"] = "Recording has no resume point";
1330 bool VDRClient::timeredit(PFMap& postFields, Json::Value& js) // RETHROWS
1332 logger->debug("timeredit");
1334 std::string oldName = getVarString(postFields, "OldName");
1335 std::string oldActive = getVarString(postFields, "OldActive");
1336 std::string oldChannelID = getVarString(postFields, "OldChannelID");
1337 std::string oldDay = getVarString(postFields, "OldDay");
1338 std::string oldWeekDays = getVarString(postFields, "OldWeekDays");
1339 std::string oldStartTime = getVarString(postFields, "OldStartTime");
1340 std::string oldStopTime = getVarString(postFields, "OldStopTime");
1341 std::string oldPriority = getVarString(postFields, "OldPriority");
1342 std::string oldLifetime = getVarString(postFields, "OldLifetime");
1344 logger->debug("timeredit: {} {} {} {} {} {} {} {} {}", oldName, oldActive, oldChannelID, oldDay, oldWeekDays, oldStartTime, oldStopTime, oldPriority, oldLifetime);
1346 std::string newName = getVarString(postFields, "NewName");
1347 std::string newActive = getVarString(postFields, "NewActive");
1348 std::string newChannelID = getVarString(postFields, "NewChannelID");
1349 std::string newDay = getVarString(postFields, "NewDay");
1350 std::string newWeekDays = getVarString(postFields, "NewWeekDays");
1351 std::string newStartTime = getVarString(postFields, "NewStartTime");
1352 std::string newStopTime = getVarString(postFields, "NewStopTime");
1353 std::string newPriority = getVarString(postFields, "NewPriority");
1354 std::string newLifetime = getVarString(postFields, "NewLifetime");
1356 logger->debug("timeredit: {} {} {} {} {} {} {} {} {}", newName, newActive, newChannelID, newDay, newWeekDays, newStartTime, newStopTime, newPriority, newLifetime);
1359 Timers->SetExplicitModify();
1361 cTimer* timer = findTimer2(Timers, oldName.c_str(), oldActive.c_str(), oldChannelID.c_str(), oldDay.c_str(), oldWeekDays.c_str(), oldStartTime.c_str(), oldStopTime.c_str(), oldPriority.c_str(), oldLifetime.c_str());
1364 js["Result"] = false;
1365 js["Error"] = "Timer not found";
1369 Timers->SetModified();
1371 // Old version commented below (now removed) used to set each thing individually based on whether it had changed. However, since
1372 // the only way to change the timer channel appears to be with the cTimer::Parse function, might as well use that
1373 // for everything it supports
1374 // Except flags. Get current flags, set using Parse, then add/remove active as needed the other way.
1376 time_t nstt = std::stoi(newStartTime);
1378 localtime_r(&nstt, &nstm);
1379 int nssf = (nstm.tm_hour * 100) + nstm.tm_min;
1381 time_t nztt = std::stoi(newStopTime);
1383 localtime_r(&nztt, &nztm);
1384 int nzsf = (nztm.tm_hour * 100) + nztm.tm_min;
1386 std::replace(newName.begin(), newName.end(), ':', '|');
1388 // ? Convert to std::string?
1389 cString parseBuffer = cString::sprintf("%u:%s:%s:%04d:%04d:%d:%d:%s:%s",
1390 timer->Flags(), newChannelID.c_str(), *(cTimer::PrintDay(std::stoi(newDay), std::stoi(newWeekDays), true)),
1391 nssf, nzsf, std::stoi(newPriority), std::stoi(newLifetime), newName.c_str(), timer->Aux() ? timer->Aux() : "");
1393 logger->debug("timeredit: new parse: {}", *parseBuffer);
1395 bool parseResult = timer->Parse(*parseBuffer);
1398 js["Result"] = false;
1399 js["Error"] = "Timer parsing failed";
1403 if (timer->HasFlags(tfActive) != !(strcasecmp(newActive.c_str(), "true")))
1405 logger->debug("timeredit: {} {} set new active: {}", timer->HasFlags(tfActive), !(strcasecmp(newActive.c_str(), "true")), newActive);
1407 if (strcasecmp(newActive.c_str(), "true") == 0)
1409 timer->SetFlags(tfActive);
1411 else if (strcasecmp(newActive.c_str(), "false") == 0)
1413 timer->ClrFlags(tfActive);
1417 js["Result"] = false;
1418 js["Error"] = "Bad request parameters";
1423 js["Result"] = true;
1427 bool VDRClient::epgfilteradd(PFMap& postFields, Json::Value& js) // RETHROWS
1429 std::string channel = getVarString(postFields, "channel");
1430 std::string programme = getVarString(postFields, "programme");
1432 logger->debug("epgFilterAdd: {} {}", channel, programme);
1434 libconfig::Config epgFilter;
1435 if (!loadEpgFilter(epgFilter))
1437 js["Result"] = false;
1438 js["Error"] = "Error initialising EPG filter";
1442 libconfig::Setting& setting = epgFilter.lookup("filters");
1443 libconfig::Setting& newPair = setting.add(libconfig::Setting::Type::TypeGroup);
1444 libconfig::Setting& newChannel = newPair.add("c", libconfig::Setting::Type::TypeString);
1445 newChannel = channel;
1446 libconfig::Setting& newProgramme = newPair.add("p", libconfig::Setting::Type::TypeString);
1447 newProgramme = programme;
1449 if (!saveEpgFilter(epgFilter))
1451 js["Result"] = false;
1452 js["Error"] = "Failed to save EPG filter";
1456 js["Result"] = true;
1460 bool VDRClient::epgfilterdel(PFMap& postFields, Json::Value& js) // RETHROWS
1462 std::string channel = getVarString(postFields, "channel");
1463 std::string programme = getVarString(postFields, "programme");
1465 logger->debug("epgFilterDel: {} {}", channel, programme);
1467 libconfig::Config epgFilter;
1468 if (!loadEpgFilter(epgFilter))
1470 js["Result"] = false;
1471 js["Error"] = "Error initialising EPG filter";
1477 libconfig::Setting& setting = epgFilter.lookup("filters");
1478 int numFilters = setting.getLength();
1480 for (x = 0; x < numFilters; x++)
1482 libconfig::Setting& pair = setting[x];
1485 if (!pair.lookupValue("c", c) || !pair.lookupValue("p", p))
1487 js["Result"] = false;
1488 js["Error"] = "Filter file format error";
1491 if ((c == channel) && (p == programme))
1495 if (!saveEpgFilter(epgFilter))
1497 js["Result"] = false;
1498 js["Error"] = "Failed to save EPG filter";
1502 logger->debug("Found and deleted: {} {}", c, p);
1503 js["Result"] = true;
1508 js["Result"] = false;
1509 js["Error"] = "Channel/Programme not found";
1512 catch (const std::exception& e)
1514 js["Result"] = false;
1515 js["Error"] = "Unknown error";
1520 bool VDRClient::epgfilterget(PFMap& postFields, Json::Value& js) // RETHROWS
1522 logger->debug("epgFilterget");
1524 libconfig::Config epgFilter;
1525 if (!loadEpgFilter(epgFilter))
1527 js["Result"] = false;
1528 js["Error"] = "Error initialising EPG filter";
1534 libconfig::Setting& setting = epgFilter.lookup("filters");
1535 int numFilters = setting.getLength();
1537 Json::Value jsfilters(Json::arrayValue);
1538 for (x = 0; x < numFilters; x++)
1540 libconfig::Setting& pair = setting[x];
1543 if (!pair.lookupValue("c", c) || !pair.lookupValue("p", p))
1545 js["Result"] = false;
1546 js["Error"] = "Filter file format error";
1549 Json::Value oneFilter;
1552 jsfilters.append(oneFilter);
1554 js["EPGFilters"] = jsfilters;
1556 catch (const std::exception& e)
1558 js["Result"] = false;
1559 js["Error"] = "Unknown error";
1563 js["Result"] = true;
1567 //////////////////////////////////////////////////////////////////////////////////////////////////
1569 const cEvent* VDRClient::getEvent(const cChannels* Channels, const cSchedules* Schedules,
1570 Json::Value& js, int channelNumber, int eventID, int aroundTime)
1572 const cChannel* channel = NULL;
1574 for (channel = Channels->First(); channel; channel = Channels->Next(channel))
1576 if (channel->GroupSep()) continue;
1577 if (channel->Number() == channelNumber) break;
1582 logger->error("getevent: Could not find requested channel: {}", channelNumber);
1583 js["Error"] = "Could not find channel";
1587 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
1590 logger->error("getevent: Could not find requested channel: {}", channelNumber);
1591 js["Error"] = "Internal schedules error (2)";
1595 const cEvent* event = NULL;
1597 event = Schedule->GetEvent(eventID);
1599 event = Schedule->GetEventAround(aroundTime);
1603 logger->error("getevent: Could not find requested event: {}", eventID);
1604 js["Error"] = "Internal schedules error (3)";
1611 cTimer* VDRClient::findTimer(cTimers* Timers,
1612 const char* rChannelID, const char* rName, const char* rStartTime, const char* rStopTime, const char* rWeekDays)
1614 int numTimers = Timers->Count();
1616 for (int i = 0; i < numTimers; i++)
1618 timer = Timers->Get(i);
1620 logger->debug("findtimer: current: {}", (const char*)timer->ToText(true));
1621 logger->debug("findtimer: {}", (const char*)timer->Channel()->GetChannelID().ToString());
1622 logger->debug("findtimer: {}", rChannelID);
1623 logger->debug("findtimer: {}", timer->File());
1624 logger->debug("findtimer: {}", rName);
1625 logger->debug("findtimer: {}", timer->StartTime());
1626 logger->debug("findtimer: {}", rStartTime);
1627 logger->debug("findtimer: {}", timer->StopTime());
1628 logger->debug("findtimer: {}", rStopTime);
1629 logger->debug("findtimer: {}", timer->WeekDays());
1630 logger->debug("findtimer: {}", rWeekDays);
1633 (strcmp(timer->Channel()->GetChannelID().ToString(), rChannelID) == 0)
1634 && (strcmp(timer->File(), rName) == 0)
1635 && (timer->StartTime() == atoi(rStartTime))
1636 && (timer->StopTime() == atoi(rStopTime))
1637 && (timer->WeekDays() == atoi(rWeekDays))
1640 logger->debug("findtimer: found");
1644 logger->debug("findtimer: no timer found");
1648 // Differs only from above by taking const Timers and returning const cTimer
1649 const cTimer* VDRClient::findTimer(const cTimers* Timers,
1650 const char* rChannelID, const char* rName, const char* rStartTime, const char* rStopTime, const char* rWeekDays)
1652 int numTimers = Timers->Count();
1653 const cTimer* timer;
1654 for (int i = 0; i < numTimers; i++)
1656 timer = Timers->Get(i);
1658 logger->debug("findtimer: current: {}", (const char*)timer->ToText(true));
1659 logger->debug("findtimer: {}", (const char*)timer->Channel()->GetChannelID().ToString());
1660 logger->debug("findtimer: {}", rChannelID);
1661 logger->debug("findtimer: {}", timer->File());
1662 logger->debug("findtimer: {}", rName);
1663 logger->debug("findtimer: {}", timer->StartTime());
1664 logger->debug("findtimer: {}", rStartTime);
1665 logger->debug("findtimer: {}", timer->StopTime());
1666 logger->debug("findtimer: {}", rStopTime);
1667 logger->debug("findtimer: {}", timer->WeekDays());
1668 logger->debug("findtimer: {}", rWeekDays);
1671 (strcmp(timer->Channel()->GetChannelID().ToString(), rChannelID) == 0)
1672 && (strcmp(timer->File(), rName) == 0)
1673 && (timer->StartTime() == atoi(rStartTime))
1674 && (timer->StopTime() == atoi(rStopTime))
1675 && (timer->WeekDays() == atoi(rWeekDays))
1678 logger->debug("findtimer: found");
1682 logger->debug("findtimer: no timer found");
1686 cTimer* VDRClient::findTimer2(cTimers* Timers, const char* rName, const char* rActive, const char* rChannelID, const char* rDay, const char* rWeekDays, const char* rStartTime, const char* rStopTime, const char* rPriority, const char* rLifetime)
1688 int numTimers = Timers->Count();
1690 logger->debug("findtimer2: {} {} {} {} {} {} {} {} {}", rName, rActive, rChannelID, rDay, rWeekDays, rStartTime, rStopTime, rPriority, rLifetime);
1691 for (int i = 0; i < numTimers; i++)
1693 timer = Timers->Get(i);
1695 logger->debug("findtimer2: search: {} {} {} {} {} {} {} {} {}", timer->File(), timer->HasFlags(tfActive), (const char*)timer->Channel()->GetChannelID().ToString(),
1696 (int)timer->Day(), timer->WeekDays(), (int)timer->StartTime(), (int)timer->StopTime(),
1697 timer->Priority(), timer->Lifetime());
1699 if ( (strcmp(timer->File(), rName) == 0)
1700 && (timer->HasFlags(tfActive) == !(strcasecmp(rActive, "true")))
1701 && (strcmp(timer->Channel()->GetChannelID().ToString(), rChannelID) == 0)
1702 && (timer->Day() == atoi(rDay))
1703 && (timer->WeekDays() == atoi(rWeekDays))
1704 && (timer->StartTime() == atoi(rStartTime))
1705 && (timer->StopTime() == atoi(rStopTime))
1706 && (timer->Priority() == atoi(rPriority))
1707 && (timer->Lifetime() == atoi(rLifetime))
1710 logger->debug("findtimer2: found");
1714 logger->debug("findtimer2: no timer found");
1718 int VDRClient::getVarInt(PFMap& postFields, const char* paramName) // THROWS
1720 auto i = postFields.find(paramName);
1721 if (i == postFields.end()) throw BadParamException(paramName);
1723 try { r = std::stoi(i->second); }
1724 catch (const std::exception& e) { throw BadParamException(paramName); }
1728 std::string VDRClient::getVarString(PFMap& postFields, const char* paramName, bool emptyOk) // THROWS
1730 auto i = postFields.find(paramName);
1731 if (i == postFields.end()) throw BadParamException(paramName);
1732 if (!emptyOk && i->second.empty()) throw BadParamException(paramName);
1736 bool VDRClient::loadEpgFilter(libconfig::Config& epgFilter)
1738 std::string epgFilterFile(configDir + std::string("/epgfilter.conf"));
1739 FILE* fp = fopen(epgFilterFile.c_str(), "a");
1742 logger->error("loadEpgFilter: Error: Failed to fopen epgfilter.conf");
1749 epgFilter.readFile(epgFilterFile.c_str());
1751 catch (const libconfig::FileIOException &fioex)
1753 logger->error("loadEpgFilter: Error: Failed to read filter file");
1756 catch(const libconfig::ParseException &pex)
1758 logger->error("loadEpgFilter: Parse error at {}: {} - {}", pex.getFile(), pex.getLine(), pex.getError());
1764 libconfig::Setting& setting = epgFilter.lookup("filters");
1766 if (!setting.isList())
1768 logger->error("loadEpgFilter: Error: Failed to read filter file (2)");
1772 catch (const libconfig::SettingNotFoundException& e)
1774 libconfig::Setting& setting = epgFilter.getRoot();
1775 setting.add("filters", libconfig::Setting::Type::TypeList);
1781 bool VDRClient::saveEpgFilter(libconfig::Config& epgFilter)
1783 std::string epgFilterFile(configDir + std::string("/epgfilter.conf"));
1786 epgFilter.writeFile(epgFilterFile.c_str());
1787 logger->debug("saveEpgFilter: EPG filter saved");
1790 catch (const libconfig::FileIOException& e)
1792 logger->error("saveEpgFilter: Error: File write error");