Skip to content

Commit

Permalink
match language when searching for existing recordings
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Ehrnsperger committed Mar 5, 2023
1 parent f4fc98c commit 2391bfe
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 45 deletions.
2 changes: 1 addition & 1 deletion live/js/live/createHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function addEventRec(s, eventprefix, eventid, title, folder, shortText, descript
s.a += title
if (folder.length != 0) {
s.a += '<span class="normal-font"> ('
s.a += folder
s.a += folder.replaceAll("~", "~<wbr>")
s.a += ')</span>'
}
s.a += '</div>'
Expand Down
12 changes: 7 additions & 5 deletions pages/timerconflicts.ecpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html");
longDescription = StringEscapeAndBreak(SortedTimers::GetTimerInfo(*timer)) + "<hr>"
+ StringEscapeAndBreak(StringWordTruncate(epgEvent->LongDescr(), LiveSetup().GetMaxTooltipChars()))
+ "<br/><br/>" + tr("Click to view details.");
searchTimName = SortedTimers::SearchTimerInfo(*timer, "searchtimer");
AppendHtmlEscapedAndCorrectNonUTF8(searchTimName, SortedTimers::SearchTimerInfo(*timer, "searchtimer").c_str());
searchTimId = SortedTimers::SearchTimerInfo(*timer, "s-id");
if (searchTimName.empty() && searchTimId.empty() ) searchTimName = SortedTimers::TvScraperTimerInfo(*timer);
if (searchTimName.empty() && searchTimId.empty() ) AppendHtmlEscapedAndCorrectNonUTF8(searchTimName, SortedTimers::TvScraperTimerInfo(*timer).c_str());
title = epgEvent->Title();
}
std::string timerFile;
AppendHtmlEscapedAndCorrectNonUTF8(timerFile, timer->File());
</%cpp>
<tr>
<td class="leftcol <? bottom ? "bottomrow" ?>"><img src="<$ LiveSetup().GetThemedLink("img", timerStateImg) $>" alt="" <%cpp> if (!timerStateHint.empty()) { </%cpp><& tooltip.hint text=(timerStateHint) &><%cpp> } </%cpp>></img></td>
Expand All @@ -129,13 +131,13 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html");
<& tooltip.display domId=(epgEvent->Id()) &>
% }
class="apopup" title="<$$longDescription$>"
><$ timer->File() $></a></div></td>
><$$ StringReplace(timerFile, "~", "~<wbr>") $></a></div></td>

<td class="<? bottom ? "bottomrow" ?>"><div class="withmargin">
% if ( !timer->Local() || searchTimId.empty() ) {
<$ searchTimName $></div></td>
<$$ StringReplace(searchTimName, "~", "~<wbr>") $></div></td>
% } else {
<a href="edit_searchtimer.html?searchtimerid=<$ searchTimId $>"><$ searchTimName $></a></div></td>
<a href="edit_searchtimer.html?searchtimerid=<$ searchTimId $>"><$$ StringReplace(searchTimName, "~", "~<wbr>") $></a></div></td>
% }
<td class="<? bottom ? "bottomrow" ?> td-hidden-xs"><a class="hidden-xs action-rightcol" href="searchresults.html?searchplain=<$ StringEscapeAndBreak(title) $>"><img src="<$ LiveSetup().GetThemedLink("img", "search.png") $>" alt="" <& tooltip.hint text=(tr("Search for repeats.")) &>></img></a></td>
<td class="<? bottom ? "bottomrow" ?> td-hidden-xs"><a class="hidden-xs action-rightcol" href="timers.html?timerid=<$ SortedTimers::EncodeDomId(timers.GetTimerId(*timer)) $>&action=toggle"><img src="<$ LiveSetup().GetThemedLink("img", (timer->Flags() & tfActive) ? "active.png" : "inactive.png") $>" alt="" <& tooltip.hint text=(tr("Toggle timer active/inactive")) &>></img></a></td>
Expand Down
22 changes: 12 additions & 10 deletions pages/timers.ecpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ using namespace vdrlive;

