Skip to content

Commit

Permalink
searchtimerquery
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Ehrnsperger committed Jul 16, 2024
1 parent 36c5c96 commit 7a612d3
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 43 deletions.
3 changes: 1 addition & 2 deletions epg_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ void AppendScraperData(cToSvConcat<0> &target, cScraperVideo *scraperVideo) {
cOrientations(eOrientation::landscape, eOrientation::portrait, eOrientation::banner), false);
AppendScraperData(target, s_IMDB_ID, s_image, scraperVideo->getVideoType(), s_title, scraperVideo->getSeasonNumber(), scraperVideo->getEpisodeNumber(), s_episode_name, s_runtime, s_release_date);
}
bool appendEpgItem(cToSvConcat<0> &epg_item, RecordingsItemRecPtr &recItem, const cEvent *Event, const cChannel *Channel, bool withChannel, bool form) {
bool appendEpgItem(cToSvConcat<0> &epg_item, RecordingsItemRecPtr &recItem, const cEvent *Event, const cChannel *Channel, bool withChannel) {
cGetScraperVideo getScraperVideo(Event, NULL);
getScraperVideo.call(LiveSetup().GetPluginScraper());

Expand All @@ -512,7 +512,6 @@ bool appendEpgItem(cToSvConcat<0> &epg_item, RecordingsItemRecPtr &recItem, cons
epg_item.append(EpgEvents::EncodeDomId(Channel->GetChannelID(), Event->EventID()).c_str() + 6);
epg_item.append("\",\"");
// [1] : Timer ID
if (form) epg_item.append("-"); // timer id starts with - to indicate that history.back is not working
const cTimer* timer = LiveTimerManager().GetTimer(Event->EventID(), Channel->GetChannelID() );
if (timer) epg_item.append(vdrlive::EncodeDomId(LiveTimerManager().GetTimers().GetTimerId(*timer), ".-:", "pmc"));
epg_item.append("\",");
Expand Down
3 changes: 1 addition & 2 deletions epg_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ namespace vdrlive
mutable bool m_checkedArchived;
mutable std::string m_archived;
};
bool appendEpgItem(cToSvConcat<0> &epg_item, RecordingsItemRecPtr &recItem, const cEvent *Event, const cChannel *Channel, bool withChannel, bool form = false);
// set form = true if history.back is not working because the list of epg items is a result of an html form
bool appendEpgItem(cToSvConcat<0> &epg_item, RecordingsItemRecPtr &recItem, const cEvent *Event, const cChannel *Channel, bool withChannel);
}; // namespace vdrlive

#endif // VDR_LIVE_EPG_EVENTS_H
41 changes: 31 additions & 10 deletions epgsearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ const cEvent* SearchResult::GetEvent(const cChannel* Channel)
return Schedule->GetEvent(m_eventId);
}

std::set<std::string> SearchResults::querySet;
std::vector<cQueryEntry> SearchResults::queryList;

void SearchResults::GetByID(int id)
{
Expand All @@ -587,7 +587,7 @@ void SearchResults::GetByID(int id)

std::list<std::string> list = service.handler->QuerySearchTimer(id);
m_list.assign( list.begin(), list.end() );
m_list.sort();
m_list.sort();
}

void SearchResults::GetByQuery(std::string const& query)
Expand All @@ -601,29 +601,50 @@ void SearchResults::GetByQuery(std::string const& query)
m_list.sort();
}

std::string SearchResults::AddQuery(std::string const& query)
std::string SearchResults::AddQuery(cSv query)
{
querySet.insert(query);
for (auto it = queryList.begin(); it != queryList.end(); ++it) if (it->Value() == query) {
it->Used();
return std::string(cToSvXxHash128(query));
}
queryList.emplace_back(query);
return std::string(cToSvXxHash128(query));
}

std::string SearchResults::PopQuery(cSv md5)
std::string SearchResults::GetQuery(cSv md5)
{
if (md5.empty()) return std::string();
std::string query;
std::set<std::string>::iterator it;
for (it = querySet.begin(); it != querySet.end(); it++)
for (auto it = queryList.begin(); it != queryList.end(); ++it)
{
if(md5 == cSv(cToSvXxHash128(*it)))
if(md5 == cSv(cToSvXxHash128(it->Value() )))
{
query = *it;
querySet.erase(it);
query = it->Value() ;
it->Used();
break;
}
}
return query;
}

