aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp74
1 files changed, 61 insertions, 13 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index f5aaea5..01a82c6 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -6,6 +6,7 @@
#include "../plugins/Pornhub.hpp"
#include "../plugins/Fourchan.hpp"
#include "../plugins/Dmenu.hpp"
+#include "../plugins/NyaaSi.hpp"
#include "../include/Scale.hpp"
#include "../include/Program.h"
#include "../include/VideoPlayer.hpp"
@@ -161,9 +162,9 @@ namespace QuickMedia {
if (!disp)
throw std::runtime_error("Failed to open display to X11 server");
- resources_root = "../../../";
- if(get_file_type("/usr/share/quickmedia/") == FileType::DIRECTORY) {
- resources_root = "/usr/share/quickmedia/";
+ resources_root = "/usr/share/quickmedia/";
+ if(get_file_type("../../../images/manganelo_logo.png") == FileType::REGULAR) {
+ resources_root = "../../../";
}
if(!font.loadFromFile(resources_root + "fonts/Lato-Regular.ttf")) {
@@ -236,7 +237,7 @@ namespace QuickMedia {
static void usage() {
fprintf(stderr, "usage: QuickMedia <plugin> [--tor] [--use-system-mpv-config] [-p placeholder-text]\n");
fprintf(stderr, "OPTIONS:\n");
- fprintf(stderr, " plugin The plugin to use. Should be either 4chan, manganelo, mangatown, mangadex, pornhub, youtube or dmenu\n");
+ fprintf(stderr, " plugin The plugin to use. Should be either 4chan, manganelo, mangatown, mangadex, pornhub, youtube, nyaa.si or dmenu\n");
fprintf(stderr, " --tor Use tor. Disabled by default\n");
fprintf(stderr, " --use-system-mpv-config Use system mpv config instead of no config. Disabled by default\n");
fprintf(stderr, " --upscale-images Upscale low-resolution manga pages using waifu2x-ncnn-vulkan. Disabled by default\n");
@@ -296,6 +297,9 @@ namespace QuickMedia {
} else if(strcmp(argv[i], "4chan") == 0) {
current_plugin = new Fourchan(resources_root);
plugin_logo_path = resources_root + "images/4chan_logo.png";
+ } else if(strcmp(argv[i], "nyaa.si") == 0) {
+ current_plugin = new NyaaSi();
+ plugin_logo_path = resources_root + "images/nyaa_si_logo.png";
} else if(strcmp(argv[i], "dmenu") == 0) {
current_plugin = new Dmenu();
} else {
@@ -827,7 +831,7 @@ namespace QuickMedia {
return false;
Page next_page = current_plugin->get_page_after_search();
- bool skip_search = next_page == Page::VIDEO_CONTENT;
+ bool skip_search = (next_page == Page::VIDEO_CONTENT || next_page == Page::CONTENT_LIST);
// TODO: This shouldn't be done if search_selected_suggestion fails
if(search_selected_suggestion(input_body, output_body, current_plugin, content_title, content_url, skip_search) != SearchResult::OK) {
show_notification("Search", "Search failed!", Urgency::CRITICAL);
@@ -2291,15 +2295,28 @@ namespace QuickMedia {
}
void Program::content_list_page() {
+ std::string update_search_text;
+ bool search_running = false;
+ std::future<BodyItems> search_future;
+
+ if(!current_plugin->content_list_search_is_filter())
+ search_bar->text_autosearch_delay = current_plugin->get_content_list_search_delay();
+
+ body->clear_items();
+ body->clear_thumbnails();
if(current_plugin->get_content_list(content_list_url, body->items) != PluginResult::OK) {
show_notification("Content list", "Failed to get content list for url: " + content_list_url, Urgency::CRITICAL);
current_page = Page::SEARCH_SUGGESTION;
return;
}
- search_bar->onTextUpdateCallback = [this](const std::string &text) {
- body->filter_search_fuzzy(text);
- body->select_first_item();
+ search_bar->onTextUpdateCallback = [this, &update_search_text](const std::string &text) {
+ if(current_plugin->content_list_search_is_filter()) {
+ body->filter_search_fuzzy(text);
+ body->clamp_selection();
+ } else {
+ update_search_text = text;
+ }
};
search_bar->onTextSubmitCallback = [this](const std::string &text) -> bool {
@@ -2335,11 +2352,35 @@ namespace QuickMedia {
search_bar->update();
+ if(!update_search_text.empty() && !search_running) {
+ search_future = std::async(std::launch::async, [this, update_search_text]() {
+ BodyItems result;
+ if(current_plugin->content_list_search(content_list_url, update_search_text, result) != SearchResult::OK) {
+ show_notification("Search", "Search failed!", Urgency::CRITICAL);
+ }
+ return result;
+ });
+ update_search_text.clear();
+ search_running = true;
+ }
+
+ if(search_running && search_future.valid() && search_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
+ if(update_search_text.empty()) {
+ body->items = search_future.get();
+ body->clamp_selection();
+ } else {
+ search_future.get();
+ }
+ search_running = false;
+ }
+
window.clear(back_color);
body->draw(window, body_pos, body_size);
search_bar->draw(window);
window.display();
}
+
+ search_bar->text_autosearch_delay = current_plugin->get_search_delay();
}
void Program::content_details_page() {
@@ -2352,15 +2393,22 @@ namespace QuickMedia {
return;
}
- // Instead of using search bar to searching, use it for commenting.
// TODO: Have an option for the search bar to be multi-line.
search_bar->onTextUpdateCallback = nullptr;
search_bar->onTextSubmitCallback = [this](const std::string &text) -> bool {
- if(text.empty())
- return false;
-
- return true;
+ if(current_plugin->name == "nyaa.si") {
+ BodyItem *selected_item = body->get_selected();
+ if(selected_item && strncmp(selected_item->url.c_str(), "magnet:?", 8) == 0) {
+ if(!is_program_executable_by_name("xdg-open")) {
+ show_notification("Nyaa.si", "xdg-utils which provides xdg-open needs to be installed to download torrents", Urgency::CRITICAL);
+ return false;
+ }
+ const char *args[] = { "xdg-open", selected_item->url.c_str(), nullptr };
+ exec_program_async(args, nullptr);
+ }
+ }
+ return false;
};
sf::Vector2f body_pos;