Skip to content

Commit

Permalink
recs_level_0
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Ehrnsperger committed Nov 23, 2023
1 parent 444d5b6 commit 62a875e
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 301 deletions.
41 changes: 14 additions & 27 deletions pages/recordings.ecpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ std::vector<int> available_recs;
std::string openTreeNodes;
if (request.hasCookie("VDR-Live-Recordings-Tree-Open-Nodes")) {
openTreeNodes = request.getCookie("VDR-Live-Recordings-Tree-Open-Nodes");
isyslog("live: VDR-Live-Recordings-Tree-Open-Nodes = %s", openTreeNodes.c_str());
// isyslog("live: VDR-Live-Recordings-Tree-Open-Nodes = %s", openTreeNodes.c_str());
}
cLargeString recoring_item("recoring_item", 25000);
</%cpp>
Expand Down Expand Up @@ -456,6 +456,17 @@ if (currentFlat != "true") {
addDuplicateRecordingsNoSd(recItems, recordingsTree);
recItemsC = &recItems;
}
}
// do we have to get/write the recording details?
// we have to, if currentFlat == true || level == 0 || this folder is open (cookie)
bool write_recs = level == 0 || currentFlat == "true";
if (!write_recs) {
// check: is this folder open (cookie)?
auto equal_fldf = [parentIdHash](cSv f) { return f.compare(5, std::string_view::npos, parentIdHash) == 0; };
cSplit splitOpenTreeNodes(openTreeNodes, ',');
write_recs = std::find_if(splitOpenTreeNodes.begin(), splitOpenTreeNodes.end(), equal_fldf) != splitOpenTreeNodes.end();
}
if (write_recs) {
char buffer_i[21];
buffer_i[20] = 0;
</%cpp>
Expand All @@ -466,9 +477,7 @@ if (currentFlat != "true") {
rPtr->AppendAsJSArray(*recoring_item, true);
</%cpp>
recs[<$concat::addCharsIbe(buffer_i+20, rPtr->IdI())$>]=[<$$ recoring_item->c_str() $>]
<%cpp>
}
</%cpp>
% }
</script>
<%cpp>
}
Expand All @@ -489,29 +498,7 @@ if (currentSort != "duplicates" || currentFlat == "true") {
document.write(rec_string_d([<$level$>, <$displayFolder$>, [ <$$ recoring_item->c_str() $> ]]))
% } else {
rec_ids["fldr_<$ parentIdHash $>"] = [<$level$>, <$displayFolder$>, [ <$$ recoring_item->c_str() $> ]]
<%cpp>
// if this folder is open, also add the recs
// check: is this folder open?
auto equal_fldf = [parentIdHash](cSv f) { return f.compare(5, std::string_view::npos, parentIdHash) == 0; };
cSplit splitOpenTreeNodes(openTreeNodes, ',');
if (std::find_if(splitOpenTreeNodes.begin(), splitOpenTreeNodes.end(), equal_fldf) != splitOpenTreeNodes.end()) {
// this folder is open -> write the missing recs
char buffer_i[21];
buffer_i[20] = 0;
for (const RecordingsItemPtr &rPtr: *recItemsC) {
if (std::find(available_recs.begin(), available_recs.end(), rPtr->IdI() ) == available_recs.end() ) {
// this rPtr->IdI() was not provided before
recoring_item->clear();
rPtr->AppendAsJSArray(*recoring_item, true);
</%cpp>
recs[<$concat::addCharsIbe(buffer_i+20, rPtr->IdI())$>]=[<$$ recoring_item->c_str() $>]
<%cpp>
available_recs.push_back(rPtr->IdI());
}
}
}
}
</%cpp>
% }
</script>
<%cpp>
}
Expand Down
64 changes: 51 additions & 13 deletions recman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ namespace vdrlive {

std::string RecordingsManager::Md5Hash(cRecording const * recording) const
{
return "recording_" + MD5Hash(recording->FileName());
m_timeMd5Hash.start();
std::string result = "recording_" + MD5Hash(recording->FileName());
m_timeMd5Hash.stop();
return result;
// return "recording_" + MD5Hash(recording->FileName());
}

cRecording const * RecordingsManager::GetByMd5Hash(cSv hash) const
Expand Down Expand Up @@ -580,16 +584,27 @@ bool searchNameDesc(RecordingsItemPtr &RecItem, const std::vector<RecordingsItem

void RecordingsItem::getScraperData(const cRecording* recording, const cImageLevels &imageLevels, std::string *collectionName) {
cGetScraperVideo getScraperVideo(NULL, recording);
if (getScraperVideo.call(LiveSetup().GetPluginScraper()) ) {
if (m_timeIdentify) m_timeIdentify->start();
bool scraper_available = getScraperVideo.call(LiveSetup().GetPluginScraper());
if (m_timeIdentify) m_timeIdentify->stop();
if (scraper_available) {
m_s_videoType = getScraperVideo.m_scraperVideo->getVideoType();
m_s_dbid = getScraperVideo.m_scraperVideo->getDbId();
getScraperVideo.m_scraperVideo->getOverview(&m_s_title, &m_s_episode_name, &m_s_release_date, &m_s_runtime, &m_s_IMDB_ID, &m_s_collection_id, collectionName);
m_s_episode_number = getScraperVideo.m_scraperVideo->getEpisodeNumber();
m_s_season_number = getScraperVideo.m_scraperVideo->getSeasonNumber();
if (m_s_videoType == tSeries || m_s_videoType == tMovie) {
if (m_timeOverview) m_timeOverview->start();
getScraperVideo.m_scraperVideo->getOverview(&m_s_title, &m_s_episode_name, &m_s_release_date, &m_s_runtime, &m_s_IMDB_ID, &m_s_collection_id, collectionName);
if (m_timeOverview) m_timeOverview->stop();
m_s_episode_number = getScraperVideo.m_scraperVideo->getEpisodeNumber();
m_s_season_number = getScraperVideo.m_scraperVideo->getSeasonNumber();
if (m_timeDurationDeviation) m_timeDurationDeviation->start();
m_duration_deviation = getScraperVideo.m_scraperVideo->getDurationDeviation();
if (m_timeDurationDeviation) m_timeDurationDeviation->stop();
m_language = getScraperVideo.m_scraperVideo->getLanguage();
m_video_SD_HD = getScraperVideo.m_scraperVideo->getHD();
}
if (m_timeImage) m_timeImage->start();
m_s_image = getScraperVideo.m_scraperVideo->getImage(imageLevels, cOrientations(eOrientation::landscape, eOrientation::portrait, eOrientation::banner), false);
m_duration_deviation = getScraperVideo.m_scraperVideo->getDurationDeviation();
m_language = getScraperVideo.m_scraperVideo->getLanguage();
m_video_SD_HD = getScraperVideo.m_scraperVideo->getHD();
if (m_timeImage) m_timeImage->stop();
} else {
// service "GetScraperVideo" is not available, just get the image
m_s_videoType = tNone;
Expand Down Expand Up @@ -719,14 +734,19 @@ bool searchNameDesc(RecordingsItemPtr &RecItem, const std::vector<RecordingsItem
/**
* Implementation of class RecordingsItemRec:
*/
RecordingsItemRec::RecordingsItemRec(int idI, cSv id, cSv name, const cRecording* recording):
RecordingsItemRec::RecordingsItemRec(int idI, cSv id, cSv name, const cRecording* recording, cMeasureTime *timeIdentify, cMeasureTime *timeOverview, cMeasureTime *timeImage, cMeasureTime *timeDurationDeviation):
RecordingsItem(name),
m_recording(recording),
m_id(id),
m_isArchived(RecordingsManager::GetArchiveType(m_recording) )
{
// dsyslog("live: REC: C: rec %s -> %s", name.c_str(), parent->Name().c_str());
m_idI = idI;
m_timeIdentify = timeIdentify;
m_timeOverview = timeOverview;
m_timeImage = timeImage;
m_timeDurationDeviation = timeDurationDeviation;

getScraperData(recording,
cImageLevels(eImageLevel::episodeMovie, eImageLevel::seasonMovie, eImageLevel::tvShowCollection, eImageLevel::anySeasonCollection));
// find our number of ts files
Expand Down Expand Up @@ -986,6 +1006,14 @@ void RecordingsItemRec::AppendAsJSArray(cLargeString &target, std::vector<Record
m_root(new RecordingsItemDir("", 0))
{
// esyslog("live: DH: ****** RecordingsTree::RecordingsTree() ********");
recMan->m_timeMd5Hash.reset();
cMeasureTime timeRecs, timeIdentify, timeOverview, timeImage, timeDurationDeviation;
timeRecs.reset();
timeIdentify.reset();
timeOverview.reset();
timeImage.reset();
timeDurationDeviation.reset();

std::chrono::time_point<std::chrono::high_resolution_clock> begin = std::chrono::high_resolution_clock::now();
// check availability of scraper data
m_creation_timestamp = time(0);
Expand Down Expand Up @@ -1015,21 +1043,23 @@ void RecordingsItemRec::AppendAsJSArray(cLargeString &target, std::vector<Record
else m_maxLevel = std::max(m_maxLevel, recording->HierarchyLevels() );

RecordingsItemPtr dir = m_rootFileSystem;
std::string_view name(recording->Name());
cSv name(recording->Name());

size_t index = 0;
size_t pos = 0;
do {
pos = name.find('~', index);
if (pos != std::string::npos) {
// note: the dir returned is the added (or existing) subdir named name.substr(index, pos - index)
dir = dir->addDirIfNotExists(name.substr(index, pos - index) );
dir = dir->addDirIfNotExists(name.substr_csv(index, pos - index) );
index = pos + 1;
// esyslog("live: DH: current dir: '%s'", dir->Name().c_str());
}
else {
std::string_view recName(name.substr(index, name.length() - index));
RecordingsItemPtr recPtr (new RecordingsItemRec(recording->Id(), recMan->Md5Hash(recording), recName, recording));
cSv recName = name.substr_csv(index, name.length() - index);
timeRecs.start();
RecordingsItemPtr recPtr (new RecordingsItemRec(recording->Id(), recMan->Md5Hash(recording), recName, recording, &timeIdentify, &timeOverview, &timeImage, &timeDurationDeviation));
timeRecs.stop();
dir->m_entries.push_back(recPtr);
m_allRecordings.push_back(recPtr);
// esyslog("live: DH: added rec: '%.*s'", (int)recName.length(), recName.data());
Expand Down Expand Up @@ -1068,6 +1098,14 @@ m_allRecordings.push_back(recPtr);
m_root->finishRecordingsTree();
std::chrono::duration<double> timeNeeded = std::chrono::high_resolution_clock::now() - begin;
esyslog("live: DH: ------ RecordingsTree::RecordingsTree() --------, required time: %9.5f", timeNeeded.count() );
/*
recMan->m_timeMd5Hash.print("live: timeMd5Hash");
timeRecs.print("live: timeRecs ");
timeIdentify.print("live: Identify ");
timeOverview.print("live: Overview ");
timeImage.print("live: Image ");
timeDurationDeviation.print("live: DurDev ");
*/
}

RecordingsTree::~RecordingsTree()
Expand Down
8 changes: 7 additions & 1 deletion recman.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ namespace vdrlive {
* to reidentify a recording.
*/
std::string Md5Hash(cRecording const * recording) const;
mutable cMeasureTime m_timeMd5Hash;

/**
* fetches a cRecording from VDR's Recordings collection. Returns
Expand Down Expand Up @@ -243,6 +244,11 @@ template<class T>
bool recEntriesSorted() { return m_cmp_rec != NULL; }
bool dirEntriesSorted() { return m_cmp_dir != NULL; }

mutable cMeasureTime *m_timeIdentify = nullptr;
mutable cMeasureTime *m_timeOverview = nullptr;
mutable cMeasureTime *m_timeImage = nullptr;
mutable cMeasureTime *m_timeDurationDeviation = nullptr;

private:
std::string GetNameForSearch(cSv name);
protected:
Expand Down Expand Up @@ -333,7 +339,7 @@ template<class T>
class RecordingsItemRec : public RecordingsItem
{
public:
RecordingsItemRec(int idI, cSv id, cSv name, const cRecording* recording);
RecordingsItemRec(int idI, cSv id, cSv name, const cRecording* recording, cMeasureTime *timeIdentify, cMeasureTime *timeOverview, cMeasureTime *timeImage, cMeasureTime *timeDurationDeviation);

virtual ~RecordingsItemRec();

Expand Down
Loading

0 comments on commit 62a875e

Please sign in to comment.