if (timer->Event())
{
epgEvent = EpgEvents::CreateEpgInfo(timer->Channel(), timer->Event());
bool truncated = false;
longDescription = StringEscapeAndBreak(SortedTimers::GetTimerInfo(*timer), lf);
longDescription += LiveSetup().GetUseAjax()?"<hr>":lf;
epgEvent = EpgEvents::CreateEpgInfo(timer->Channel(), timer->Event());
bool truncated = false;
longDescription = StringEscapeAndBreak(SortedTimers::GetTimerInfo(*timer), lf);
longDescription += LiveSetup().GetUseAjax()?"<hr>":lf;
longDescription += StringEscapeAndBreak(StringWordTruncate(epgEvent->LongDescr(), LiveSetup().GetMaxTooltipChars(), truncated), lf);
if (truncated) longDescription += "...";
searchTimName = SortedTimers::SearchTimerInfo(*timer, "searchtimer");
searchTimId = SortedTimers::SearchTimerInfo(*timer, "s-id");
if (searchTimName.empty() && searchTimId.empty() ) searchTimName = SortedTimers::TvScraperTimerInfo(*timer);
AppendHtmlEscapedAndCorrectNonUTF8(searchTimName, SortedTimers::SearchTimerInfo(*timer, "searchtimer").c_str());
searchTimId = SortedTimers::SearchTimerInfo(*timer, "s-id");
if (searchTimName.empty() && searchTimId.empty() ) AppendHtmlEscapedAndCorrectNonUTF8(searchTimName, SortedTimers::TvScraperTimerInfo(*timer).c_str());
}
std::string currentDay = SortedTimers::GetTimerDays(timer);
const cTimer *nextTimer = NULL;
Expand Down Expand Up @@ -155,6 +155,8 @@ using namespace vdrlive;
timerStateImg = "arrow.png";
timerStateHint = tr("Timer is active.");
}
std::string timerFile;
AppendHtmlEscapedAndCorrectNonUTF8(timerFile, timer->File());
</%cpp>
<tr>

