aboutsummaryrefslogtreecommitdiff
path: root/src/Youtube.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-08-05 00:37:57 +0200
committerdec05eba <dec05eba@protonmail.com>2019-08-05 00:38:00 +0200
commit7e8a2f23a40e6374ddfb551920257846021e86fa (patch)
treee9fae05dbc3c2b83f580f5c40fd4cae97e03b536 /src/Youtube.cpp
parent887b6003010a0c455667fb67c12a5577c60498db (diff)
Skip youtube ads in search
Diffstat (limited to 'src/Youtube.cpp')
-rw-r--r--src/Youtube.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/Youtube.cpp b/src/Youtube.cpp
index 4647887..780244c 100644
--- a/src/Youtube.cpp
+++ b/src/Youtube.cpp
@@ -1,8 +1,13 @@
#include "../plugins/Youtube.hpp"
#include <quickmedia/HtmlSearch.h>
#include <json/reader.h>
+#include <string.h>
namespace QuickMedia {
+ static bool begins_with(const char *str, const char *begin_with) {
+ return strncmp(str, begin_with, strlen(begin_with)) == 0;
+ }
+
SearchResult Youtube::search(const std::string &text, std::vector<std::unique_ptr<BodyItem>> &result_items) {
std::string url = "https://youtube.com/results?search_query=";
url += url_param_encode(text);
@@ -21,8 +26,9 @@ namespace QuickMedia {
auto *result_items = (std::vector<std::unique_ptr<BodyItem>>*)userdata;
const char *href = quickmedia_html_node_get_attribute_value(node, "href");
const char *title = quickmedia_html_node_get_attribute_value(node, "title");
- if(href && title) {
- auto item = std::make_unique<BodyItem>(title);
+ // Checking for watch?v helps skipping ads
+ if(href && title && begins_with(href, "/watch?v=")) {
+ auto item = std::make_unique<BodyItem>(title);
item->url = std::string("https://www.youtube.com") + href;
result_items->push_back(std::move(item));
}
@@ -98,7 +104,7 @@ namespace QuickMedia {
auto *result_items = (std::vector<std::unique_ptr<BodyItem>>*)userdata;
const char *href = quickmedia_html_node_get_attribute_value(node, "href");
// TODO: Also add title for related media
- if(href) {
+ if(href && begins_with(href, "/watch?v=")) {
auto item = std::make_unique<BodyItem>("");
item->url = std::string("https://www.youtube.com") + href;
result_items->push_back(std::move(item));