From 9046473e0b71c239851918041b42a3f369ce8f5e Mon Sep 17 00:00:00 2001 From: Markus Ehrnsperger <> Date: Sat, 2 Dec 2023 11:52:30 +0100 Subject: [PATCH] newR --- pages/pageelems.ecpp | 2 +- pages/recordings.ecpp | 10 +- recman.cpp | 87 +++++-------- recman.h | 292 ++++++++++++++++++++---------------------- stringhelpers.h | 2 - tools.cpp | 10 +- 6 files changed, 182 insertions(+), 221 deletions(-) diff --git a/pages/pageelems.ecpp b/pages/pageelems.ecpp index d87c581a..5b64c91f 100644 --- a/pages/pageelems.ecpp +++ b/pages/pageelems.ecpp @@ -347,7 +347,7 @@ function existingRecordingString(col_span, bottomrow, id, archiveDescr, imdb_id, // if (LiveSetup().GetShowIMDb()) { if (s_IMDB_ID.empty() ) { - } else { } diff --git a/pages/recordings.ecpp b/pages/recordings.ecpp index 5ff9d4d4..a0fb1010 100644 --- a/pages/recordings.ecpp +++ b/pages/recordings.ecpp @@ -299,7 +299,7 @@ if (!deleteResult.empty()) { <%cpp> } else { uintptr_t irecoring_item = (uintptr_t)&recoring_item; - RecordingsItemPtr recItemRoot = recordingsTree->getRoot(); + RecordingsItemDirPtr recItemRoot = recordingsTree->getRoot(); uintptr_t iRecItemRoot = (uintptr_t)&recItemRoot; uintptr_t iRecordingsTree = (uintptr_t)&recordingsTree; uintptr_t iOpenTreeNodes = (uintptr_t)&openTreeNodes; @@ -350,7 +350,7 @@ if (currentSort.compare(0, 8, "errorsdur", 8) == 0) sortOrder = eSortOrder::dur if (currentSort.compare(0, 10, "duplicates", 10) == 0) sortOrder = eSortOrder::duplicatesLanguage; if (currentSort == "datedesc" || currentSort == "namedesc") reverse = true; // get rec item of this (current) dir -RecordingsItemPtr recItemThisDir = *(static_cast((void *)iRecItem) ); +RecordingsItemDirPtr recItemThisDir = *(static_cast((void *)iRecItem) ); RecordingsTreePtr recordingsTree = *(static_cast((void *)iRecordingsTree) ); cLargeString *recoring_item = static_cast((void *)irecoring_item ); std::string openTreeNodes= *(static_cast((void *)iOpenTreeNodes) ); @@ -362,8 +362,8 @@ std::vector recItems; const std::vector *recItemsC = NULL; // data for dirs, and loop over dirs -const std::vector *dirItems = recItemThisDir->getDirs(); -std::vector::const_iterator dirIterS, dirIterE, dirIter; +const std::vector *dirItems = recItemThisDir->getDirs(); +std::vector::const_iterator dirIterS, dirIterE, dirIter; int direction; // for dirs if (currentFlat != "true") { if (currentSort != "duplicates") { @@ -384,7 +384,7 @@ if (currentFlat != "true") { // this is the loop over the subdirs // each subdir is a node, which can be expanded (or not) // each subdir has an identifier in
    tag: fldr_<$ idHash $> - RecordingsItemPtr recItem = *dirIter; + RecordingsItemDirPtr recItem = *dirIter; /* search trough directory for new recordings */ bool newR = false; diff --git a/recman.cpp b/recman.cpp index a876a9fb..1c6eaed4 100644 --- a/recman.cpp +++ b/recman.cpp @@ -361,7 +361,7 @@ namespace vdrlive { if(i != 0) return i < 0; return first->CompareStD(second) < 0; } - bool RecordingsItemPtrCompare::ByAscendingNameSort(const RecordingsItemPtr & first, const RecordingsItemPtr & second) // return first < second + bool RecordingsItemPtrCompare::ByAscendingNameSort(const RecordingsItemDirPtr & first, const RecordingsItemDirPtr & second) // return first < second { return compareWithLocale(first->Name(), second->Name()) < 0; } @@ -377,7 +377,7 @@ namespace vdrlive { return first->scraperEpisodeNumber() < second->scraperEpisodeNumber(); } - bool RecordingsItemPtrCompare::BySeason(const RecordingsItemPtr & first, const RecordingsItemPtr & second) { + bool RecordingsItemPtrCompare::BySeason(const RecordingsItemDirPtr & first, const RecordingsItemDirPtr & second) { return first->scraperSeasonNumber() < second->scraperSeasonNumber(); } @@ -463,23 +463,21 @@ bool searchNameDesc(RecordingsItemRecPtr &RecItem, const std::vectornumberOfRecordings(); return result; } - void RecordingsItem::finishRecordingsTree() { + void RecordingsItemDir::finishRecordingsTree() { for (auto &item: m_subdirs) item->finishRecordingsTree(); if (m_cmp_rec) std::sort(m_entries.begin(), m_entries.end(), m_cmp_rec); if (m_cmp_dir) std::sort(m_subdirs.begin(), m_subdirs.end(), m_cmp_dir); @@ -488,31 +486,31 @@ bool searchNameDesc(RecordingsItemRecPtr &RecItem, const std::vector::iterator iter = std::lower_bound(m_subdirs.begin(), m_subdirs.end(), dirName); + RecordingsItemDirPtr RecordingsItemDir::addDirIfNotExists(cSv dirName) { + std::vector::iterator iter = std::lower_bound(m_subdirs.begin(), m_subdirs.end(), dirName); if (iter != m_subdirs.end() && !(dirName < *iter) ) return *iter; - RecordingsItemPtr recPtr (new RecordingsItemDir(dirName, Level() + 1)); + RecordingsItemDirPtr recPtr (new RecordingsItemDir(dirName, Level() + 1)); m_subdirs.insert(iter, recPtr); return recPtr; } - RecordingsItemPtr RecordingsItem::addDirCollectionIfNotExists(int collectionId, const RecordingsItemRecPtr &rPtr) { - std::vector::iterator iter = std::lower_bound(m_subdirs.begin(), m_subdirs.end(), collectionId); + RecordingsItemDirPtr RecordingsItemDir::addDirCollectionIfNotExists(int collectionId, const RecordingsItemRecPtr &rPtr) { + std::vector::iterator iter = std::lower_bound(m_subdirs.begin(), m_subdirs.end(), collectionId); if (iter != m_subdirs.end() && !(collectionId < *iter) ) return *iter; - RecordingsItemPtr recPtr2 (new RecordingsItemDirCollection(Level() + 1, rPtr)); + RecordingsItemDirPtr recPtr2 (new RecordingsItemDirCollection(Level() + 1, rPtr)); m_subdirs.insert(iter, recPtr2); return recPtr2; } - RecordingsItemPtr RecordingsItem::addDirSeasonIfNotExists(int seasonNumber, const RecordingsItemRecPtr &rPtr) { - std::vector::iterator iter = std::lower_bound(m_subdirs.begin(), m_subdirs.end(), seasonNumber); + RecordingsItemDirPtr RecordingsItemDir::addDirSeasonIfNotExists(int seasonNumber, const RecordingsItemRecPtr &rPtr) { + std::vector::iterator iter = std::lower_bound(m_subdirs.begin(), m_subdirs.end(), seasonNumber); if (iter != m_subdirs.end() && !(seasonNumber < *iter) ) return *iter; - RecordingsItemPtr recPtr2 (new RecordingsItemDirSeason(Level() + 1, rPtr)); + RecordingsItemDirPtr recPtr2 (new RecordingsItemDirSeason(Level() + 1, rPtr)); m_subdirs.insert(iter, recPtr2); return recPtr2; } - const std::vector *RecordingsItem::getRecordings(eSortOrder sortOrder) + const std::vector *RecordingsItemDir::getRecordings(eSortOrder sortOrder) { if (m_cmp_rec) return &m_entries; if (sortOrder == eSortOrder::name) { @@ -529,12 +527,12 @@ bool searchNameDesc(RecordingsItemRecPtr &RecItem, const std::vectorcheckNew()) return true; for (const auto &subdir:m_subdirs) if (subdir->checkNew() ) return true; return false; } - void RecordingsItem::addDirList(std::vector &dirs, cSv basePath) + void RecordingsItemDir::addDirList(std::vector &dirs, cSv basePath) const { std::string basePath0(basePath); if (basePath.empty() ) dirs.push_back(""); @@ -548,7 +546,7 @@ bool searchNameDesc(RecordingsItemRecPtr &RecItem, const std::vectorscraperSeasonNumber(); } - const cTvMedia &RecordingsItem::scraperImage() const { + const cTvMedia &RecordingsItemDir::scraperImage() const { if (!m_s_image_requested) { m_s_image_requested = true; if (m_rec_item && m_rec_item->m_scraperVideo) @@ -565,21 +563,6 @@ bool searchNameDesc(RecordingsItemRecPtr &RecItem, const std::vector %s", name.c_str(), parent ? parent->Name().c_str() : "ROOT"); - } - - RecordingsItemDir::~RecordingsItemDir() - { - // dsyslog("live: REC: D: dir %s", Name().c_str()); - } - /** * Implementation of class RecordingsItemDirCollection: */ @@ -668,7 +651,7 @@ bool searchNameDesc(RecordingsItemRecPtr &RecItem, const std::vector= -1) return m_video_SD_HD; // < -2: not checked. -1: Radio. 0 is SD, 1 is HD, >1 is UHD or better if (m_scraperVideo) m_video_SD_HD = m_scraperVideo->getHD(); @@ -889,7 +872,7 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im target.append("\""); } - void RecordingsItemRec::AppendAsJSArray(cLargeString &target) { + void RecordingsItemRec::AppendAsJSArray(cLargeString &target) const { target.append("\""); // [0] : ID target.append(cToSvXxHash128(IdHash())); @@ -1001,11 +984,11 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im } } - bool operator< (const RecordingsItemPtr &a, const RecordingsItemPtr &b) { return *a < b; } - bool operator< (cSv a, const RecordingsItemPtr &b) { return a < b->Name(); } - bool operator< (const RecordingsItemPtr &a, cSv b) { return a->Name() < b; } - bool operator< (int a, const RecordingsItemPtr &b) { return *b > a; } - bool operator< (const RecordingsItemPtr &a, int b) { return *a < b; } + bool operator< (const RecordingsItemDirPtr &a, const RecordingsItemDirPtr &b) { return *a < b; } + bool operator< (cSv a, const RecordingsItemDirPtr &b) { return a < b->Name(); } + bool operator< (const RecordingsItemDirPtr &a, cSv b) { return a->Name() < b; } + bool operator< (int a, const RecordingsItemDirPtr &b) { return *b > a; } + bool operator< (const RecordingsItemDirPtr &a, int b) { return *a < b; } /** * Implementation of class RecordingsTree: @@ -1022,8 +1005,8 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im m_creation_timestamp = time(0); cGetScraperVideo getScraperVideo; bool scraperDataAvailable = getScraperVideo.call(LiveSetup().GetPluginScraper()); - RecordingsItemPtr recPtrTvShows (new RecordingsItemDir(tr("TV shows"), 1)); - RecordingsItemPtr recPtrMovieCollections (new RecordingsItemDir(tr("Movie collections"), 1)); + RecordingsItemDirPtr recPtrTvShows (new RecordingsItemDir(tr("TV shows"), 1)); + RecordingsItemDirPtr recPtrMovieCollections (new RecordingsItemDir(tr("Movie collections"), 1)); // create "base" folders m_allRecordings.clear(); if (scraperDataAvailable) { @@ -1032,7 +1015,7 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im m_root->m_subdirs.push_back(recPtrTvShows); recPtrMovieCollections->m_s_season_number = 2; m_root->m_subdirs.push_back(recPtrMovieCollections); - RecordingsItemPtr recPtrOthers (new RecordingsItemDir(tr("File system view"), 1)); + RecordingsItemDirPtr recPtrOthers (new RecordingsItemDir(tr("File system view"), 1)); recPtrOthers->m_s_season_number = 3; m_rootFileSystem = recPtrOthers; m_root->m_subdirs.push_back(recPtrOthers); @@ -1045,7 +1028,7 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im if (scraperDataAvailable) m_maxLevel = std::max(m_maxLevel, recording->HierarchyLevels() + 1); else m_maxLevel = std::max(m_maxLevel, recording->HierarchyLevels() ); - RecordingsItemPtr dir = m_rootFileSystem; + RecordingsItemDirPtr dir = m_rootFileSystem; cSv name(recording->Name()); size_t index = 0; diff --git a/recman.h b/recman.h index 79ad56d8..563f9cfc 100644 --- a/recman.h +++ b/recman.h @@ -36,18 +36,18 @@ namespace vdrlive { class RecordingsManager; class RecordingsTree; class RecordingsTreePtr; - class RecordingsItem; + class RecordingsItemDir; class RecordingsItemRec; typedef std::shared_ptr RecordingsManagerPtr; - typedef std::shared_ptr RecordingsItemPtr; + typedef std::shared_ptr RecordingsItemDirPtr; typedef std::shared_ptr RecordingsItemRecPtr; - bool operator< (const RecordingsItemPtr &a, const RecordingsItemPtr &b); - bool operator< (cSv a, const RecordingsItemPtr &b); - bool operator< (const RecordingsItemPtr &a, cSv b); - bool operator< (int a, const RecordingsItemPtr &b); - bool operator< (const RecordingsItemPtr &a, int b); + bool operator< (const RecordingsItemDirPtr &a, const RecordingsItemDirPtr &b); + bool operator< (cSv a, const RecordingsItemDirPtr &b); + bool operator< (const RecordingsItemDirPtr &a, cSv b); + bool operator< (int a, const RecordingsItemDirPtr &b); + bool operator< (const RecordingsItemDirPtr &a, int b); int GetNumberOfTsFiles(const cRecording* recording); @@ -60,79 +60,79 @@ namespace vdrlive { */ class RecordingsManager { - friend RecordingsManagerPtr LiveRecordingsManager(); + friend RecordingsManagerPtr LiveRecordingsManager(); - public: - /** - * Returns a shared pointer to a fully populated - * recordings tree. - */ - RecordingsTreePtr GetRecordingsTree() const; - - /** - * fetches a cRecording from VDR's Recordings collection. Returns - * NULL if recording was not found - */ - cRecording const* GetByMd5Hash(cSv hash) const; - - /** - * Move a recording with the given hash according to - * VDRs recording mechanisms. - */ - bool MoveRecording(cRecording const * recording, cSv name, bool copy = false) const; - - /** - * Delete recording resume with the given hash according to - * VDRs recording mechanisms. - */ - void DeleteResume(cRecording const * recording) const; - - /** - * Delete recording marks with the given hash according to - * VDRs recording mechanisms. - */ - void DeleteMarks(cRecording const * recording) const; - - /** - * Delete a recording with the given hash according to - * VDRs recording deletion mechanisms. - */ - void DeleteRecording(cRecording const * recording) const; - - /** - * Determine wether the recording has been archived on - * removable media (e.g. DVD-ROM) - */ - static int GetArchiveType(cRecording const * recording); - - /** - * Provide an identification of the removable media - * (e.g. DVD-ROM Number or Name) where the recording has - * been archived. - */ - static std::string const GetArchiveId(cRecording const * recording, int archiveType); - - static std::string const GetArchiveDescr(cRecording const * recording); + public: + /** + * Returns a shared pointer to a fully populated + * recordings tree. + */ + RecordingsTreePtr GetRecordingsTree() const; + + /** + * fetches a cRecording from VDR's Recordings collection. Returns + * NULL if recording was not found + */ + cRecording const* GetByMd5Hash(cSv hash) const; + + /** + * Move a recording with the given hash according to + * VDRs recording mechanisms. + */ + bool MoveRecording(cRecording const * recording, cSv name, bool copy = false) const; + + /** + * Delete recording resume with the given hash according to + * VDRs recording mechanisms. + */ + void DeleteResume(cRecording const * recording) const; + + /** + * Delete recording marks with the given hash according to + * VDRs recording mechanisms. + */ + void DeleteMarks(cRecording const * recording) const; + + /** + * Delete a recording with the given hash according to + * VDRs recording deletion mechanisms. + */ + void DeleteRecording(cRecording const * recording) const; + + /** + * Determine wether the recording has been archived on + * removable media (e.g. DVD-ROM) + */ + static int GetArchiveType(cRecording const * recording); + + /** + * Provide an identification of the removable media + * (e.g. DVD-ROM Number or Name) where the recording has + * been archived. + */ + static std::string const GetArchiveId(cRecording const * recording, int archiveType); + + static std::string const GetArchiveDescr(cRecording const * recording); - private: - RecordingsManager(); + private: + RecordingsManager(); - static bool StateChanged(); - static RecordingsManagerPtr EnsureValidData(); + static bool StateChanged(); + static RecordingsManagerPtr EnsureValidData(); - static std::weak_ptr m_recMan; - static std::shared_ptr m_recTree; - static cStateKey m_recordingsStateKey; + static std::weak_ptr m_recMan; + static std::shared_ptr m_recTree; + static cStateKey m_recordingsStateKey; }; class ShortTextDescription { - public: - ShortTextDescription(const char * ShortText, const char * Description); - wint_t getNextNonPunctChar(); - private: - const char * m_short_text; - const char * m_description; + public: + ShortTextDescription(const char * ShortText, const char * Description); + wint_t getNextNonPunctChar(); + private: + const char * m_short_text; + const char * m_description; }; /** @@ -140,21 +140,24 @@ namespace vdrlive { */ enum class eSortOrder { name, date, errors, durationDeviation, duplicatesLanguage }; typedef bool (*tCompRec)(const RecordingsItemRecPtr &a, const RecordingsItemRecPtr &b); - typedef bool (*tCompDir)(const RecordingsItemPtr &a, const RecordingsItemPtr &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 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); - static bool ByAscendingNameSort(const RecordingsItemPtr & first, const RecordingsItemPtr & second); static bool ByAscendingNameDescSort(const RecordingsItemRecPtr & first, const RecordingsItemRecPtr & second); static bool ByDescendingRecordingErrors(const RecordingsItemRecPtr & first, const RecordingsItemRecPtr & second); static bool ByDescendingDurationDeviation(const RecordingsItemRecPtr & first, const RecordingsItemRecPtr & second); static bool ByEpisode(const RecordingsItemRecPtr & first, const RecordingsItemRecPtr & second); - static bool BySeason(const RecordingsItemPtr & first, const RecordingsItemPtr & second); static bool ByReleaseDate(const RecordingsItemRecPtr & first, const RecordingsItemRecPtr & second); +// dirs + static bool ByAscendingNameSort(const RecordingsItemDirPtr & first, const RecordingsItemDirPtr & second); + static bool BySeason(const RecordingsItemDirPtr & first, const RecordingsItemDirPtr & second); +// helpers static int compareLC(const char *first, const char *second, int *numEqualChars = NULL); // as std::compare, but compare lower case static int FindBestMatch(RecordingsItemRecPtr &BestMatch, const std::vector::const_iterator & First, const std::vector::const_iterator & Last, const RecordingsItemRecPtr & EPG_Entry); @@ -163,63 +166,60 @@ namespace vdrlive { // search a recording matching an EPG entry. The EPG entry is given with Name, ShortText, Description, Duration, scraperOverview bool searchNameDesc(RecordingsItemRecPtr &RecItem, const std::vector *RecItems, const cEvent *event, cScraperVideo *scraperVideo); - /** - * Base class for entries in recordings tree and recordings list. - * All operations possible on recordings are performed against - * pointers to instances of recordings items. The C++ polymorphy - * delegates them to the 'right' class. - */ - class RecordingsItem +/** + * A recordings item that resembles a directory with other + * subdirectories and/or real recordings. + */ + class RecordingsItemDir { friend class RecordingsTree; protected: - RecordingsItem(cSv name); + RecordingsItemDir(cSv name, int level); public: - virtual ~RecordingsItem(); + virtual ~RecordingsItemDir(); - virtual const cSv Name() const { return m_name; } + cSv Name() const { return m_name; } + int Level() const { return m_level; } void finishRecordingsTree(); // sort recursively, Order: m_cmp_rec (if defined. Otherwise: no sort) // dirs: Order: m_cmp_dir (if defined. Otherwise: m_name_for_sort) - virtual bool operator< (const RecordingsItemPtr &sec) const { return m_name < sec->m_name; } + virtual bool operator< (const RecordingsItemDirPtr &sec) const { return m_name < sec->m_name; } virtual bool operator< (cSv sec) const { return m_name < sec; } virtual bool operator> (cSv sec) const { return m_name > sec; } virtual bool operator< (int sec) const { return false; } virtual bool operator> (int sec) const { return false; } - virtual int Level() { return 0; } - int numberOfRecordings(); - RecordingsItemPtr addDirIfNotExists(cSv dirName); - RecordingsItemPtr addDirCollectionIfNotExists(int collectionId, const RecordingsItemRecPtr &rPtr); - RecordingsItemPtr addDirSeasonIfNotExists(int seasonNumber, const RecordingsItemRecPtr &rPtr); + int numberOfRecordings() const; + RecordingsItemDirPtr addDirIfNotExists(cSv dirName); + RecordingsItemDirPtr addDirCollectionIfNotExists(int collectionId, const RecordingsItemRecPtr &rPtr); + RecordingsItemDirPtr addDirSeasonIfNotExists(int seasonNumber, const RecordingsItemRecPtr &rPtr); const std::vector *getRecordings(eSortOrder sortOrder); - const std::vector *getDirs() { return &m_subdirs; } - bool checkNew(); - void addDirList(std::vector &dirs, cSv basePath); + const std::vector *getDirs() { return &m_subdirs; } + bool checkNew() const; + void addDirList(std::vector &dirs, cSv basePath) const; void setTvShow(const RecordingsItemRecPtr &rPtr); int scraperCollectionId() const { return m_s_collection_id; } int scraperSeasonNumber() const { return m_s_season_number; } const cTvMedia &scraperImage() const; - virtual const char *NewR() const { return "" ; } - bool recEntriesSorted() { return m_cmp_rec != NULL; } - bool dirEntriesSorted() { return m_cmp_dir != NULL; } + bool recEntriesSorted() const { return m_cmp_rec != NULL; } + bool dirEntriesSorted() const { return m_cmp_dir != NULL; } protected: std::string m_name; - std::vector m_subdirs; + int m_level; + std::vector m_subdirs; std::vector m_entries; bool m_entriesSorted = false; std::vector m_entries_other_sort; eSortOrder m_sortOrder = (eSortOrder)-1; - bool (*m_cmp_dir)(const RecordingsItemPtr &itemPtr1, const RecordingsItemPtr &itemPtr2) = NULL; + bool (*m_cmp_dir)(const RecordingsItemDirPtr &itemPtr1, const RecordingsItemDirPtr &itemPtr2) = NULL; bool (*m_cmp_rec)(const RecordingsItemRecPtr &itemPtr1, const RecordingsItemRecPtr &itemPtr2) = NULL; // scraper data RecordingsItemRecPtr m_rec_item; // in this rec item (if available), there are the relevant scraper data - // for rec items, it is just a pointer to the rec itme itself - // for dirs (collection), it point to a rec item with relevant data for the collection + // for dirs (collection), it points to a rec item with relevant data for the collection // similar for dirs (TV show, season). // for others, it is just nullptr -> no data available mutable cTvMedia m_s_image; @@ -229,49 +229,30 @@ namespace vdrlive { int m_s_season_number = 0; }; - - /** - * A recordings item that resembles a directory with other - * subdirectories and/or real recordings. - */ - class RecordingsItemDir : public RecordingsItem - { - public: - RecordingsItemDir(cSv name, int level); - - virtual ~RecordingsItemDir(); - virtual int Level() { return m_level; } - - private: - int m_level; - }; - class RecordingsItemDirSeason : public RecordingsItemDir { - public: - RecordingsItemDirSeason(int level, const RecordingsItemRecPtr &rPtr); - virtual ~RecordingsItemDirSeason(); - - virtual bool operator< (const RecordingsItemPtr &sec) const { return m_s_season_number < sec->scraperSeasonNumber(); } - virtual bool operator< (cSv sec) const { return false; } - virtual bool operator> (cSv sec) const { return false; } - virtual bool operator< (int sec) const { return m_s_season_number < sec; } - virtual bool operator> (int sec) const { return m_s_season_number > sec; } - + public: + RecordingsItemDirSeason(int level, const RecordingsItemRecPtr &rPtr); + virtual ~RecordingsItemDirSeason(); + + virtual bool operator< (const RecordingsItemDirPtr &sec) const { return m_s_season_number < sec->scraperSeasonNumber(); } + virtual bool operator< (cSv sec) const { return false; } + virtual bool operator> (cSv sec) const { return false; } + virtual bool operator< (int sec) const { return m_s_season_number < sec; } + virtual bool operator> (int sec) const { return m_s_season_number > sec; } }; class RecordingsItemDirCollection : public RecordingsItemDir { - public: - RecordingsItemDirCollection(int level, const RecordingsItemRecPtr &rPtr); - virtual ~RecordingsItemDirCollection(); - - virtual bool operator< (const RecordingsItemPtr &sec) const { return m_s_collection_id < sec->scraperCollectionId(); } - virtual bool operator< (cSv sec) const { return false; } - virtual bool operator> (cSv sec) const { return false; } - virtual bool operator< (int sec) const { return m_s_collection_id < sec; } - virtual bool operator> (int sec) const { return m_s_collection_id > sec; } - + public: + RecordingsItemDirCollection(int level, const RecordingsItemRecPtr &rPtr); + virtual ~RecordingsItemDirCollection(); + + virtual bool operator< (const RecordingsItemDirPtr &sec) const { return m_s_collection_id < sec->scraperCollectionId(); } + virtual bool operator< (cSv sec) const { return false; } + virtual bool operator> (cSv sec) const { return false; } + virtual bool operator< (int sec) const { return m_s_collection_id < sec; } + virtual bool operator> (int sec) const { return m_s_collection_id > sec; } }; @@ -283,7 +264,6 @@ namespace vdrlive { class RecordingsItemRec { friend class RecordingsTree; - friend class RecordingsItem; friend class RecordingsItemDir; friend class RecordingsItemDirSeason; friend class RecordingsItemDirCollection; @@ -292,8 +272,8 @@ namespace vdrlive { virtual ~RecordingsItemRec(); - virtual const cSv Name() const { return m_name; } - virtual const cSv NameForSearch() const { return m_name_for_search; } + const cSv Name() const { return m_name; } + const cSv NameForSearch() const { return m_name_for_search; } virtual const char * ShortText() const { return RecInfo()? RecInfo()->ShortText():0; } virtual const char * Description() const { return RecInfo()? RecInfo()->Description():0; } virtual time_t StartTime() const { return m_recording->Start(); } @@ -307,10 +287,10 @@ namespace vdrlive { virtual const cRecordingInfo* RecInfo() const { return m_recording->Info(); } // To display the recording on the UI - virtual bool checkNew() { return m_recording->GetResume() <= 0; } - virtual const int IsArchived() const { return m_isArchived ; } + virtual const int IsArchived() const { return m_isArchived; } virtual const std::string ArchiveDescr() const { return RecordingsManager::GetArchiveDescr(m_recording) ; } - virtual const char *NewR() const { return LiveSetup().GetMarkNewRec() && (Recording()->GetResume() < 0) ? "_new" : "" ; } + virtual const char *NewR() const { return LiveSetup().GetMarkNewRec() && Recording()->IsNew() ? "_new" : "" ; } + virtual bool checkNew() const { return m_recording->IsNew(); } // for recursive checks on dirs, here we don't check LiveSetup #if VDRVERSNUM >= 20505 virtual const int RecordingErrors() const { return RecInfo()->Errors(); } #else @@ -334,10 +314,10 @@ namespace vdrlive { int CompareStD(const RecordingsItemRecPtr &second, int *numEqualChars=NULL) const; bool orderDuplicates(const RecordingsItemRecPtr &second, bool alwaysShortText, bool lang = false) const; // To display the recording on the UI - bool matchesFilter(cSv filter); + bool matchesFilter(cSv filter) const; - virtual int SD_HD(); - virtual void AppendAsJSArray(cLargeString &target); + virtual int SD_HD() const; + virtual void AppendAsJSArray(cLargeString &target) const; static void AppendAsJSArray(cLargeString &target, std::vector::const_iterator recIterFirst, std::vector::const_iterator recIterLast, bool &first, cSv filter, bool reverse); mutable cMeasureTime *m_timeIdentify = nullptr; @@ -369,7 +349,7 @@ namespace vdrlive { int m_s_episode_number = 0; int m_s_season_number = 0; int m_language = 0; - int m_video_SD_HD = -2; // < -2: not checked. -1: Radio. 0 is SD, 1 is HD, >1 is UHD or better + mutable int m_video_SD_HD = -2; // < -2: not checked. -1: Radio. 0 is SD, 1 is HD, >1 is UHD or better int m_duration_deviation = 0; protected: @@ -397,7 +377,7 @@ namespace vdrlive { virtual const cRecording* Recording() const { return nullptr; } virtual const cRecordingInfo* RecInfo() const { return nullptr; } - virtual bool checkNew() { return false; } + virtual bool checkNew() const { return false; } virtual const int IsArchived() const { return 0 ; } virtual const std::string ArchiveDescr() const { return std::string(); } virtual const char *NewR() const { return ""; } @@ -406,8 +386,8 @@ namespace vdrlive { virtual void getScraperData(std::string *collectionName = NULL) {} const cTvMedia &scraperImage() const { return m_s_image; } - virtual int SD_HD() { return 0; } - virtual void AppendAsJSArray(cLargeString &target) {} + virtual int SD_HD() const { return 0; } + virtual void AppendAsJSArray(cLargeString &target) const {} private: const cEvent *m_event; }; @@ -426,7 +406,7 @@ namespace vdrlive { public: virtual ~RecordingsTree(); - RecordingsItemPtr getRoot() const { return m_root; } + RecordingsItemDirPtr getRoot() const { return m_root; } std::vector getAllDirs() { std::vector result; m_rootFileSystem->addDirList(result, ""); return result; } const std::vector *allRecordings() { return &m_allRecordings;} const std::vector *allRecordings(eSortOrder sortOrder); @@ -436,8 +416,8 @@ namespace vdrlive { private: int m_maxLevel; - RecordingsItemPtr m_root; - RecordingsItemPtr m_rootFileSystem; + RecordingsItemDirPtr m_root; + RecordingsItemDirPtr m_rootFileSystem; std::vector m_allRecordings; bool m_allRecordingsSorted = false; std::vector m_allRecordings_other_sort; @@ -474,10 +454,10 @@ namespace vdrlive { */ RecordingsManagerPtr LiveRecordingsManager(); - inline void print(const char *t, const RecordingsItemPtr &a) { + inline void print(const char *t, const RecordingsItemDirPtr &a) { std::cout << t << (a ? a->Name() : "nullptr"); } - inline void swap(RecordingsItemPtr &a, RecordingsItemPtr &b) { + inline void swap(RecordingsItemDirPtr &a, RecordingsItemDirPtr &b) { a.swap(b); } inline void swap(RecordingsItemRecPtr &a, RecordingsItemRecPtr &b) { diff --git a/stringhelpers.h b/stringhelpers.h index d347ae77..ad5934ba 100644 --- a/stringhelpers.h +++ b/stringhelpers.h @@ -151,9 +151,7 @@ class cSv: public std::string_view { cSv(const cSv &sv): std::string_view(sv) {} cSv(const std::string &s): std::string_view(s) {} cSv substr(size_t pos = 0) const { return (length() > pos)?cSv(data() + pos, length() - pos):cSv(); } - cSv substr_csv(size_t pos = 0) const { return (length() > pos)?cSv(data() + pos, length() - pos):cSv(); } cSv substr(size_t pos, size_t count) const { return (length() > pos)?cSv(data() + pos, std::min(length() - pos, count) ):cSv(); } - cSv substr_csv(size_t pos, size_t count) const { return (length() > pos)?cSv(data() + pos, std::min(length() - pos, count) ):cSv(); } private: static std::string_view charPointerToStringView(const char *s) { return s?std::string_view(s, strlen(s)):std::string_view(); diff --git a/tools.cpp b/tools.cpp index 057406aa..a8f152b7 100644 --- a/tools.cpp +++ b/tools.cpp @@ -194,9 +194,9 @@ template void AppendDuration(cLargeString &target, char const* for return input; } truncated = true; - cSv result = input.substr_csv(0, maxLen); + cSv result = input.substr(0, maxLen); size_t pos = result.find_last_of(" \t,;:.\n?!'\"/\\()[]{}*+-"); - return result.substr_csv(0, pos); + return result.substr(0, pos); } std::string StringFormatBreak(cSv input) @@ -216,10 +216,10 @@ template void AppendDuration(cLargeString &target, char const* for { size_t pos = str.find_last_not_of(' '); if (pos == std::string::npos) return cSv(); - cSv trailBlankRemoved = str.substr_csv(0, pos); + cSv trailBlankRemoved = str.substr(0, pos); pos = trailBlankRemoved.find_first_not_of(' '); if (pos == std::string::npos) return cSv(); - return trailBlankRemoved.substr_csv(pos); + return trailBlankRemoved.substr(pos); } // Spielfilm Thailand / Deutschland / Großbritannien 2015 (Rak ti Khon Kaen) @@ -638,7 +638,7 @@ template void AppendTextTruncateOnWord(cLargeString &target, const esyslog("live: ERROR, image path %.*s does not start with %s", (int)path.length(), path.data(), LiveSetup().GetTvscraperImageDir().c_str()); return cSv(); } - return path.substr_csv(tvscraperImageDirLength); + return path.substr(tvscraperImageDirLength); } bool ScraperCallService(const char *Id, void *Data) {