<%pre> #include #include #include #include #include #include #include "exception.h" #include "setup.h" #include "tools.h" #include "epg_events.h" #include "recordings.h" using namespace vdrlive; using namespace std; <%args> int update; <%session scope="global"> bool logged_in(false); <%cpp> if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); EpgEvents epgEvents; string EMPTY_STR; tChannelID prev_chan; tChannelID next_chan; reply.setContentType( "application/xml" ); if (cReplayControl::NowReplaying()) { RecordingsManagerPtr recManager = LiveRecordingsManager(); cRecording *recording = Recordings.GetByName(cReplayControl::NowReplaying()); if (recording) { string name(recording->Name()); size_t index = name.find_last_of('~'); if (index != string::npos) name = name.substr(index, name.length()); const cRecordingInfo* info = recording->Info(); if (info) { EpgEventPtr epgEvent(new EpgEvent(recManager->Md5Hash(recording), tr("playing recording"), info->Title() ? info->Title() : name, info->ShortText() ? info->ShortText() : "", info->Description() ? info->Description() : "", recording->start, recording->start)); epgEvents.push_back(epgEvent); } } } else { string CHANNEL_STR("channel"); ReadLock channelsLock( Channels ); if (cDevice::CurrentChannel()) { const int SKIP_GAP = 1; cChannel* Channel = Channels.GetByNumber(cDevice::CurrentChannel()); cChannel* tmp = Channels.GetByNumber(Channels.GetPrevNormal(cDevice::CurrentChannel()), -SKIP_GAP); if (tmp) prev_chan = tmp->GetChannelID(); tmp = Channels.GetByNumber(Channels.GetNextNormal(cDevice::CurrentChannel()), SKIP_GAP); if (tmp) next_chan = tmp->GetChannelID(); string chanName(Channel->Name()); cSchedulesLock schedulesLock; const cSchedules* Schedules = cSchedules::Schedules(schedulesLock); const cSchedule *Schedule = Schedules->GetSchedule(Channel); if (Schedule) { const cEvent *Event = Schedule->GetPresentEvent(); if (Event) { EpgEventPtr epgEvent(new EpgEvent(CHANNEL_STR, Event, Channel->Name())); epgEvents.push_back(epgEvent); } else { string noInfo(tr("no epg info for current event!")); EpgEventPtr epgEvent(new EpgEvent(CHANNEL_STR, chanName, noInfo, EMPTY_STR, EMPTY_STR, time(0), time(0))); epgEvents.push_back(epgEvent); } } else { string noInfo(tr("no epg info for current channel!")); EpgEventPtr epgEvent(new EpgEvent(CHANNEL_STR, Channel->Name(), noInfo, EMPTY_STR, EMPTY_STR, time(0), time(0))); epgEvents.push_back(epgEvent); } } else { string chanName(tr("no current channel!")); EpgEventPtr epgEvent(new EpgEvent(CHANNEL_STR, chanName, chanName, EMPTY_STR, EMPTY_STR, time(0), time(0))); epgEvents.push_back(epgEvent); } } if (epgEvents.size() == 0) { string ERROR_STR("error"); string noInfo(tr("error retrieving status info!")); string chanName(tr("no current channel!")); EpgEventPtr epgEvent(new EpgEvent(ERROR_STR, chanName, noInfo, EMPTY_STR, EMPTY_STR, time(0), time(0))); epgEvents.push_back(epgEvent); } for (vector::iterator i = epgEvents.begin(); i != epgEvents.end(); ++i) { EpgEventPtr epg = *i; if (prev_chan.Valid() && next_chan.Valid()) { <& xmlresponse.ibox update=(update) type=(epg->Id()) caption=(epg->Caption()) currentTime=(epg->CurrentTime(tr("%I:%M:%S %p"))) duration=(epg->StartTime(tr("%I:%M %p")) + string(" - ") + epg->EndTime(tr("%I:%M %p"))) title=(epg->Title()) elapsed=(epg->Elapsed()) prev_chan=(prev_chan) next_chan=(next_chan) &> <%cpp> } else if (prev_chan.Valid()) { <& xmlresponse.ibox update=(update) type=(epg->Id()) caption=(epg->Caption()) currentTime=(epg->CurrentTime(tr("%I:%M:%S %p"))) duration=(epg->StartTime(tr("%I:%M %p")) + string(" - ") + epg->EndTime(tr("%I:%M %p"))) title=(epg->Title()) elapsed=(epg->Elapsed()) prev_chan=(prev_chan) &> <%cpp> } else if (next_chan.Valid()) { <& xmlresponse.ibox update=(update) type=(epg->Id()) caption=(epg->Caption()) currentTime=(epg->CurrentTime(tr("%I:%M:%S %p"))) duration=(epg->StartTime(tr("%I:%M %p")) + string(" - ") + epg->EndTime(tr("%I:%M %p"))) title=(epg->Title()) elapsed=(epg->Elapsed()) next_chan=(next_chan) &> <%cpp> } else { <& xmlresponse.ibox update=(update) type=(epg->Id()) caption=(epg->Caption()) currentTime=(epg->CurrentTime(tr("%I:%M:%S %p"))) duration=(epg->StartTime(tr("%I:%M %p")) + string(" - ") + epg->EndTime(tr("%I:%M %p"))) title=(epg->Title()) elapsed=(epg->Elapsed()) &> <%cpp> } break; }