void SearchResults::CleanQuery() {
time_t now = time(NULL);
size_t old_s = queryList.size();
for (auto it = queryList.begin(); it != queryList.end();)
{
if(it->IsOutdated(now))
it = queryList.erase(it);
else
++it;
}
if (old_s != queryList.size() ) {
size_t mem = 0;
for (auto it = queryList.begin(); it != queryList.end(); ++it) mem += it->Value().length();

dsyslog("live, cleanup queryList, size was %zu, is %zu, requ. mem %zu", old_s, queryList.size(), mem);
}
}

RecordingDirs::RecordingDirs(bool shortList)
{
if (shortList)
Expand Down
19 changes: 16 additions & 3 deletions epgsearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,21 @@ class SearchResult
int m_timerMode;
};

#define QUERYLIFETIME 60*20 // seconds. If a query is not used in this timeframe, it is deleted
class cQueryEntry {
public:
cQueryEntry(cSv queryString):
value(queryString) { Used(); }
bool IsOutdated(time_t now) { return now > outdated_at; }
cSv Value() { return value; }
void Used() { outdated_at = time(NULL) + QUERYLIFETIME; }
private:
time_t outdated_at;
std::string value;
};
class SearchResults
{
static std::set<std::string> querySet;
static std::vector<cQueryEntry> queryList;
public:
typedef std::list<SearchResult> searchresults;
typedef searchresults::size_type size_type;
Expand All @@ -394,8 +406,9 @@ class SearchResults
const_iterator end() const { return m_list.end(); }

void merge(SearchResults& r) {m_list.merge(r.m_list); m_list.sort();}
static std::string AddQuery(std::string const& query);
static std::string PopQuery(cSv md5);
static std::string AddQuery(cSv query);
static std::string GetQuery(cSv md5);
static void CleanQuery();
private:
searchresults m_list;
};
Expand Down
5 changes: 5 additions & 0 deletions live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "preload.h"
#include "users.h"
#include "services_live.h"
#include "epgsearch.h"

namespace vdrlive {

Expand Down Expand Up @@ -78,6 +79,10 @@ void Plugin::MainThreadHook(void)
LiveTaskManager().DoScheduledTasks();
}

void Plugin::Housekeeping(void) {
SearchResults::CleanQuery();
}

