aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-03 12:42:07 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-03 12:42:07 +0200
commita9074aeb6fdef5139ce978449efa55cf7e388020 (patch)
tree3b77342eeae60429ee729bd11260332317888b82
parentadfdc6109c18776c69d8b519606d6721354ec004 (diff)
Nyaa.si: show title when viewing torrent
-rw-r--r--TODO5
-rw-r--r--src/QuickMedia.cpp4
-rw-r--r--src/plugins/NyaaSi.cpp26
3 files changed, 30 insertions, 5 deletions
diff --git a/TODO b/TODO
index 50e381a..8416a8a 100644
--- a/TODO
+++ b/TODO
@@ -82,4 +82,7 @@ Use linear-interpolation for thumbnail creation.
If --no-audio is used then music should be played with a lightweight music player instead. MPV is heavy even for music (60mb RAM).
Optimize startup time.
Update 4chan thread in real time, just like 4chan-x.
-Save the original event message, so when replying for example we can use the original message as the replying to message, rather than our converted "body" text. \ No newline at end of file
+Save the original event message, so when replying for example we can use the original message as the replying to message, rather than our converted "body" text.
+Remove tidy dependency and use my own html-parser.
+Add option to sort by other than timestamp for nyaa.si.
+Only have one page, and the plugin should have tabs and action after each tab action and use a stack for navigation. \ No newline at end of file
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 0b02000..01bef82 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3323,12 +3323,12 @@ namespace QuickMedia {
size_t index = str.find('\n');
if(index == std::string::npos) {
if(str.size() > max_length)
- return str.substr(0, max_length) + "...";
+ return str.substr(0, max_length) + " (...)";
return str;
} else if(index == 0) {
return "";
} else {
- return str.substr(0, std::min(index, max_length)) + "...";
+ return str.substr(0, std::min(index, max_length)) + " (...)";
}
}
diff --git a/src/plugins/NyaaSi.cpp b/src/plugins/NyaaSi.cpp
index 1cdfc5f..f6724b2 100644
--- a/src/plugins/NyaaSi.cpp
+++ b/src/plugins/NyaaSi.cpp
@@ -237,6 +237,7 @@ namespace QuickMedia {
PluginResult NyaaSi::get_content_details(const std::string&, const std::string &url, BodyItems &result_items) {
size_t comments_start_index;
+ std::string title;
auto torrent_item = BodyItem::create("Download magnet");
std::string magnet_url;
@@ -251,13 +252,32 @@ namespace QuickMedia {
if(result != 0)
goto cleanup;
+ result = quickmedia_html_find_nodes_xpath(&html_search, "//h3[class='panel-title']",
+ [](QuickMediaHtmlNode *node, void *userdata) {
+ std::string *title = (std::string*)userdata;
+ const char *text = quickmedia_html_node_get_text(node);
+ if(title->empty() && text) {
+ *title = text;
+ }
+ }, &title);
+
+ if(result != 0)
+ goto cleanup;
+
+ if(title.empty()) {
+ fprintf(stderr, "Error: nyaa.si: failed to get title\n");
+ result = -1;
+ goto cleanup;
+ }
+
result = quickmedia_html_find_nodes_xpath(&html_search, "//div[class='panel-body']//a",
[](QuickMediaHtmlNode *node, void *userdata) {
auto *item_data = (BodyItems*)userdata;
const char *href = quickmedia_html_node_get_attribute_value(node, "href");
const char *text = quickmedia_html_node_get_text(node);
if(item_data->empty() && href && text && strncmp(href, "/user/", 6) == 0) {
- auto body_item = BodyItem::create("Submitter: " + strip(text));
+ auto body_item = BodyItem::create("");
+ body_item->set_description("Submitter: " + strip(text));
body_item->url = "https://nyaa.si/" + std::string(href);
item_data->push_back(std::move(body_item));
}
@@ -272,6 +292,8 @@ namespace QuickMedia {
goto cleanup;
}
+ result_items.front()->set_title(strip(title));
+
result = quickmedia_html_find_nodes_xpath(&html_search, "//div[id='torrent-description']",
[](QuickMediaHtmlNode *node, void *userdata) {
std::string *description = (std::string*)userdata;
@@ -285,7 +307,7 @@ namespace QuickMedia {
goto cleanup;
if(!description.empty())
- result_items.front()->set_description("Description:\n" + description);
+ result_items.front()->set_description(result_items.front()->get_description() + "\nDescription:\n" + description);
result = quickmedia_html_find_nodes_xpath(&html_search, "//div[class='container']//a",
[](QuickMediaHtmlNode *node, void *userdata) {