Reading category element from OPDS stream

This commit is contained in:
Veloman Yunkan 2021-03-10 21:26:28 +04:00
parent e55bf514e8
commit 6b2067c236
3 changed files with 27 additions and 3 deletions

View File

@ -95,6 +95,9 @@ class Book
void setFaviconMimeType(const std::string& faviconMimeType) { m_faviconMimeType = faviconMimeType; }
void setDownloadId(const std::string& downloadId) { m_downloadId = downloadId; }
private:
std::string getCategoryFromTags() const;
protected:
std::string m_id;
std::string m_downloadId;
@ -102,6 +105,7 @@ class Book
bool m_pathValid = false;
std::string m_title;
std::string m_description;
std::string m_category;
std::string m_language;
std::string m_creator;
std::string m_publisher;

View File

@ -127,6 +127,7 @@ void Book::updateFromXml(const pugi::xml_node& node, const std::string& baseDir)
try {
m_downloadId = ATTR("downloadId");
} catch(...) {}
m_category = getCategoryFromTags();
}
#undef ATTR
@ -156,6 +157,8 @@ void Book::updateFromOpds(const pugi::xml_node& node, const std::string& urlHost
m_name = VALUE("name");
m_flavour = VALUE("flavour");
m_tags = VALUE("tags");
const auto catnode = node.child("category");
m_category = catnode.empty() ? getCategoryFromTags() : catnode.child_value();
m_articleCount = strtoull(VALUE("articleCount"), 0, 0);
m_mediaCount = strtoull(VALUE("mediaCount"), 0, 0);
for(auto linkNode = node.child("link"); linkNode;
@ -221,6 +224,11 @@ bool Book::getTagBool(const std::string& tagName) const {
}
std::string Book::getCategory() const
{
return m_category;
}
std::string Book::getCategoryFromTags() const
{
try
{

View File

@ -46,7 +46,7 @@ const char * sampleOpdsStream = R"(
<updated>2018-06-23T00:00::00:Z</updated>
<language>fra</language>
<summary>Tania Louis videos</summary>
<tags>youtube</tags>
<tags>youtube;_category:category_defined_via_tags_only</tags>
<link type="text/html" href="/biologie-tout-compris_fr_all_2018-06" />
<author>
<name>Tania Louis</name>
@ -61,6 +61,7 @@ const char * sampleOpdsStream = R"(
<updated>2019-06-05T00:00::00:Z</updated>
<language>fra</language>
<summary>Une page de Wikiquote, le recueil des citations libres.</summary>
<category>category_defined_via_category_element_only</category>
<tags>wikiquote;nopic</tags>
<link type="text/html" href="/wikiquote_fr_all_nopic_2019-06" />
<author>
@ -76,7 +77,8 @@ const char * sampleOpdsStream = R"(
<updated>2019-06-02T00:00::00:Z</updated>
<summary>Une sélection d'articles de Wikipédia sur la géographie</summary>
<language>fra</language>
<tags>wikipedia;nopic</tags>
<category>category_element_overrides_tags</category>
<tags>wikipedia;nopic;_category:tags_override_category_element</tags>
<link type="text/html" href="/wikipedia_fr_geography_nopic_2019-06" />
<author>
<name>Wikipedia</name>
@ -91,7 +93,8 @@ const char * sampleOpdsStream = R"(
<updated>2019-05-13T00:00::00:Z</updated>
<language>fra</language>
<summary>Une</summary>
<tags>wikipedia;nopic</tags>
<tags>wikipedia;nopic;_category:tags_override_category_element</tags>
<category>category_element_overrides_tags</category>
<link type="text/html" href="/wikipedia_fr_mathematics_nopic_2019-05" />
<author>
<name>Wikipedia</name>
@ -228,6 +231,15 @@ TEST_F(LibraryTest, sanityCheck)
EXPECT_EQ(lib.getBooksPublishers().size(), 1U);
}
TEST_F(LibraryTest, categoryHandling)
{
EXPECT_EQ("", lib.getBookById("0c45160e-f917-760a-9159-dfe3c53cdcdd").getCategory());
EXPECT_EQ("category_defined_via_tags_only", lib.getBookById("0d0bcd57-d3f6-cb22-44cc-a723ccb4e1b2").getCategory());
EXPECT_EQ("category_defined_via_category_element_only", lib.getBookById("0ea1cde6-441d-6c58-f2c7-21c2838e659f").getCategory());
EXPECT_EQ("category_element_overrides_tags", lib.getBookById("1123e574-6eef-6d54-28fc-13e4caeae474").getCategory());
EXPECT_EQ("category_element_overrides_tags", lib.getBookById("14829621-c490-c376-0792-9de558b57efa").getCategory());
}
TEST_F(LibraryTest, filterCheck)
{
auto bookIds = lib.filter(kiwix::Filter());