Mailing List archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[vdr] [PATCH] New svdrp command LSTS
Since the LSTE command returns the whole EPG data and can take a long
time I was looking for a quicker way to retrieve schedule data via svdrp.
The attached patch implements a new svdrp command LSTS, which returns
schedule data in a way similar to the OSD.
Thomas
Common subdirectories: vdr-1.3.3/PLUGINS and vdr-1.3.3-LSTS/PLUGINS
Common subdirectories: vdr-1.3.3/libsi and vdr-1.3.3-LSTS/libsi
diff -uP vdr-1.3.3/svdrp.c vdr-1.3.3-LSTS/svdrp.c
--- vdr-1.3.3/svdrp.c 2004-01-17 14:47:39.000000000 +0100
+++ vdr-1.3.3-LSTS/svdrp.c 2004-02-07 19:58:14.000000000 +0100
@@ -210,6 +210,11 @@
"LSTR [ <number> ]\n"
" List recordings. Without option, all recordings are listed. Otherwise\n"
" the summary for the given recording is listed.",
+ "LSTS [ <number> | now | next | e <eventid> ]\n"
+ " List schedule. Wihout option, the schedule of the current channel is\n"
+ " listed. Otherwise the schedule of the given channel is listed, 'now'\n"
+ " or 'next' list all current or next running schedule entries. 'e eventid'\n"
+ " lists the specified event in detail.",
"LSTT [ <number> ]\n"
" List timers. Without option, all timers are listed. Otherwise\n"
" only the given timer is listed.",
@@ -760,6 +765,119 @@
Reply(550, "No recordings available");
}
+static int CompareEventChannel(const void *p1, const void *p2)
+{
+ return (int)( (*(const cEvent **)p1)->ChannelNumber() - (*(const cEvent **)p2)->ChannelNumber());
+}
+
+static int CompareEventTime(const void *p1, const void *p2)
+{
+ return (int)((*(cEvent **)p1)->StartTime() - (*(cEvent **)p2)->StartTime());
+}
+
+void cSVDRP::CmdLSTS(const char *Option)
+{
+ int ChannelNr = cDevice::CurrentChannel();
+ int EventID = 0;
+ bool Now = false;
+ bool Next = false;
+ if (*Option) {
+ if (isnumber(Option))
+ ChannelNr = strtol(Option, NULL, 10);
+ else if (strcasecmp(Option, "NOW") == 0)
+ Now = true;
+ else if (strcasecmp(Option, "NEXT") == 0)
+ Next = true;
+ else if (toupper(Option[0]) == 'E')
+ EventID = strtol(&Option[1], NULL, 10);
+ else {
+ Reply(501, "Option \"%s\" not implemented", Option);
+ return;
+ }
+ }
+ cChannel* channel = Channels.GetByNumber(ChannelNr);
+ cSchedulesLock schedulesLock;
+ const cSchedules *Schedules = cSchedules::Schedules(schedulesLock);
+ if (Schedules) {
+ if (EventID) {
+ const cSchedule *Schedule = Schedules->First();
+ const cEvent *Event;
+ while (Schedule) {
+ Event = Schedule->GetEvent(EventID);
+ if (Event) {
+ channel = Channels.GetByChannelID(Event->ChannelID(), true);
+ if (channel)
+ Event->SetChannelNumber(channel->Number());
+ channel = Channels.GetByNumber(Event->ChannelNumber());
+ Reply(250, "%d %s|%s|%s|%s|%s|%s",
+ Event->ChannelNumber(), channel ? channel->Name() : "???",
+ Event->GetDateString(), Event->GetTimeString(),
+ Event->Title(), Event->ShortText(), Event->Description());
+ return;
+ }
+ Schedule = (const cSchedule*)Schedules->Next(Schedule);
+ }
+ Reply(550, "Event %d not found", EventID);
+ }
+ else if (Now || Next) {
+ const cSchedule *Schedule = Schedules->First();
+ const cEvent **pArray = NULL;
+ int num = 0;
+ while (Schedule) {
+ pArray = (const cEvent**)realloc(pArray, (num + 1) * sizeof(cEvent*));
+ pArray[num] = Now ? Schedule->GetPresentEvent() : Schedule->GetFollowingEvent();
+ if (pArray[num]) {
+ channel = Channels.GetByChannelID(pArray[num]->ChannelID(), true);
+ if (channel)
+ pArray[num++]->SetChannelNumber(channel->Number());
+ }
+ Schedule = (const cSchedule*)Schedules->Next(Schedule);
+ }
+ qsort(pArray, num, sizeof(cEvent*), CompareEventChannel);
+ for (int a = 0; a < num; a++) {
+ channel = Channels.GetByNumber(pArray[a]->ChannelNumber());
+ Reply(a<num-1 ? -250 : 250, "%d|%d %s|%s|%s",
+ pArray[a]->EventID(), pArray[a]->ChannelNumber(),
+ channel ? channel->Name() : "???",
+ pArray[a]->GetTimeString(), pArray[a]->Title());
+ }
+ free(pArray);
+ }
+ else if (channel) {
+ const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
+ if (Schedule) {
+ int num = Schedule->NumEvents();
+ if (num > 0) {
+ const cEvent **pArray = MALLOC(const cEvent*, num);
+ if (pArray) {
+ time_t now = time(NULL);
+ int numreal = 0;
+ for (int a = 0; a < num; a++) {
+ const cEvent *Event = Schedule->GetEventNumber(a);
+ if (Event->StartTime() + Event->Duration() > now)
+ pArray[numreal++] = Event;
+ }
+ qsort(pArray, numreal, sizeof(cEvent*), CompareEventTime);
+ for (int a = 0; a < numreal; a++)
+ Reply(a<numreal-1 ? -250 : 250, "%d|%s|%s|%s",
+ pArray[a]->EventID(), pArray[a]->GetDateString(),
+ pArray[a]->GetTimeString(), pArray[a]->Title());
+ free(pArray);
+ }
+ }
+ else
+ Reply(550, "No event available");
+ }
+ else
+ Reply(550, "No schedule available");
+ }
+ else
+ Reply(555, "Channel %s not defined", Option);
+ }
+ else
+ Reply(451, "Can't get EPG data");
+}
+
void cSVDRP::CmdLSTT(const char *Option)
{
if (*Option) {
@@ -1062,6 +1180,7 @@
else if (CMD("LSTC")) CmdLSTC(s);
else if (CMD("LSTE")) CmdLSTE(s);
else if (CMD("LSTR")) CmdLSTR(s);
+ else if (CMD("LSTS")) CmdLSTS(s);
else if (CMD("LSTT")) CmdLSTT(s);
else if (CMD("MESG")) CmdMESG(s);
else if (CMD("MODC")) CmdMODC(s);
diff -uP vdr-1.3.3/svdrp.h vdr-1.3.3-LSTS/svdrp.h
--- vdr-1.3.3/svdrp.h 2004-01-17 14:30:52.000000000 +0100
+++ vdr-1.3.3-LSTS/svdrp.h 2004-02-06 19:49:56.000000000 +0100
@@ -63,6 +63,7 @@
void CmdLSTC(const char *Option);
void CmdLSTE(const char *Option);
void CmdLSTR(const char *Option);
+ void CmdLSTS(const char *Option);
void CmdLSTT(const char *Option);
void CmdMESG(const char *Option);
void CmdMODC(const char *Option);
Home |
Main Index |
Thread Index