From 4694f8544c4cbd7e7d92323976b63cc77fdadb27 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 28 Apr 2021 20:02:14 +0200 Subject: Lazy load recommendations, simplify html parser --- src/plugins/Pleroma.cpp | 5 +---- src/plugins/Pornhub.cpp | 7 ++----- src/plugins/Spankbang.cpp | 11 ++--------- src/plugins/Youtube.cpp | 5 +---- 4 files changed, 6 insertions(+), 22 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Pleroma.cpp b/src/plugins/Pleroma.cpp index 20d71c7..f0bb808 100644 --- a/src/plugins/Pleroma.cpp +++ b/src/plugins/Pleroma.cpp @@ -61,10 +61,7 @@ namespace QuickMedia { std::string content(content_json.GetString(), content_json.GetStringLength()); HtmlParseUserdata parse_userdata; - HtmlParser html_parser; - html_parser_init(&html_parser, content.data(), content.size(), html_parse_callback, &parse_userdata); - html_parser_parse(&html_parser); - html_parser_deinit(&html_parser); + html_parser_parse(content.data(), content.size(), html_parse_callback, &parse_userdata); while(!parse_userdata.result.empty() && parse_userdata.result.back() == '\n') parse_userdata.result.pop_back(); diff --git a/src/plugins/Pornhub.cpp b/src/plugins/Pornhub.cpp index 4d30001..1aa0851 100644 --- a/src/plugins/Pornhub.cpp +++ b/src/plugins/Pornhub.cpp @@ -59,14 +59,11 @@ namespace QuickMedia { } } - static HtmlElement* html_parse(char *source, size_t size) { + static HtmlElement* html_parse(const char *source, size_t size) { HtmlElement *html_element_root = new HtmlElement(); HtmlParseUserdata parse_userdata; parse_userdata.current_html_element = html_element_root; - HtmlParser html_parser; - html_parser_init(&html_parser, source, size, html_page_callback, &parse_userdata); - html_parser_parse(&html_parser); - html_parser_deinit(&html_parser); + html_parser_parse(source, size, html_page_callback, &parse_userdata); return html_element_root; } diff --git a/src/plugins/Spankbang.cpp b/src/plugins/Spankbang.cpp index cc35d39..ac0e371 100644 --- a/src/plugins/Spankbang.cpp +++ b/src/plugins/Spankbang.cpp @@ -21,10 +21,6 @@ namespace { } namespace QuickMedia { - static bool begins_with(const char *str, const char *begin_with) { - return strncmp(str, begin_with, strlen(begin_with)) == 0; - } - static void html_cleanup(HtmlElement *html_element_root) { for(HtmlElement *child_html_element : html_element_root->children) { html_cleanup(child_html_element); @@ -59,14 +55,11 @@ namespace QuickMedia { } } - static HtmlElement* html_parse(char *source, size_t size) { + static HtmlElement* html_parse(const char *source, size_t size) { HtmlElement *html_element_root = new HtmlElement(); HtmlParseUserdata parse_userdata; parse_userdata.current_html_element = html_element_root; - HtmlParser html_parser; - html_parser_init(&html_parser, source, size, html_page_callback, &parse_userdata); - html_parser_parse(&html_parser); - html_parser_deinit(&html_parser); + html_parser_parse(source, size, html_page_callback, &parse_userdata); return html_element_root; } diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 4c4372e..d03105c 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -1284,8 +1284,7 @@ namespace QuickMedia { std::vector subscription_data_list; - HtmlParser html_parser; - html_parser_init(&html_parser, website_data.data(), website_data.size(), [](HtmlParser *html_parser, HtmlParseType parse_type, void *userdata) { + html_parser_parse(website_data.data(), website_data.size(), [](HtmlParser *html_parser, HtmlParseType parse_type, void *userdata) { std::vector &subscription_data_list = *(std::vector*)userdata; if(parse_type == HTML_PARSE_TAG_START && string_view_equals(&html_parser->tag_name, "entry")) { @@ -1328,8 +1327,6 @@ namespace QuickMedia { subscription_data_list.back().subscription_entry.published = timegm(&time); } }, &subscription_data_list); - html_parser_parse(&html_parser); - html_parser_deinit(&html_parser); std::vector results; for(SubscriptionData &subscription_data : subscription_data_list) { -- cgit v1.2.3