cString Plugin::Active(void)
{
return NULL;
Expand Down
1 change: 1 addition & 0 deletions live.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Plugin : public cPlugin {
virtual bool Initialize(void);
virtual void Stop(void);
virtual void MainThreadHook(void);
virtual void Housekeeping(void);
virtual cString Active(void);
virtual cMenuSetupPage *SetupMenu(void);
virtual bool SetupParse(const char *Name, const char *Value);
Expand Down
20 changes: 18 additions & 2 deletions pages/edit_searchtimer.ecpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,29 @@ const char *TNT_ARRAY = "";
if (!testmode)
{
searchtimers.Save(&searchtimer);
return reply.redirect("searchtimers.html");
</%cpp>
<!DOCTYPE html>
<html>
<script>
window.location = "searchtimers.html";
</script>
</html>
<%cpp>
// return reply.redirect("searchtimers.html");
}
else
{
searchtimer.SetId(0);
std::string md5 = SearchResults::AddQuery(searchtimer.ToText());
return reply.redirect("searchresults.html?searchtimerquery=" + md5);
</%cpp>
<!DOCTYPE html>
<html>
<script>
window.location = "searchresults.html?searchtimerquery=<$md5$>";
</script>
</html>
<%cpp>
// return reply.redirect("searchresults.html?searchtimerquery=" + md5);
}
}
pageTitle = !searchtimerid.empty() ? tr("Edit search timer") : tr("New search timer");
Expand Down
11 changes: 0 additions & 11 deletions pages/edit_timer.ecpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ using namespace vdrlive;
std::string aux = "";
std::string directory = "";
int nav_back = 1;
std::string navigate_back = "";
</%args>
<%session scope="global">
bool logged_in(false);
Expand Down Expand Up @@ -102,7 +101,6 @@ const cTimer* timer;
// dsyslog("live: remote '%s'", remote);
LiveTimerManager().UpdateTimer( timerId, remote, oldRemote, flags, channel, weekdays, date, start, stop, priority, lifetime, file, aux );
timerNotifier.SetTimerModification();
if (navigate_back.empty() ) {
</%cpp>
<!DOCTYPE html>
<html>
Expand All @@ -111,10 +109,6 @@ const cTimer* timer;
</script>
</html>
<%cpp>
} else {
timerid.clear();
return reply.redirect(navigate_back);
}
// return reply.redirect("html/back.html");
// return reply.redirect(!edit_timerreferer.empty()?edit_timerreferer:"timers.html");
} else {
Expand Down Expand Up @@ -209,7 +203,6 @@ const cTimer* timer;
<input type="hidden" name="timerid" value="<$ timerid $>"/>
<input type="hidden" name="aux" value="<$ aux $>"/>
<input type="hidden" name="nav_back" value="<$ nav_back $>"/>
<input type="hidden" name="navigate_back" value="<$ navigate_back $>"/>
<table class="formular" cellpadding="0" cellspacing="0">
<tr class="head">
<td class="toprow leftcol rightcol" colspan="2"><div class="boxheader"><div><div class="caption"><$ timer ? tr("Edit timer") : tr("New timer") $></div></div></div></td>
Expand Down Expand Up @@ -360,11 +353,7 @@ const cTimer* timer;
<td class="buttonpanel leftcol rightcol bottomrow" colspan="2">
<div class="withmargin">
<button class="green" type="submit"><$ tr("Save") $></button>
% if (navigate_back.empty() ) {
<button type="button" class="red" onclick="history.go(<$-nav_back$>)"><$ tr("Cancel") $></button>
% } else {
<a href="<$navigate_back$>"><button type="button" class="red"><$ tr("Cancel") $></button></a>
% }
</div>
</td>
</tr>
Expand Down
12 changes: 2 additions & 10 deletions pages/pageelems.ecpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,13 @@ function addEvent(s, bottomrow_i, obj) {
let bottomrow = ''
if (bottomrow_i != 0) bottomrow = 'bottomrow'
s.a += `<tr><td class=\"action leftcol ${bottomrow}\">`
if (obj[1].length > 1) {
if (obj[1].length != 0) {
s.a += '<a href=\"edit_timer.html?timerid=timer_'
if (obj[1].startsWith('-')) {
s.a += obj[1].substring(1)
s.a += '&navigate_back=timers.html'
} else {
s.a += obj[1]
}
s.a += obj[1]
s.a += '\"><img class=\"icon\" src=\"<$ LiveSetup().GetThemedLink("img", "record_timer.png") $>\" title=\"<$tr("Edit timer")$>\" />'
} else {
s.a += '<a href=\"edit_timer.html?epgid=event_'
s.a += obj[0]
if (obj[1].startsWith('-')) {
s.a += '&navigate_back=timers.html'
}
s.a += '\"><img class=\"icon\" src=\"<$ LiveSetup().GetThemedLink("img", "record.png") $>\" title=\"<$tr("Record this")$>\" />'
}
s.a += '</a>'
Expand Down
11 changes: 10 additions & 1 deletion pages/searchepg.ecpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,16 @@ const char *TNT_ARRAY = "";

searchtimer.SetId(0);
std::string md5 = SearchResults::AddQuery(searchtimer.ToText());
return reply.redirect("searchresults.html?searchtimerquery=" + md5);
</%cpp>
<!DOCTYPE html>
<html>
<script>
window.location = "searchresults.html?searchtimerquery=<$md5$>";
</script>
</html>
<%cpp>

// return reply.redirect("searchresults.html?searchtimerquery=" + md5);
}
pageTitle = tr("Search");

Expand Down
4 changes: 2 additions & 2 deletions pages/searchresults.ecpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ bool logged_in(false);
if (!searchtimerid.empty())
results.GetByID(parse_int< int >(searchtimerid));
if (!searchtimerquery.empty())
results.GetByQuery(SearchResults::PopQuery(searchtimerquery));
results.GetByQuery(SearchResults::GetQuery(searchtimerquery));
if (!searchplain.empty())
{
SearchTimer s;
Expand Down Expand Up @@ -102,7 +102,7 @@ bool logged_in(false);
}

StateKey.Remove(); // release channels read lock before calling event_timer which make a timers read lock
recItemFound = appendEpgItem(epg_itemS, recItem, event, channel, true, !searchtimerquery.empty() );
recItemFound = appendEpgItem(epg_itemS, recItem, event, channel, true);
int col_span = 4;
if (display_pictures) col_span++;
if (current_day != day) {
Expand Down

0 comments on commit 7a612d3

Please sign in to comment.