2021-05-22 11:40:58 +02:00
|
|
|
#define DISABLE_TEMPLATES_COLLIDING_WITH_STL
|
2014-02-07 16:07:00 +01:00
|
|
|
|
2013-07-09 00:17:42 +02:00
|
|
|
#include <string>
|
2013-12-07 15:51:50 +01:00
|
|
|
#include <sstream>
|
2013-07-09 00:17:42 +02:00
|
|
|
#include <vector>
|
2013-12-07 15:51:50 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <vdr/menu.h>
|
|
|
|
#include "services/remotetimers.h"
|
|
|
|
#include "tools.h"
|
|
|
|
#include "switchtimer.h"
|
2013-12-29 18:13:45 +01:00
|
|
|
#include "timerconflict.h"
|
2018-03-08 13:02:38 +01:00
|
|
|
#include <vdr/timers.h>
|
2013-07-09 00:17:42 +02:00
|
|
|
#include "recmanager.h"
|
|
|
|
|
|
|
|
static int CompareRecording(const void *p1, const void *p2) {
|
|
|
|
return (int)((*(cRecording **)p1)->Start() - (*(cRecording **)p2)->Start());
|
|
|
|
}
|
|
|
|
|
|
|
|
cRecManager::cRecManager(void) {
|
|
|
|
epgSearchPlugin = NULL;
|
|
|
|
epgSearchAvailable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
cRecManager::~cRecManager(void) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void cRecManager::SetEPGSearchPlugin(void) {
|
|
|
|
epgSearchPlugin = cPluginManager::GetPlugin("epgsearch");
|
|
|
|
if (epgSearchPlugin) {
|
|
|
|
epgSearchAvailable = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-20 13:46:26 +02:00
|
|
|
bool cRecManager::RefreshRemoteTimers(void) {
|
|
|
|
cString errorMsg;
|
|
|
|
if (!pRemoteTimers->Service("RemoteTimers::RefreshTimers-v1.0", &errorMsg)) {
|
|
|
|
esyslog("tvguide: %s", *errorMsg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cRecManager::CheckEventForTimer(const cEvent *event) {
|
|
|
|
bool hasTimer = false;
|
2018-04-01 13:39:31 +02:00
|
|
|
|
2019-07-11 11:28:11 +02:00
|
|
|
if (config.useRemoteTimers && pRemoteTimers) {
|
2013-07-20 13:46:26 +02:00
|
|
|
RemoteTimers_GetMatch_v1_0 rtMatch;
|
|
|
|
rtMatch.event = event;
|
|
|
|
pRemoteTimers->Service("RemoteTimers::GetMatch-v1.0", &rtMatch);
|
|
|
|
if (rtMatch.timerMatch == tmFull)
|
|
|
|
hasTimer = true;
|
2019-04-06 18:22:24 +02:00
|
|
|
} else {
|
|
|
|
#if VDRVERSNUM >= 20301
|
|
|
|
eTimerMatch TimerMatch = tmNone;
|
|
|
|
LOCK_TIMERS_READ;
|
|
|
|
const cTimers *timers = Timers;
|
|
|
|
if (timers->GetMatch(event, &TimerMatch) && (TimerMatch == tmFull))
|
|
|
|
hasTimer = true;
|
|
|
|
#else
|
2013-07-20 13:46:26 +02:00
|
|
|
hasTimer = event->HasTimer();
|
2019-04-06 18:22:24 +02:00
|
|
|
#endif
|
|
|
|
}
|
2013-07-20 13:46:26 +02:00
|
|
|
return hasTimer;
|
|
|
|
}
|
|
|
|
|
2018-03-08 13:02:38 +01:00
|
|
|
const cTimer *cRecManager::GetTimerForEvent(const cEvent *event) {
|
|
|
|
const cTimer *timer = NULL;
|
2019-07-11 11:28:11 +02:00
|
|
|
if (config.useRemoteTimers && pRemoteTimers) {
|
2013-07-20 13:46:26 +02:00
|
|
|
RemoteTimers_GetMatch_v1_0 rtMatch;
|
|
|
|
rtMatch.event = event;
|
|
|
|
pRemoteTimers->Service("RemoteTimers::GetMatch-v1.0", &rtMatch);
|
|
|
|
timer = rtMatch.timer;
|
2018-03-08 13:02:38 +01:00
|
|
|
return timer;
|
|
|
|
}
|
2019-03-30 18:06:47 +01:00
|
|
|
|
|
|
|
#if VDRVERSNUM >= 20301
|
2018-04-01 13:39:31 +02:00
|
|
|
LOCK_TIMERS_READ;
|
|
|
|
timer = Timers->GetMatch(event);
|
2018-03-08 13:02:38 +01:00
|
|
|
#else
|
2019-03-30 18:06:47 +01:00
|
|
|
timer = Timers.GetMatch(event);
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2013-07-20 13:46:26 +02:00
|
|
|
return timer;
|
|
|
|
}
|
|
|
|
|
2013-07-18 17:59:59 +02:00
|
|
|
cTimer *cRecManager::createTimer(const cEvent *event, std::string path) {
|
2013-07-20 13:46:26 +02:00
|
|
|
cTimer *timer = NULL;
|
2019-07-11 11:28:11 +02:00
|
|
|
if (config.useRemoteTimers && pRemoteTimers) {
|
2013-07-20 13:46:26 +02:00
|
|
|
timer = createRemoteTimer(event, path);
|
|
|
|
} else {
|
|
|
|
timer = createLocalTimer(event, path);
|
|
|
|
}
|
|
|
|
return timer;
|
|
|
|
}
|
|
|
|
|
|
|
|
cTimer *cRecManager::createLocalTimer(const cEvent *event, std::string path) {
|
2013-07-09 00:17:42 +02:00
|
|
|
cTimer *timer = new cTimer(event);
|
2018-03-08 13:30:41 +01:00
|
|
|
#if VDRVERSNUM >= 20301
|
2018-03-08 13:02:38 +01:00
|
|
|
LOCK_TIMERS_WRITE;
|
2019-07-10 14:43:12 +02:00
|
|
|
cTimers* timers = Timers;
|
2020-02-12 13:14:17 +01:00
|
|
|
timers->SetExplicitModify();
|
|
|
|
if (Setup.SVDRPPeering && *Setup.SVDRPDefaultHost)
|
|
|
|
timer->SetRemote(Setup.SVDRPDefaultHost);
|
2018-03-08 13:02:38 +01:00
|
|
|
#else
|
2019-07-10 14:43:12 +02:00
|
|
|
cTimers* timers = &Timers;
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2019-07-10 14:43:12 +02:00
|
|
|
cTimer *t = timers->GetTimer(timer);
|
2013-07-20 13:46:26 +02:00
|
|
|
if (t) {
|
|
|
|
t->OnOff();
|
2018-03-08 13:30:41 +01:00
|
|
|
#if VDRVERSNUM >= 20301
|
2018-03-08 13:02:38 +01:00
|
|
|
t->SetEvent(event);
|
|
|
|
#else
|
2013-07-20 13:46:26 +02:00
|
|
|
t->SetEventFromSchedule();
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2013-07-20 13:46:26 +02:00
|
|
|
delete timer;
|
|
|
|
timer = t;
|
|
|
|
isyslog("timer %s reactivated", *t->ToDescr());
|
|
|
|
} else {
|
2020-02-12 13:14:17 +01:00
|
|
|
SetTimerPath(timer, event, path);
|
2019-07-10 14:43:12 +02:00
|
|
|
timers->Add(timer);
|
2020-02-12 13:14:17 +01:00
|
|
|
timers->SetModified();
|
|
|
|
#if VDRVERSNUM >= 20301
|
|
|
|
if (!HandleRemoteTimerModifications(timer)) {
|
|
|
|
timers->Del(timer);
|
|
|
|
esyslog(tr("tvguide: RemoteTimerModifications failed"));
|
|
|
|
} else {
|
|
|
|
isyslog("timer %s added (active)", *timer->ToDescr());
|
|
|
|
}
|
|
|
|
#else
|
2013-07-20 13:46:26 +02:00
|
|
|
isyslog("timer %s added (active)", *timer->ToDescr());
|
2020-02-12 13:14:17 +01:00
|
|
|
#endif
|
2013-07-20 13:46:26 +02:00
|
|
|
}
|
2020-02-23 19:41:24 +01:00
|
|
|
return timers->GetTimer(timer);
|
2013-07-20 13:46:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cTimer *cRecManager::createRemoteTimer(const cEvent *event, std::string path) {
|
|
|
|
cTimer *t = new cTimer(event);
|
2013-12-24 11:30:47 +01:00
|
|
|
SetTimerPath(t, event, path);
|
2013-07-20 13:46:26 +02:00
|
|
|
RemoteTimers_Timer_v1_0 rt;
|
|
|
|
rt.timer = t;
|
|
|
|
pRemoteTimers->Service("RemoteTimers::GetTimer-v1.0", &rt.timer);
|
|
|
|
if (rt.timer) {
|
|
|
|
rt.timer->OnOff();
|
|
|
|
if (!pRemoteTimers->Service("RemoteTimers::ModTimer-v1.0", &rt))
|
|
|
|
rt.timer = NULL;
|
|
|
|
} else {
|
|
|
|
rt.timer = t;
|
|
|
|
if (!pRemoteTimers->Service("RemoteTimers::NewTimer-v1.0", &rt))
|
|
|
|
isyslog("%s", *rt.errorMsg);
|
|
|
|
}
|
|
|
|
RefreshRemoteTimers();
|
|
|
|
return rt.timer;
|
|
|
|
}
|
|
|
|
|
2013-12-24 11:30:47 +01:00
|
|
|
void cRecManager::SetTimerPath(cTimer *timer, const cEvent *event, std::string path) {
|
2019-07-11 11:28:11 +02:00
|
|
|
if (config.instRecFolderMode == eFolderFixed) {
|
2014-02-06 17:38:55 +01:00
|
|
|
Epgsearch_services_v1_2 *epgSearch = new Epgsearch_services_v1_2;
|
2019-07-11 11:28:11 +02:00
|
|
|
std::string recDir = config.instRecFixedFolder;
|
2014-02-06 17:38:55 +01:00
|
|
|
std::replace(recDir.begin(), recDir.end(), '/', '~');
|
|
|
|
if (strchr(recDir.c_str(), '%') != NULL) {
|
|
|
|
if (epgSearchPlugin->Service("Epgsearch-services-v1.1", epgSearch)) {
|
|
|
|
std::string newFileName = epgSearch->handler->Evaluate(recDir, event);
|
|
|
|
if (strchr(newFileName.c_str(), '%') == NULL) // only set directory to new value if all categories could have been replaced
|
|
|
|
timer->SetFile(newFileName.c_str());
|
2018-04-01 13:39:31 +02:00
|
|
|
else
|
2014-02-06 17:38:55 +01:00
|
|
|
esyslog("tvguide: timer path not set because replacing variable was not successfull: %s", newFileName.c_str());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cString newFileName;
|
|
|
|
if (recDir.size() > 0) {
|
|
|
|
newFileName = cString::sprintf("%s~%s", recDir.c_str(), timer->File());
|
|
|
|
timer->SetFile(*newFileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//Set choosen path
|
2020-02-17 14:15:44 +01:00
|
|
|
bool addSubtitle = false;
|
|
|
|
if (!isempty(event->ShortText())) { // add subtitle if present
|
|
|
|
addSubtitle = (config.addSubtitleToTimer != addSubtitleNever);
|
|
|
|
if (config.addSubtitleToTimer == addSubtitleSmart)
|
|
|
|
if (event->Duration() > 80 * 60)
|
|
|
|
addSubtitle = false;
|
|
|
|
}
|
2013-12-24 11:30:47 +01:00
|
|
|
cString newFileName;
|
2013-07-18 17:59:59 +02:00
|
|
|
if (path.size() > 0) {
|
|
|
|
std::replace(path.begin(), path.end(), '/', '~');
|
2020-02-17 14:15:44 +01:00
|
|
|
if (addSubtitle)
|
|
|
|
newFileName = cString::sprintf("%s~%s~%s", path.c_str(), event->Title(), event->ShortText());
|
|
|
|
else
|
|
|
|
newFileName = cString::sprintf("%s~%s", path.c_str(), timer->File());
|
2013-12-24 11:30:47 +01:00
|
|
|
} else {
|
2020-02-17 14:15:44 +01:00
|
|
|
if (addSubtitle)
|
|
|
|
newFileName = cString::sprintf("%s~%s", event->Title(), event->ShortText());
|
|
|
|
else
|
|
|
|
newFileName = event->Title();
|
2013-07-18 17:59:59 +02:00
|
|
|
}
|
2013-12-24 11:30:47 +01:00
|
|
|
timer->SetFile(*newFileName);
|
2013-07-09 00:17:42 +02:00
|
|
|
}
|
|
|
|
|
2013-07-20 13:46:26 +02:00
|
|
|
void cRecManager::DeleteTimer(const cEvent *event) {
|
2014-01-10 12:44:01 +01:00
|
|
|
if (!event)
|
|
|
|
return;
|
2019-07-11 11:28:11 +02:00
|
|
|
if (config.useRemoteTimers && pRemoteTimers) {
|
2013-07-20 13:46:26 +02:00
|
|
|
DeleteRemoteTimer(event);
|
|
|
|
} else {
|
|
|
|
DeleteLocalTimer(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cRecManager::DeleteLocalTimer(const cEvent *event) {
|
2019-03-30 18:06:47 +01:00
|
|
|
const cTimer *t;
|
2018-03-08 13:30:41 +01:00
|
|
|
#if VDRVERSNUM >= 20301
|
2018-03-31 15:21:32 +02:00
|
|
|
{
|
2019-03-30 18:06:47 +01:00
|
|
|
LOCK_TIMERS_READ;
|
2018-03-31 15:21:32 +02:00
|
|
|
t = Timers->GetMatch(event);
|
|
|
|
}
|
2018-03-08 13:02:38 +01:00
|
|
|
#else
|
2019-03-30 18:06:47 +01:00
|
|
|
t = Timers.GetMatch(event);
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2013-07-09 00:17:42 +02:00
|
|
|
if (!t)
|
|
|
|
return;
|
|
|
|
DeleteTimer(t);
|
|
|
|
}
|
|
|
|
|
2019-03-30 18:06:47 +01:00
|
|
|
void cRecManager::DeleteTimer(const cTimer *timer) {
|
2018-04-01 15:53:09 +02:00
|
|
|
#if VDRVERSNUM >= 20301
|
2018-03-08 13:02:38 +01:00
|
|
|
LOCK_TIMERS_WRITE;
|
2019-03-30 18:06:47 +01:00
|
|
|
cTimers* timers = Timers;
|
2020-02-12 13:14:17 +01:00
|
|
|
if (timer && timer->Remote() && !timer->Recording()) {
|
|
|
|
if (HandleRemoteTimerModifications(NULL, (cTimer*)timer)) {
|
|
|
|
timers->Del((cTimer*)timer);
|
|
|
|
}
|
|
|
|
timers->SetModified();
|
|
|
|
}
|
2019-03-30 18:06:47 +01:00
|
|
|
cTimer* t = timers->GetTimer(timer);
|
2018-04-01 15:53:09 +02:00
|
|
|
#else
|
2019-03-30 18:06:47 +01:00
|
|
|
cTimers* timers = &Timers;
|
|
|
|
cTimer* t = timers->GetTimer((cTimer*)timer);
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2019-07-06 12:14:19 +02:00
|
|
|
if (!t)
|
|
|
|
return;
|
2019-03-30 18:06:47 +01:00
|
|
|
if (t->Recording()) {
|
|
|
|
t->Skip();
|
2018-03-08 13:30:41 +01:00
|
|
|
#if VDRVERSNUM >= 20301
|
2019-03-30 18:06:47 +01:00
|
|
|
cRecordControls::Process(timers, time(NULL));
|
2018-03-08 13:02:38 +01:00
|
|
|
#else
|
2019-03-30 18:06:47 +01:00
|
|
|
cRecordControls::Process(time(NULL));
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2019-07-10 16:14:58 +02:00
|
|
|
}
|
2019-03-30 18:06:47 +01:00
|
|
|
isyslog("timer %s deleted", *t->ToDescr());
|
|
|
|
timers->Del(t, true);
|
|
|
|
timers->SetModified();
|
2013-07-09 00:17:42 +02:00
|
|
|
}
|
|
|
|
|
2013-07-20 13:46:26 +02:00
|
|
|
void cRecManager::DeleteRemoteTimer(const cEvent *event) {
|
|
|
|
RemoteTimers_GetMatch_v1_0 rtMatch;
|
|
|
|
rtMatch.event = event;
|
|
|
|
pRemoteTimers->Service("RemoteTimers::GetMatch-v1.0", &rtMatch);
|
|
|
|
if (rtMatch.timer) {
|
|
|
|
RemoteTimers_Timer_v1_0 rt;
|
|
|
|
rt.timer = rtMatch.timer;
|
|
|
|
isyslog("remotetimer %s deleted", *rt.timer->ToDescr());
|
|
|
|
if (!pRemoteTimers->Service("RemoteTimers::DelTimer-v1.0", &rt))
|
|
|
|
isyslog("remotetimer error");
|
|
|
|
RefreshRemoteTimers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-04 15:08:37 +02:00
|
|
|
void cRecManager::OnOffTimer(const cEvent *event) {
|
|
|
|
const cTimer *t;
|
|
|
|
#if VDRVERSNUM >= 20301
|
|
|
|
{
|
|
|
|
LOCK_TIMERS_READ;
|
|
|
|
t = Timers->GetMatch(event);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
t = Timers.GetMatch(event);
|
|
|
|
#endif
|
|
|
|
if (!t)
|
|
|
|
return;
|
|
|
|
SaveTimer(t);
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:14:17 +01:00
|
|
|
void cRecManager::SaveTimer(const cTimer *t, cTimer *newTimerSettings) {
|
2018-04-01 14:06:43 +02:00
|
|
|
if (!t)
|
2013-07-09 00:17:42 +02:00
|
|
|
return;
|
2018-04-01 13:39:31 +02:00
|
|
|
|
2018-04-01 14:06:43 +02:00
|
|
|
#if VDRVERSNUM >= 20301
|
|
|
|
LOCK_TIMERS_WRITE;
|
2020-02-12 13:14:17 +01:00
|
|
|
cTimers* timers = Timers;
|
|
|
|
timers->SetExplicitModify();
|
|
|
|
if (t && t->Remote()) {
|
|
|
|
if (!HandleRemoteTimerModifications(newTimerSettings, (cTimer *)t)) {
|
|
|
|
esyslog(tr("tvguide: RemoteTimerModifications failed"));
|
|
|
|
}
|
|
|
|
}
|
2020-03-04 15:25:44 +01:00
|
|
|
cTimer *timer = timers->GetTimer(t);
|
2019-03-30 18:06:47 +01:00
|
|
|
#else
|
2020-02-12 13:14:17 +01:00
|
|
|
cTimers* timers = &Timers;
|
2020-03-04 15:25:44 +01:00
|
|
|
cTimer *timer = timers->GetTimer((cTimer *)t);
|
2018-04-01 14:06:43 +02:00
|
|
|
#endif
|
2020-02-12 13:14:17 +01:00
|
|
|
if (!timer) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-09 00:17:42 +02:00
|
|
|
|
2020-08-04 15:08:37 +02:00
|
|
|
bool active = true;
|
|
|
|
if (newTimerSettings) {
|
|
|
|
int prio = newTimerSettings->Priority();
|
|
|
|
int lifetime = newTimerSettings->Lifetime();
|
|
|
|
time_t day = newTimerSettings->Day();
|
|
|
|
int start = newTimerSettings->Start();
|
|
|
|
int stop = newTimerSettings->Stop();
|
|
|
|
std::string fileName = newTimerSettings->File();
|
|
|
|
|
|
|
|
timer->SetDay(day);
|
|
|
|
timer->SetStart(start);
|
|
|
|
timer->SetStop(stop);
|
|
|
|
timer->SetPriority(prio);
|
|
|
|
timer->SetLifetime(lifetime);
|
|
|
|
timer->SetFile(fileName.c_str());
|
|
|
|
|
|
|
|
active = newTimerSettings->HasFlags(tfActive);
|
|
|
|
} else
|
|
|
|
active = !timer->HasFlags(tfActive);
|
2018-03-08 13:02:38 +01:00
|
|
|
|
2020-02-12 13:14:17 +01:00
|
|
|
if (active)
|
|
|
|
timer->SetFlags(tfActive);
|
|
|
|
else
|
|
|
|
timer->ClrFlags(tfActive);
|
2018-03-08 13:02:38 +01:00
|
|
|
|
2018-04-01 14:06:43 +02:00
|
|
|
#if VDRVERSNUM < 20300
|
2013-07-09 00:17:42 +02:00
|
|
|
timer->SetEventFromSchedule();
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2019-07-11 11:28:11 +02:00
|
|
|
if (config.useRemoteTimers && pRemoteTimers) {
|
2013-07-20 13:46:26 +02:00
|
|
|
RemoteTimers_Timer_v1_0 rt;
|
|
|
|
rt.timer = timer;
|
|
|
|
if (!pRemoteTimers->Service("RemoteTimers::ModTimer-v1.0", &rt))
|
|
|
|
rt.timer = NULL;
|
|
|
|
RefreshRemoteTimers();
|
|
|
|
} else {
|
2020-02-12 13:14:17 +01:00
|
|
|
timers->SetModified();
|
2018-04-01 13:39:31 +02:00
|
|
|
}
|
2013-07-09 00:17:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cRecManager::IsRecorded(const cEvent *event) {
|
2018-03-08 13:30:41 +01:00
|
|
|
#if VDRVERSNUM >= 20301
|
2018-03-08 13:02:38 +01:00
|
|
|
LOCK_TIMERS_WRITE;
|
|
|
|
cTimer *timer = Timers->GetMatch(event);
|
|
|
|
#else
|
2013-07-09 00:17:42 +02:00
|
|
|
cTimer *timer = Timers.GetMatch(event);
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2013-07-09 00:17:42 +02:00
|
|
|
if (!timer)
|
|
|
|
return false;
|
|
|
|
return timer->Recording();
|
|
|
|
}
|
|
|
|
|
2013-12-29 18:13:45 +01:00
|
|
|
cTVGuideTimerConflicts *cRecManager::CheckTimerConflict(void) {
|
|
|
|
cTVGuideTimerConflicts *conflictList = new cTVGuideTimerConflicts();
|
2013-07-09 00:17:42 +02:00
|
|
|
if (!epgSearchAvailable)
|
2013-12-29 18:13:45 +01:00
|
|
|
return conflictList;
|
2013-07-09 00:17:42 +02:00
|
|
|
Epgsearch_services_v1_1 *epgSearch = new Epgsearch_services_v1_1;
|
|
|
|
if (epgSearchPlugin->Service("Epgsearch-services-v1.1", epgSearch)) {
|
|
|
|
std::list<std::string> conflicts = epgSearch->handler->TimerConflictList();
|
|
|
|
int numConflicts = conflicts.size();
|
2013-12-29 18:13:45 +01:00
|
|
|
if (numConflicts == 0)
|
|
|
|
return conflictList;
|
|
|
|
for (std::list<std::string>::iterator it=conflicts.begin(); it != conflicts.end(); ++it) {
|
|
|
|
conflictList->AddConflict(*it);
|
2013-07-09 00:17:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
delete epgSearch;
|
2013-12-29 18:13:45 +01:00
|
|
|
conflictList->CalculateConflicts();
|
|
|
|
return conflictList;
|
2013-07-09 00:17:42 +02:00
|
|
|
}
|
|
|
|
|
2014-01-10 12:44:01 +01:00
|
|
|
void cRecManager::CreateSeriesTimer(cTimer *seriesTimer) {
|
2019-07-06 12:14:19 +02:00
|
|
|
#if VDRVERSNUM < 20300
|
2013-07-09 00:17:42 +02:00
|
|
|
seriesTimer->SetEventFromSchedule();
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2019-07-11 11:28:11 +02:00
|
|
|
if (config.useRemoteTimers && pRemoteTimers) {
|
2013-07-20 13:46:26 +02:00
|
|
|
RemoteTimers_Timer_v1_0 rt;
|
|
|
|
rt.timer = seriesTimer;
|
|
|
|
if (!pRemoteTimers->Service("RemoteTimers::NewTimer-v1.0", &rt))
|
|
|
|
isyslog("%s", *rt.errorMsg);
|
|
|
|
RefreshRemoteTimers();
|
|
|
|
} else {
|
2018-03-08 13:30:41 +01:00
|
|
|
#if VDRVERSNUM >= 20301
|
2018-03-08 13:02:38 +01:00
|
|
|
LOCK_TIMERS_WRITE;
|
|
|
|
cTimers* timers = Timers;
|
|
|
|
#else
|
2019-07-06 12:14:19 +02:00
|
|
|
cTimers* timers = &Timers;
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2019-07-06 12:14:19 +02:00
|
|
|
timers->Add(seriesTimer);
|
|
|
|
timers->SetModified();
|
2013-07-20 13:46:26 +02:00
|
|
|
}
|
2013-07-09 00:17:42 +02:00
|
|
|
}
|
|
|
|
|
2014-01-10 12:44:01 +01:00
|
|
|
|
|
|
|
void cRecManager::ReadEPGSearchTemplates(std::vector<TVGuideEPGSearchTemplate> *epgTemplates) {
|
2013-07-09 00:17:42 +02:00
|
|
|
cString ConfigDir = cPlugin::ConfigDirectory("epgsearch");
|
|
|
|
cString epgsearchConf = "epgsearchtemplates.conf";
|
|
|
|
cString fileName = AddDirectory(*ConfigDir, *epgsearchConf);
|
|
|
|
if (access(fileName, F_OK) == 0) {
|
|
|
|
FILE *f = fopen(fileName, "r");
|
|
|
|
if (f) {
|
|
|
|
char *s;
|
|
|
|
cReadLine ReadLine;
|
|
|
|
while ((s = ReadLine.Read(f)) != NULL) {
|
|
|
|
char *p = strchr(s, '#');
|
|
|
|
if (p)
|
|
|
|
*p = 0;
|
|
|
|
stripspace(s);
|
|
|
|
try {
|
|
|
|
if (!isempty(s)) {
|
|
|
|
std::string templ = s;
|
|
|
|
int posID = templ.find_first_of(":");
|
|
|
|
int posName = templ.find_first_of(":", posID+1);
|
|
|
|
std::string name = templ.substr(posID+1, posName - posID - 1);
|
|
|
|
std::string templValue = templ.substr(posName);
|
|
|
|
TVGuideEPGSearchTemplate tmp;
|
|
|
|
tmp.name = name;
|
|
|
|
tmp.templValue = templValue;
|
2014-01-10 12:44:01 +01:00
|
|
|
epgTemplates->push_back(tmp);
|
2013-07-09 00:17:42 +02:00
|
|
|
}
|
|
|
|
} catch (...){}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const cEvent **cRecManager::PerformSearchTimerSearch(std::string epgSearchString, int &numResults) {
|
|
|
|
if (!epgSearchAvailable)
|
|
|
|
return NULL;
|
|
|
|
const cEvent **searchResults = NULL;
|
|
|
|
Epgsearch_services_v1_1 *epgSearch = new Epgsearch_services_v1_1;
|
|
|
|
if (epgSearchPlugin->Service("Epgsearch-services-v1.1", epgSearch)) {
|
|
|
|
std::list<std::string> results = epgSearch->handler->QuerySearch(epgSearchString);
|
|
|
|
numResults = results.size();
|
|
|
|
if (numResults > 0) {
|
|
|
|
searchResults = new const cEvent *[numResults];
|
2019-03-28 13:10:31 +01:00
|
|
|
const cSchedules *schedules;
|
2018-03-08 13:30:41 +01:00
|
|
|
#if VDRVERSNUM >= 20301
|
2019-03-28 13:10:31 +01:00
|
|
|
{
|
2018-03-08 13:02:38 +01:00
|
|
|
LOCK_SCHEDULES_READ;
|
2019-03-28 13:10:31 +01:00
|
|
|
schedules = Schedules;
|
|
|
|
}
|
2018-03-08 13:02:38 +01:00
|
|
|
#else
|
2013-07-09 17:06:49 +02:00
|
|
|
cSchedulesLock schedulesLock;
|
|
|
|
schedules = cSchedules::Schedules(schedulesLock);
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2013-07-09 00:17:42 +02:00
|
|
|
const cEvent *event = NULL;
|
|
|
|
int index=0;
|
|
|
|
for (std::list<std::string>::iterator it=results.begin(); it != results.end(); ++it) {
|
|
|
|
try {
|
|
|
|
splitstring s(it->c_str());
|
|
|
|
std::vector<std::string> flds = s.split(':', 1);
|
|
|
|
int eventID = atoi(flds[1].c_str());
|
|
|
|
std::string channelID = flds[7];
|
|
|
|
tChannelID chanID = tChannelID::FromString(channelID.c_str());
|
2019-03-28 13:10:31 +01:00
|
|
|
const cChannel *channel;
|
2018-03-08 13:30:41 +01:00
|
|
|
#if VDRVERSNUM >= 20301
|
2019-03-28 13:10:31 +01:00
|
|
|
{
|
2018-03-08 13:02:38 +01:00
|
|
|
LOCK_CHANNELS_READ;
|
2019-03-28 13:10:31 +01:00
|
|
|
channel = Channels->GetByChannelID(chanID);
|
|
|
|
}
|
2018-03-08 13:02:38 +01:00
|
|
|
#else
|
2019-03-28 13:10:31 +01:00
|
|
|
channel = Channels.GetByChannelID(chanID);
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2013-07-09 00:17:42 +02:00
|
|
|
if (channel) {
|
|
|
|
const cSchedule *Schedule = NULL;
|
|
|
|
Schedule = schedules->GetSchedule(channel);
|
|
|
|
event = Schedule->GetEvent(eventID);
|
|
|
|
if (event) {
|
2018-04-01 13:39:31 +02:00
|
|
|
searchResults[index] = event;
|
2013-07-09 00:17:42 +02:00
|
|
|
} else
|
|
|
|
return NULL;
|
|
|
|
} else
|
|
|
|
return NULL;
|
|
|
|
index++;
|
|
|
|
} catch (...){}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return searchResults;
|
|
|
|
}
|
|
|
|
|
2014-01-10 12:44:01 +01:00
|
|
|
const cEvent **cRecManager::PerformSearch(Epgsearch_searchresults_v1_0 data, int &numResults) {
|
2013-07-09 00:17:42 +02:00
|
|
|
if (epgSearchAvailable) {
|
|
|
|
if (epgSearchPlugin->Service("Epgsearch-searchresults-v1.0", &data)) {
|
|
|
|
cList<Epgsearch_searchresults_v1_0::cServiceSearchResult> *list = data.pResultList;
|
2013-07-23 18:50:33 +02:00
|
|
|
if (!list)
|
|
|
|
return NULL;
|
2013-07-09 00:17:42 +02:00
|
|
|
int numElements = list->Count();
|
|
|
|
const cEvent **searchResults = NULL;
|
|
|
|
if (numElements > 0) {
|
|
|
|
searchResults = new const cEvent *[numElements];
|
|
|
|
numResults = numElements;
|
|
|
|
int index = 0;
|
|
|
|
for (Epgsearch_searchresults_v1_0::cServiceSearchResult *r = list->First(); r ; r = list->Next(r)) {
|
|
|
|
searchResults[index] = r->event;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete list;
|
|
|
|
return searchResults;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-01-10 12:44:01 +01:00
|
|
|
void cRecManager::GetSearchTimers(std::vector<cTVGuideSearchTimer> *searchTimer) {
|
|
|
|
if (!epgSearchAvailable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Epgsearch_services_v1_1 *epgSearch = new Epgsearch_services_v1_1;
|
|
|
|
if (epgSearchPlugin->Service("Epgsearch-services-v1.1", epgSearch)) {
|
|
|
|
std::list<std::string> searchTimerList;
|
|
|
|
searchTimerList = epgSearch->handler->SearchTimerList();
|
|
|
|
for(std::list<std::string>::iterator it = searchTimerList.begin(); it != searchTimerList.end(); it++) {
|
|
|
|
cTVGuideSearchTimer timer;
|
|
|
|
timer.SetEPGSearchString(it->c_str());
|
|
|
|
if (timer.Parse())
|
|
|
|
searchTimer->push_back(timer);
|
|
|
|
}
|
|
|
|
}
|
2014-02-07 16:07:00 +01:00
|
|
|
std::sort(searchTimer->begin(), searchTimer->end());
|
2014-01-10 12:44:01 +01:00
|
|
|
}
|
|
|
|
|
2019-06-16 13:45:47 +02:00
|
|
|
void cRecManager::GetSearchExtCats(std::vector<std::string> *searchExtCats) {
|
|
|
|
if (!epgSearchAvailable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Epgsearch_services_v1_1 *epgSearch = new Epgsearch_services_v1_1;
|
|
|
|
if (epgSearchPlugin->Service("Epgsearch-services-v1.1", epgSearch)) {
|
|
|
|
std::list<std::string> list;
|
|
|
|
list = epgSearch->handler->ExtEPGInfoList();
|
|
|
|
|
|
|
|
for (std::list<std::string>::iterator it = list.begin(); it != list.end(); it++) {
|
|
|
|
searchExtCats->push_back(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-09 18:25:58 +02:00
|
|
|
void cRecManager::GetChannelGroups(std::vector<std::string> *channelGroups) {
|
|
|
|
if (!epgSearchAvailable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Epgsearch_services_v1_1 *epgSearch = new Epgsearch_services_v1_1;
|
|
|
|
if (epgSearchPlugin->Service("Epgsearch-services-v1.1", epgSearch)) {
|
2019-06-16 13:45:47 +02:00
|
|
|
std::list<std::string> list;
|
|
|
|
list = epgSearch->handler->ChanGrpList();
|
2019-04-09 18:25:58 +02:00
|
|
|
|
2019-06-16 13:45:47 +02:00
|
|
|
for (std::list<std::string>::iterator it = list.begin(); it != list.end(); it++) {
|
2019-04-09 18:25:58 +02:00
|
|
|
channelGroups->push_back(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::sort(channelGroups->begin(), channelGroups->end());
|
|
|
|
}
|
|
|
|
|
2019-06-16 13:45:47 +02:00
|
|
|
void cRecManager::GetBlacklists(std::vector<std::string> *blacklists) {
|
|
|
|
if (!epgSearchAvailable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Epgsearch_services_v1_1 *epgSearch = new Epgsearch_services_v1_1;
|
|
|
|
if (epgSearchPlugin->Service("Epgsearch-services-v1.1", epgSearch)) {
|
|
|
|
std::list<std::string> list;
|
|
|
|
list = epgSearch->handler->BlackList();
|
|
|
|
|
|
|
|
for (std::list<std::string>::iterator it = list.begin(); it != list.end(); it++) {
|
|
|
|
blacklists->push_back(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 00:17:42 +02:00
|
|
|
int cRecManager::CreateSearchTimer(std::string epgSearchString) {
|
|
|
|
int timerID = -1;
|
|
|
|
if (!epgSearchAvailable)
|
|
|
|
return timerID;
|
|
|
|
Epgsearch_services_v1_1 *epgSearch = new Epgsearch_services_v1_1;
|
|
|
|
if (epgSearchPlugin->Service("Epgsearch-services-v1.1", epgSearch)) {
|
|
|
|
timerID = epgSearch->handler->AddSearchTimer(epgSearchString);
|
|
|
|
}
|
|
|
|
return timerID;
|
|
|
|
}
|
|
|
|
|
2014-01-10 12:44:01 +01:00
|
|
|
bool cRecManager::SaveSearchTimer(cTVGuideSearchTimer *searchTimer) {
|
|
|
|
if (!epgSearchAvailable)
|
|
|
|
return false;
|
|
|
|
Epgsearch_services_v1_1 *epgSearch = new Epgsearch_services_v1_1;
|
|
|
|
if (searchTimer->GetID() > -1) {
|
|
|
|
if (epgSearchPlugin->Service("Epgsearch-services-v1.1", epgSearch)) {
|
|
|
|
bool success = epgSearch->handler->ModSearchTimer(searchTimer->BuildSearchString());
|
|
|
|
if (success) {
|
|
|
|
esyslog("tvguide: search timer with id %d sucessfully modified", searchTimer->GetID());
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
esyslog("tvguide: error modifying search timer with id %d, build string %s", searchTimer->GetID(), searchTimer->BuildSearchString().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (epgSearchPlugin->Service("Epgsearch-services-v1.1", epgSearch)) {
|
|
|
|
int timerID = epgSearch->handler->AddSearchTimer(searchTimer->BuildSearchString());
|
|
|
|
if (timerID >=0) {
|
|
|
|
esyslog("tvguide: search timer with id %d sucessfully created", timerID);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
esyslog("tvguide: error creating search timer, build string %s", searchTimer->BuildSearchString().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cRecManager::DeleteSearchTimer(cTVGuideSearchTimer *searchTimer, bool delTimers) {
|
|
|
|
if (!epgSearchAvailable)
|
|
|
|
return;
|
|
|
|
int searchTimerID = searchTimer->GetID();
|
|
|
|
if (delTimers) {
|
2019-03-30 16:49:50 +01:00
|
|
|
cTimers* timers;
|
2018-03-08 13:30:41 +01:00
|
|
|
#if VDRVERSNUM >= 20301
|
2019-03-30 16:49:50 +01:00
|
|
|
{
|
2018-03-08 13:02:38 +01:00
|
|
|
LOCK_TIMERS_WRITE;
|
2019-03-30 16:49:50 +01:00
|
|
|
timers = Timers;
|
|
|
|
}
|
2018-03-08 13:02:38 +01:00
|
|
|
#else
|
2019-03-30 16:49:50 +01:00
|
|
|
timers = &Timers;
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2019-03-30 16:49:50 +01:00
|
|
|
cTimer *timer = timers->First();
|
2019-07-10 16:14:58 +02:00
|
|
|
while (timer) {
|
2014-01-10 12:44:01 +01:00
|
|
|
if (!timer->Recording()) {
|
|
|
|
char* searchID = GetAuxValue(timer, "s-id");
|
|
|
|
if (searchID) {
|
|
|
|
if (searchTimerID == atoi(searchID)) {
|
2019-03-30 16:49:50 +01:00
|
|
|
cTimer* timerNext = timers->Next(timer);
|
2014-01-10 12:44:01 +01:00
|
|
|
DeleteTimer(timer);
|
|
|
|
timer = timerNext;
|
|
|
|
} else {
|
2019-03-30 16:49:50 +01:00
|
|
|
timer = timers->Next(timer);
|
2014-01-10 12:44:01 +01:00
|
|
|
}
|
|
|
|
free(searchID);
|
|
|
|
} else {
|
2019-03-30 16:49:50 +01:00
|
|
|
timer = timers->Next(timer);
|
2014-01-10 12:44:01 +01:00
|
|
|
}
|
|
|
|
} else {
|
2019-03-30 16:49:50 +01:00
|
|
|
timer = timers->Next(timer);
|
2014-01-10 12:44:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Epgsearch_services_v1_1 *epgSearch = new Epgsearch_services_v1_1;
|
|
|
|
if (epgSearchPlugin->Service("Epgsearch-services-v1.1", epgSearch)) {
|
|
|
|
bool success = epgSearch->handler->DelSearchTimer(searchTimerID);
|
|
|
|
if (success) {
|
2019-06-16 13:11:28 +02:00
|
|
|
esyslog("tvguide: search timer \"%s\" sucessfully deleted", searchTimer->GetSearchString().c_str());
|
2014-01-10 12:44:01 +01:00
|
|
|
} else {
|
2019-06-16 13:11:28 +02:00
|
|
|
esyslog("tvguide: error deleting search timer \"%s\"", searchTimer->GetSearchString().c_str());
|
2014-01-10 12:44:01 +01:00
|
|
|
}
|
2018-04-01 13:39:31 +02:00
|
|
|
}
|
2014-01-10 12:44:01 +01:00
|
|
|
}
|
|
|
|
|
2013-07-09 00:17:42 +02:00
|
|
|
void cRecManager::UpdateSearchTimers(void) {
|
|
|
|
if (epgSearchAvailable) {
|
|
|
|
Epgsearch_updatesearchtimers_v1_0 data;
|
|
|
|
data.showMessage = false;
|
|
|
|
epgSearchPlugin->Service("Epgsearch-updatesearchtimers-v1.0", &data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 11:35:45 +02:00
|
|
|
// switchMode: 0 = switch, 1 = announce only, 2 = ask for switch
|
2014-01-10 12:44:01 +01:00
|
|
|
bool cRecManager::CreateSwitchTimer(const cEvent *event, cSwitchTimer switchTimer) {
|
|
|
|
if (epgSearchAvailable && event) {
|
2013-07-09 00:17:42 +02:00
|
|
|
Epgsearch_switchtimer_v1_0 data;
|
|
|
|
data.event = event;
|
|
|
|
data.mode = 1;
|
2014-01-10 12:44:01 +01:00
|
|
|
data.switchMinsBefore = switchTimer.switchMinsBefore;
|
2019-04-05 11:35:45 +02:00
|
|
|
data.announceOnly = switchTimer.switchMode;
|
2013-07-09 00:17:42 +02:00
|
|
|
data.success = false;
|
|
|
|
epgSearchPlugin->Service("Epgsearch-switchtimer-v1.0", &data);
|
|
|
|
cSwitchTimer *t = new cSwitchTimer(event);
|
|
|
|
SwitchTimers.Add(t);
|
|
|
|
return data.success;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cRecManager::DeleteSwitchTimer(const cEvent *event) {
|
|
|
|
SwitchTimers.DeleteSwitchTimer(event);
|
|
|
|
if (epgSearchAvailable) {
|
|
|
|
Epgsearch_switchtimer_v1_0 data;
|
|
|
|
data.event = event;
|
|
|
|
data.mode = 2;
|
|
|
|
data.switchMinsBefore = 0;
|
|
|
|
data.announceOnly = 0;
|
|
|
|
data.success = false;
|
|
|
|
epgSearchPlugin->Service("Epgsearch-switchtimer-v1.0", &data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-08 13:02:38 +01:00
|
|
|
const cRecording **cRecManager::SearchForRecordings(std::string searchString, int &numResults) {
|
|
|
|
|
|
|
|
const cRecording **matchingRecordings = NULL;
|
2013-07-09 00:17:42 +02:00
|
|
|
int num = 0;
|
|
|
|
numResults = 0;
|
2018-04-01 13:39:31 +02:00
|
|
|
|
2018-03-08 13:30:41 +01:00
|
|
|
#if VDRVERSNUM >= 20301
|
2018-03-08 13:02:38 +01:00
|
|
|
LOCK_RECORDINGS_READ;
|
2019-03-30 18:06:47 +01:00
|
|
|
const cRecordings* recordings = Recordings;
|
2018-03-08 13:02:38 +01:00
|
|
|
#else
|
2019-03-30 18:06:47 +01:00
|
|
|
const cRecordings* recordings = &Recordings;
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2019-03-30 18:06:47 +01:00
|
|
|
|
|
|
|
for (const cRecording *recording = recordings->First(); recording; recording = recordings->Next(recording)) {
|
2013-07-09 00:17:42 +02:00
|
|
|
std::string s1 = recording->Name();
|
2014-01-10 12:44:01 +01:00
|
|
|
std::string s2 = searchString;
|
2013-07-09 00:17:42 +02:00
|
|
|
if (s1.empty() || s2.empty()) continue;
|
2018-04-01 13:39:31 +02:00
|
|
|
|
2013-07-09 00:17:42 +02:00
|
|
|
// tolerance for fuzzy searching: 90% of the shorter text length, but at least 1
|
2018-04-01 13:39:31 +02:00
|
|
|
int tolerance = std::max(1, (int)std::min(s1.size(), s2.size()) / 10);
|
2013-07-09 00:17:42 +02:00
|
|
|
|
|
|
|
bool match = FindIgnoreCase(s1, s2) >= 0 || FindIgnoreCase(s2, s1) >= 0;
|
2018-04-01 13:39:31 +02:00
|
|
|
|
2013-07-09 00:17:42 +02:00
|
|
|
if (!match) {
|
|
|
|
AFUZZY af = { NULL, NULL, NULL, NULL, NULL, NULL, { 0 }, { 0 }, 0, 0, 0, 0, 0, 0 };
|
|
|
|
if (s1.size() > 32) s1 = s1.substr(0, 32);
|
|
|
|
afuzzy_init(s1.c_str(), tolerance, 0, &af);
|
|
|
|
/* Checking substring */
|
|
|
|
int res = afuzzy_checkSUB(s2.c_str(), &af);
|
|
|
|
afuzzy_free(&af);
|
|
|
|
match = (res > 0);
|
|
|
|
}
|
2018-04-01 13:39:31 +02:00
|
|
|
|
2013-07-09 00:17:42 +02:00
|
|
|
if (!match) {
|
|
|
|
AFUZZY af = { NULL, NULL, NULL, NULL, NULL, NULL, { 0 }, { 0 }, 0, 0, 0, 0, 0, 0 };
|
|
|
|
if (s2.size() > 32) s2 = s2.substr(0, 32);
|
|
|
|
afuzzy_init(s2.c_str(), tolerance, 0, &af);
|
|
|
|
/* Checking substring */
|
|
|
|
int res = afuzzy_checkSUB(s1.c_str(), &af);
|
|
|
|
afuzzy_free(&af);
|
|
|
|
match = (res > 0);
|
|
|
|
}
|
2018-04-01 13:39:31 +02:00
|
|
|
|
2013-07-09 00:17:42 +02:00
|
|
|
if (match) {
|
2018-03-08 13:02:38 +01:00
|
|
|
matchingRecordings = (const cRecording **)realloc(matchingRecordings, (num + 1) * sizeof(cRecording *));
|
2013-07-09 00:17:42 +02:00
|
|
|
matchingRecordings[num++] = recording;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (num > 0) {
|
|
|
|
qsort(matchingRecordings, num, sizeof(cRecording *), CompareRecording);
|
|
|
|
numResults = num;
|
|
|
|
return matchingRecordings;
|
|
|
|
}
|
|
|
|
return NULL;
|
2013-12-29 18:13:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const cEvent **cRecManager::LoadReruns(const cEvent *event, int &numResults) {
|
|
|
|
if (epgSearchAvailable && !isempty(event->Title())) {
|
|
|
|
Epgsearch_searchresults_v1_0 data;
|
|
|
|
std::string strQuery = event->Title();
|
2019-07-11 11:28:11 +02:00
|
|
|
if (config.useSubtitleRerun > 0) {
|
|
|
|
if (config.useSubtitleRerun == 2 || !isempty(event->ShortText()))
|
2013-12-29 18:13:45 +01:00
|
|
|
strQuery += "~";
|
|
|
|
if (!isempty(event->ShortText()))
|
|
|
|
strQuery += event->ShortText();
|
2018-03-08 14:20:23 +01:00
|
|
|
data.useSubTitle = true;
|
2013-12-29 18:13:45 +01:00
|
|
|
} else {
|
|
|
|
data.useSubTitle = false;
|
|
|
|
}
|
|
|
|
data.query = (char *)strQuery.c_str();
|
|
|
|
data.mode = 0;
|
|
|
|
data.channelNr = 0;
|
|
|
|
data.useTitle = true;
|
|
|
|
data.useDescription = false;
|
2018-04-01 13:39:31 +02:00
|
|
|
|
2013-12-29 18:13:45 +01:00
|
|
|
if (epgSearchPlugin->Service("Epgsearch-searchresults-v1.0", &data)) {
|
|
|
|
cList<Epgsearch_searchresults_v1_0::cServiceSearchResult>* list = data.pResultList;
|
|
|
|
if (!list)
|
|
|
|
return NULL;
|
|
|
|
const cEvent **searchResults = NULL;
|
|
|
|
int numElements = list->Count();
|
|
|
|
if (numElements > 0) {
|
|
|
|
searchResults = new const cEvent *[numElements];
|
|
|
|
int index = 0;
|
|
|
|
for (Epgsearch_searchresults_v1_0::cServiceSearchResult *r = list->First(); r; r = list->Next(r)) {
|
|
|
|
if ((event->ChannelID() == r->event->ChannelID()) && (event->StartTime() == r->event->StartTime()))
|
|
|
|
continue;
|
|
|
|
searchResults[index] = r->event;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
delete list;
|
|
|
|
numResults = index;
|
|
|
|
return searchResults;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2014-01-02 11:25:58 +01:00
|
|
|
}
|
2014-01-14 18:00:32 +01:00
|
|
|
|
|
|
|
void cRecManager::GetFavorites(std::vector<cTVGuideSearchTimer> *favorites) {
|
|
|
|
if (!epgSearchAvailable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Epgsearch_services_v1_1 *epgSearch = new Epgsearch_services_v1_1;
|
|
|
|
if (epgSearchPlugin->Service("Epgsearch-services-v1.1", epgSearch)) {
|
|
|
|
std::list<std::string> searchTimerList;
|
|
|
|
searchTimerList = epgSearch->handler->SearchTimerList();
|
|
|
|
for(std::list<std::string>::iterator it = searchTimerList.begin(); it != searchTimerList.end(); it++) {
|
|
|
|
cTVGuideSearchTimer timer;
|
|
|
|
timer.SetEPGSearchString(it->c_str());
|
|
|
|
if (timer.Parse()) {
|
|
|
|
if (timer.UseInFavorites())
|
|
|
|
favorites->push_back(timer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-01-19 13:52:05 +01:00
|
|
|
|
|
|
|
const cEvent **cRecManager::WhatsOnNow(bool nowOrNext, int &numResults) {
|
|
|
|
std::vector<const cEvent*> tmpResults;
|
2018-03-08 13:30:41 +01:00
|
|
|
#if VDRVERSNUM >= 20301
|
2018-03-08 13:02:38 +01:00
|
|
|
LOCK_CHANNELS_READ;
|
2019-07-10 14:55:14 +02:00
|
|
|
const cChannels* channels = Channels;
|
2019-03-23 12:35:25 +01:00
|
|
|
LOCK_SCHEDULES_READ;
|
2018-03-08 13:02:38 +01:00
|
|
|
const cSchedules* schedules = Schedules;
|
|
|
|
#else
|
2019-07-10 14:55:14 +02:00
|
|
|
cChannels* channels = &Channels;
|
2014-01-19 13:52:05 +01:00
|
|
|
cSchedulesLock schedulesLock;
|
|
|
|
const cSchedules *schedules = cSchedules::Schedules(schedulesLock);
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2014-01-19 13:52:05 +01:00
|
|
|
const cChannel *startChannel = NULL, *stopChannel = NULL;
|
2019-07-11 11:28:11 +02:00
|
|
|
if (config.favLimitChannels) {
|
|
|
|
startChannel = channels->GetByNumber(config.favStartChannel);
|
|
|
|
stopChannel = channels->GetByNumber(config.favStopChannel);
|
2014-01-19 13:52:05 +01:00
|
|
|
}
|
|
|
|
if (!startChannel)
|
2019-07-10 14:55:14 +02:00
|
|
|
startChannel = channels->First();
|
2014-01-19 13:52:05 +01:00
|
|
|
|
2019-07-10 14:55:14 +02:00
|
|
|
for (const cChannel *channel = startChannel; channel; channel = channels->Next(channel)) {
|
2014-01-19 13:52:05 +01:00
|
|
|
if (channel->GroupSep()) continue;
|
|
|
|
const cSchedule *Schedule = schedules->GetSchedule(channel);
|
|
|
|
if (!Schedule) continue;
|
|
|
|
|
|
|
|
const cEvent *event = NULL;
|
|
|
|
if (nowOrNext)
|
|
|
|
event = Schedule->GetPresentEvent();
|
|
|
|
else
|
|
|
|
event = Schedule->GetFollowingEvent();
|
|
|
|
if (event) {
|
|
|
|
tmpResults.push_back(event);
|
|
|
|
}
|
|
|
|
if (stopChannel && (stopChannel->Number() <= channel->Number()))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
numResults = tmpResults.size();
|
|
|
|
const cEvent **results = new const cEvent *[numResults];
|
|
|
|
for (int i=0; i<numResults; i++) {
|
2018-04-01 13:39:31 +02:00
|
|
|
results[i] = tmpResults[i];
|
2014-01-19 13:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
const cEvent **cRecManager::UserDefinedTime(int userTime, int &numResults) {
|
|
|
|
std::vector<const cEvent*> tmpResults;
|
|
|
|
int favTime = 0;
|
|
|
|
if (userTime == 1) {
|
2019-07-11 11:28:11 +02:00
|
|
|
favTime = config.favTime1;
|
2014-01-19 13:52:05 +01:00
|
|
|
} else if (userTime == 2) {
|
2019-07-11 11:28:11 +02:00
|
|
|
favTime = config.favTime2;
|
2014-01-19 13:52:05 +01:00
|
|
|
} else if (userTime == 3) {
|
2019-07-11 11:28:11 +02:00
|
|
|
favTime = config.favTime3;
|
2014-01-19 13:52:05 +01:00
|
|
|
} else if (userTime == 4) {
|
2019-07-11 11:28:11 +02:00
|
|
|
favTime = config.favTime4;
|
2014-01-19 13:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
time_t now = time(0);
|
|
|
|
tm *midn = localtime(&now);
|
|
|
|
midn->tm_sec = 0;
|
|
|
|
midn->tm_min = 0;
|
|
|
|
midn->tm_hour = 0;
|
|
|
|
time_t midnight = mktime(midn);
|
|
|
|
int hours = favTime/100;
|
|
|
|
int mins = favTime - hours * 100;
|
|
|
|
time_t searchTime = midnight + hours*60*60 + mins*60;
|
|
|
|
if (searchTime < now)
|
|
|
|
searchTime += 24*60*60;
|
|
|
|
|
2018-03-08 13:30:41 +01:00
|
|
|
#if VDRVERSNUM >= 20301
|
2018-03-08 13:02:38 +01:00
|
|
|
LOCK_CHANNELS_READ;
|
2019-07-10 14:58:25 +02:00
|
|
|
const cChannels* channels = Channels;
|
2018-03-08 13:02:38 +01:00
|
|
|
LOCK_SCHEDULES_READ;
|
|
|
|
const cSchedules* schedules = Schedules;
|
|
|
|
#else
|
2019-07-10 14:58:25 +02:00
|
|
|
cChannels* channels = &Channels;
|
2014-01-19 13:52:05 +01:00
|
|
|
cSchedulesLock schedulesLock;
|
|
|
|
const cSchedules *schedules = cSchedules::Schedules(schedulesLock);
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2014-01-19 13:52:05 +01:00
|
|
|
const cChannel *startChannel = NULL, *stopChannel = NULL;
|
2019-07-11 11:28:11 +02:00
|
|
|
if (config.favLimitChannels) {
|
|
|
|
startChannel = channels->GetByNumber(config.favStartChannel);
|
|
|
|
stopChannel = channels->GetByNumber(config.favStopChannel);
|
2014-01-19 13:52:05 +01:00
|
|
|
}
|
|
|
|
if (!startChannel)
|
2019-07-10 14:58:25 +02:00
|
|
|
startChannel = channels->First();
|
2014-01-19 13:52:05 +01:00
|
|
|
|
2019-07-10 14:58:25 +02:00
|
|
|
for (const cChannel *channel = startChannel; channel; channel = channels->Next(channel)) {
|
2014-01-19 13:52:05 +01:00
|
|
|
if (channel->GroupSep()) continue;
|
|
|
|
const cSchedule *Schedule = schedules->GetSchedule(channel);
|
|
|
|
if (!Schedule) continue;
|
|
|
|
const cEvent *event = Schedule->GetEventAround(searchTime);
|
|
|
|
if (!event) continue;
|
|
|
|
//if event is more or less over (only 15mns left), take next
|
|
|
|
if ((event->EndTime() - searchTime) < 15*60) {
|
|
|
|
event = Schedule->Events()->Next(event);
|
|
|
|
}
|
|
|
|
if (event)
|
|
|
|
tmpResults.push_back(event);
|
|
|
|
if (stopChannel && (stopChannel->Number() <= channel->Number()))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
numResults = tmpResults.size();
|
|
|
|
const cEvent **results = new const cEvent *[numResults];
|
|
|
|
for (int i=0; i<numResults; i++) {
|
2018-04-01 13:39:31 +02:00
|
|
|
results[i] = tmpResults[i];
|
2014-01-19 13:52:05 +01:00
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}
|