Languages OPDS feed includes book counts

This commit is contained in:
Veloman Yunkan
2021-07-08 17:00:54 +04:00
committed by Matthieu Gautier
parent 45adda44b3
commit ab3095745e
5 changed files with 34 additions and 5 deletions

View File

@ -208,18 +208,26 @@ bool Library::writeBookmarksToFile(const std::string& path) const
return writeTextFile(path, dumper.dumpLibXMLBookmark());
}
std::vector<std::string> Library::getBookPropValueSet(BookStrPropMemFn p) const
Library::AttributeCounts Library::getBookAttributeCounts(BookStrPropMemFn p) const
{
std::set<std::string> propValues;
AttributeCounts propValueCounts;
for (const auto& pair: m_books) {
const auto& book = pair.second;
if (book.getOrigId().empty()) {
propValues.insert((book.*p)());
propValueCounts[(book.*p)()] += 1;
}
}
return propValueCounts;
}
return std::vector<std::string>(propValues.begin(), propValues.end());
std::vector<std::string> Library::getBookPropValueSet(BookStrPropMemFn p) const
{
std::vector<std::string> result;
for ( const auto& kv : getBookAttributeCounts(p) ) {
result.push_back(kv.first);
}
return result;
}
std::vector<std::string> Library::getBooksLanguages() const
@ -227,6 +235,11 @@ std::vector<std::string> Library::getBooksLanguages() const
return getBookPropValueSet(&Book::getLanguage);
}
Library::AttributeCounts Library::getBooksLanguagesWithCounts() const
{
return getBookAttributeCounts(&Book::getLanguage);
}
std::vector<std::string> Library::getBooksCategories() const
{
std::set<std::string> categories;

View File

@ -160,11 +160,14 @@ std::string OPDSDumper::languagesOPDSFeed() const
{
const auto now = gen_date_str();
kainjow::mustache::list languageData;
for ( const auto& languageCode : library->getBooksLanguages() ) {
for ( const auto& langAndBookCount : library->getBooksLanguagesWithCounts() ) {
const std::string languageCode = langAndBookCount.first;
const int bookCount = langAndBookCount.second;
const auto languageSelfName = getLanguageSelfName(languageCode);
languageData.push_back(kainjow::mustache::object{
{"lang_code", languageCode},
{"lang_self_name", languageSelfName},
{"book_count", to_string(bookCount)},
{"updated", now},
{"id", gen_uuid(libraryId + "/languages/" + languageCode)}
});