Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of sorting recordings by duration #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pages/recordings.ecpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ if (!sort.empty()) {
if (sort == "date")
currentSort = (currentSort == "datedesc") ? "dateasc" : "datedesc";
else if (sort == "datedesc" || sort == "dateasc") currentSort = sort;
else if (sort == "duration")
currentSort = (currentSort == "durationasc") ? "durationdesc" : "durationasc";
else if (sort == "durationasc" || sort == "durationdesc") currentSort = sort;
else if (sort == "name")
currentSort = (currentSort == "nameasc") ? "namedesc" : "nameasc";
else if (sort == "nameasc" || sort == "namedesc") currentSort = sort;
Expand Down Expand Up @@ -262,10 +265,11 @@ dsyslog("live, time recordings.ecpp: %f", timeNeeded.count());
bool reverse = false;
eSortOrder sortOrder = eSortOrder::name; // default
if (currentSort.compare(0, 4, "date" , 4) == 0) sortOrder = eSortOrder::date;
if (currentSort.compare(0, 8, "duration", 8) == 0) sortOrder = eSortOrder::duration;
if (currentSort.compare(0, 6, "errors", 6) == 0) sortOrder = eSortOrder::errors;
if (currentSort.compare(0, 8, "errorsdur", 8) == 0) sortOrder = eSortOrder::durationDeviation;
if (currentSort.compare(0, 10, "duplicates", 10) == 0) sortOrder = eSortOrder::duplicatesLanguage;
if (currentSort == "datedesc" || currentSort == "namedesc") reverse = true;
if (currentSort == "datedesc" || currentSort == "durationdesc" || currentSort == "namedesc") reverse = true;
// get rec item of this (current) dir
RecordingsItemDirPtr recItemThisDir = *(static_cast<RecordingsItemDirPtr *>((void *)iRecItem) );
RecordingsTreePtr recordingsTree = *(static_cast<RecordingsTreePtr *>((void *)iRecordingsTree) );
Expand Down Expand Up @@ -499,6 +503,8 @@ recs[<$cSv(cToSvInt(rPtr->IdI()))$>]=[<$$ recording_item->c_str() $>]
<span class="sep">|</span>
<a href="recordings.html?sort=<$ (currentSort == "datedesc") ? "dateasc" : "datedesc"$>&filter=<? !currentFilter.empty() ? currentFilter ?>&flat=<$currentFlat$>" <& setactive current="date" &> ><$ tr("Date") $></a>
<span class="sep">|</span>
<a href="recordings.html?sort=<$ (currentSort == "durationasc") ? "durationdesc" : "durationasc"$>&filter=<? !currentFilter.empty() ? currentFilter ?>&flat=<$currentFlat$>" <& setactive current="duration" &> ><$ tr("Duration") $></a>
<span class="sep">|</span>
<a href="recordings.html?sort=duplicates&filter=<? !currentFilter.empty() ? currentFilter ?>&flat=<$currentFlat$>" <& setactive current="duplicates" &> ><$ tr("Duplicates") $></a>
<%cpp>
#if VDRVERSNUM >= 20505
Expand Down
6 changes: 6 additions & 0 deletions recman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ namespace vdrlive {
return (first->StartTime() < second->StartTime());
}

bool RecordingsItemPtrCompare::ByAscendingDuration(const RecordingsItemRecPtr & first, const RecordingsItemRecPtr & second)
{
return (first->Duration() < second->Duration());
}

bool RecordingsItemPtrCompare::ByDuplicatesName(const RecordingsItemRecPtr & first, const RecordingsItemRecPtr & second) // return first < second
{
return first->orderDuplicates(second, false);
Expand Down Expand Up @@ -422,6 +427,7 @@ namespace vdrlive {
switch (sortOrder) {
case eSortOrder::name: return &RecordingsItemPtrCompare::ByAscendingNameDescSort;
case eSortOrder::date: return &RecordingsItemPtrCompare::ByAscendingDate;
case eSortOrder::duration: return &RecordingsItemPtrCompare::ByAscendingDuration;
case eSortOrder::errors: return &RecordingsItemPtrCompare::ByDescendingRecordingErrors;
case eSortOrder::durationDeviation: return &RecordingsItemPtrCompare::ByDescendingDurationDeviation;
case eSortOrder::duplicatesLanguage: return &RecordingsItemPtrCompare::ByDuplicatesLanguage;
Expand Down
13 changes: 12 additions & 1 deletion recman.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,24 @@ cToSvConcat<N> & StringAppendFrameParams(cToSvConcat<N> &s, const cRecording *re
/**
* Class containing possible recordings compare functions
*/
enum class eSortOrder { name, date, errors, durationDeviation, duplicatesLanguage };
enum class eSortOrder
{
name,
date,
duration,
errors,
durationDeviation,
duplicatesLanguage
};

typedef bool (*tCompRec)(const RecordingsItemRecPtr &a, const RecordingsItemRecPtr &b);
typedef bool (*tCompDir)(const RecordingsItemDirPtr &a, const RecordingsItemDirPtr &b);
class RecordingsItemPtrCompare
{
public:
// recs
static bool ByAscendingDate(const RecordingsItemRecPtr & first, const RecordingsItemRecPtr & second);
static bool ByAscendingDuration(const RecordingsItemRecPtr & first, const RecordingsItemRecPtr & second);
static bool ByDuplicatesName(const RecordingsItemRecPtr & first, const RecordingsItemRecPtr & second);
static bool ByDuplicates(const RecordingsItemRecPtr & first, const RecordingsItemRecPtr & second);
static bool ByDuplicatesLanguage(const RecordingsItemRecPtr & first, const RecordingsItemRecPtr & second);
Expand Down Expand Up @@ -338,6 +348,7 @@ cToSvConcat<N> & StringAppendFrameParams(cToSvConcat<N> &s, const cRecording *re
const cSv scraperReleaseDate() const { return m_s_release_date; }
const cTvMedia &scraperImage() const;
int language() const { return m_language; }
int CompareL(const RecordingsItemRecPtr &second, int *numEqualChars=NULL) const;
int CompareTexts(const RecordingsItemRecPtr &second, int *numEqualChars=NULL) const;
int CompareStD(const RecordingsItemRecPtr &second, int *numEqualChars=NULL) const;
bool orderDuplicates(const RecordingsItemRecPtr &second, bool alwaysShortText, bool lang = false) const;
Expand Down