Expand All @@ -171,14 +173,14 @@ using namespace vdrlive;
<& tooltip.display domId=(epgEvent->Id()) &>
% }
class="apopup" title="<$$longDescription$>"
><$ timer->File() $></a></div>
><$$ StringReplace(timerFile, "~", "~<wbr>") $></a></div>
</td>
<td class="<? bottom ? "bottomrow" ?> td-hidden-xs"><div class="xs-nomargin"><$ timer->Local()?trVDR(" "):timer->Remote() $></div></td>
<td class="<? bottom ? "bottomrow" ?>"><div class="withmargin">
% if ( !timer->Local() || searchTimId.empty() ) {
<$ searchTimName $></div></td>
<$$ StringReplace(searchTimName, "~", "~<wbr>") $></div></td>
% } else {
<a href="edit_searchtimer.html?searchtimerid=<$ searchTimId $>"><$ searchTimName $></a></div></td>
<a href="edit_searchtimer.html?searchtimerid=<$ searchTimId $>"><$$ StringReplace(searchTimName, "~", "~<wbr>") $></a></div></td>
% }
<td class="<? bottom ? "bottomrow" ?> td-hidden-xs"><a class="hidden-xs action-rightcol" href="timers.html?timerid=<$ SortedTimers::EncodeDomId(timers.GetTimerId(*timer)) $>&action=toggle"><img src="<$ LiveSetup().GetThemedLink("img", (timer->Flags() & tfActive) ? "active.png" : "inactive.png") $>" alt="" <& tooltip.hint text=(tr("Toggle timer active/inactive")) &>></img></a></td>
<td class="<? bottom ? "bottomrow" ?> td-hidden-xs"><div class="hidden-xs action-rightcol"><& pageelems.edit_timer timerId=(timers.GetTimerId(*timer)) &></div></td>
Expand Down
65 changes: 36 additions & 29 deletions recman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ int firstNonPunct(const std::string &s) {
if (*first ) return 1;
return 0;
}
tCompRec RecordingsItemPtrCompare::getComp(eSortOrder sortOrder) {

tCompRec RecordingsItemPtrCompare::getComp(eSortOrder sortOrder) {
switch (sortOrder) {
case eSortOrder::name: return &RecordingsItemPtrCompare::ByAscendingNameDescSort;
case eSortOrder::date: return &RecordingsItemPtrCompare::ByAscendingDate;
Expand All @@ -434,21 +435,25 @@ int firstNonPunct(const std::string &s) {
}
esyslog("live: ERROR, RecordingsItemPtrCompare::getComp, sortOrder %d unknown", (int)sortOrder);
return &RecordingsItemPtrCompare::ByAscendingNameDescSort;
}
}


bool searchNameDesc(RecordingsItemPtr &RecItem, const std::vector<RecordingsItemPtr> *RecItems, const cEvent *event, cScraperVideo *scraperVideo) {
if(RecItems->empty() ) return false; // there are no recordings
if (RecItems->empty() ) return false; // there are no recordings

// find all recordings with equal name
RecordingsItemPtr dummy (new RecordingsItemDummy(event, scraperVideo));
const auto equalName = std::equal_range(RecItems->begin(), RecItems->end(), dummy, RecordingsItemPtrCompare::ByDuplicatesName);
if ( equalName.first == equalName.second ) return false; // there is no recording with this name
if (equalName.first == equalName.second) return false; // there is no recording with this name

// find all recordings with matching short text / description
auto equalDuplicates = std::equal_range(equalName.first, equalName.second, dummy, RecordingsItemPtrCompare::ByDuplicates);
// find all recordings with matching short text / description / language
auto equalDuplicates = std::equal_range(equalName.first, equalName.second, dummy, RecordingsItemPtrCompare::ByDuplicatesLanguage);

if(equalDuplicates.first != equalDuplicates.second) { // exact match found
if (equalDuplicates.first == equalDuplicates.second) { // nothing found. Try again, and include other languages
equalDuplicates = std::equal_range(equalName.first, equalName.second, dummy, RecordingsItemPtrCompare::ByDuplicates);
}

if (equalDuplicates.first != equalDuplicates.second) { // exact match found
if (RecordingsItemPtrCompare::FindBestMatch(RecItem, equalDuplicates.first, equalDuplicates.second, dummy) > 0) return true;
RecItem = *equalDuplicates.first;
return true;
Expand All @@ -457,23 +462,23 @@ bool searchNameDesc(RecordingsItemPtr &RecItem, const std::vector<RecordingsItem
int numEqualCharsLow = 0;
int numEqualCharsUp = 0;

if(equalDuplicates.first != equalName.first) {
if (equalDuplicates.first != equalName.first) {
--equalDuplicates.first;
(*equalDuplicates.first)->CompareStD(dummy, &numEqualCharsLow);
}
if(equalDuplicates.second != equalName.second)
if (equalDuplicates.second != equalName.second)
(*equalDuplicates.second)->CompareStD(dummy, &numEqualCharsUp);

if ( numEqualCharsLow > numEqualCharsUp ) {
if( numEqualCharsLow > 5 ) { RecItem = *equalDuplicates.first; return true; }
if (numEqualCharsLow > numEqualCharsUp ) {
if (numEqualCharsLow > 5) { RecItem = *equalDuplicates.first; return true; }
} else {
if( numEqualCharsUp > 5 ) { RecItem = *equalDuplicates.second; return true; }
if (numEqualCharsUp > 5) { RecItem = *equalDuplicates.second; return true; }
}

// no sufficient match in short text / description
// get best match from length of event match
int num_match_rec = RecordingsItemPtrCompare::FindBestMatch(RecItem, equalName.first, equalName.second, dummy);
if(num_match_rec == 0 || num_match_rec > 5) return false; // no matching lenght or series (too many matching length)
if (num_match_rec == 0 || num_match_rec > 5) return false; // no matching lenght or series (too many matching length)
return true;
}

Expand Down Expand Up @@ -901,19 +906,21 @@ void RecordingsItemRec::AppendAsJSArray(cLargeString &target, std::vector<Record
/**
* Implemetation of class RecordingsItemDummy
*/
RecordingsItemDummy::RecordingsItemDummy(const cEvent *event, cScraperVideo *scraperVideo):
RecordingsItem(charToString(event->Title() )),
m_event(event)
{
if (scraperVideo) {
m_s_videoType = scraperVideo->getVideoType();
m_s_dbid = scraperVideo->getDbId();
m_s_episode_number = scraperVideo->getEpisodeNumber();
m_s_season_number = scraperVideo->getSeasonNumber();
} else {
m_s_videoType = tNone;
}
}
RecordingsItemDummy::RecordingsItemDummy(const cEvent *event, cScraperVideo *scraperVideo):
RecordingsItem(charToString(event->Title() )),
m_event(event)
{
if (scraperVideo) {
m_s_videoType = scraperVideo->getVideoType();
m_s_dbid = scraperVideo->getDbId();
m_s_episode_number = scraperVideo->getEpisodeNumber();
m_s_season_number = scraperVideo->getSeasonNumber();
m_language = scraperVideo->getLanguage();
m_video_SD_HD = scraperVideo->getHD();
} else {
m_s_videoType = tNone;
}
}

bool operator< (const RecordingsItemPtr &a, const RecordingsItemPtr &b) { return *a < b; }
bool operator< (const std::string &a, const RecordingsItemPtr &b) { return a < b->Name(); }
Expand Down Expand Up @@ -1029,10 +1036,10 @@ void RecordingsItemRec::AppendAsJSArray(cLargeString &target, std::vector<Record
m_allRecordingsSorted = true;
}
return &m_allRecordings;
}
if (m_allRecordings_other_sort.empty() ) m_allRecordings_other_sort = m_allRecordings;
}
if (m_allRecordings_other_sort.empty() ) m_allRecordings_other_sort = m_allRecordings;
std::sort(m_allRecordings_other_sort.begin(), m_allRecordings_other_sort.end(), RecordingsItemPtrCompare::getComp(sortOrder));
m_sortOrder = sortOrder;
m_sortOrder = sortOrder;
return &m_allRecordings_other_sort;
}

Expand Down

0 comments on commit 2391bfe

Please sign in to comment.