From 5394d8e2c85b52d7375a02f72e089d22a82fba1b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 21 Dec 2020 20:47:59 +0100 Subject: Add pipe plugin, increase video load timeout to 500 seconds --- src/QuickMedia.cpp | 11 ++++++++--- src/VideoPlayer.cpp | 2 +- src/plugins/Pipe.cpp | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 src/plugins/Pipe.cpp (limited to 'src') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index db0f9f6..1191ecb 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -9,6 +9,7 @@ #include "../plugins/Matrix.hpp" #include "../plugins/Pleroma.hpp" #include "../plugins/FileManager.hpp" +#include "../plugins/Pipe.hpp" #include "../include/Scale.hpp" #include "../include/Program.hpp" #include "../include/VideoPlayer.hpp" @@ -396,7 +397,7 @@ namespace QuickMedia { static void usage() { fprintf(stderr, "usage: QuickMedia [--tor] [--no-video] [--use-system-mpv-config] [--dir ]\n"); fprintf(stderr, "OPTIONS:\n"); - fprintf(stderr, " plugin The plugin to use. Should be either 4chan, manganelo, mangatown, mangadex, pornhub, youtube, nyaa.si, matrix or file-manager\n"); + fprintf(stderr, " plugin The plugin to use. Should be either 4chan, manganelo, mangatown, mangadex, pornhub, youtube, nyaa.si, matrix, file-manager or pipe\n"); fprintf(stderr, " --no-video Only play audio when playing a video. Disabled by default\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"); @@ -455,6 +456,8 @@ namespace QuickMedia { plugin_logo_path = resources_root + "images/pleroma_logo.png"; } else if(strcmp(argv[i], "file-manager") == 0) { plugin_name = argv[i]; + } else if(strcmp(argv[i], "pipe") == 0) { + plugin_name = argv[i]; } } @@ -597,6 +600,10 @@ namespace QuickMedia { auto file_manager_body = create_body(); file_manager_page->get_files_in_directory(file_manager_body->items); tabs.push_back(Tab{std::move(file_manager_body), std::move(file_manager_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); + } else if(strcmp(plugin_name, "pipe") == 0) { + auto pipe_body = create_body(); + PipePage::load_body_items_from_stdin(pipe_body->items); + tabs.push_back(Tab{std::move(pipe_body), std::make_unique(this), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); } else if(strcmp(plugin_name, "youtube") == 0) { auto search_body = create_body(); tabs.push_back(Tab{std::move(search_body), std::make_unique(this), create_search_bar("Search...", 350)}); @@ -1817,8 +1824,6 @@ namespace QuickMedia { window_size.y = event.size.height; sf::FloatRect visible_area(0, 0, window_size.x, window_size.y); window.setView(sf::View(visible_area)); - } else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) { - current_page = previous_page; } } diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index c6f5a36..22d1762 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -14,7 +14,7 @@ #include const int RETRY_TIME_MS = 500; -const int MAX_RETRIES_CONNECT = 20; +const int MAX_RETRIES_CONNECT = 1000; const int READ_TIMEOUT_MS = 200; namespace QuickMedia { diff --git a/src/plugins/Pipe.cpp b/src/plugins/Pipe.cpp new file mode 100644 index 0000000..5d7d269 --- /dev/null +++ b/src/plugins/Pipe.cpp @@ -0,0 +1,33 @@ +#include "../../plugins/Pipe.hpp" +#include +#include + +namespace QuickMedia { + PluginResult PipePage::submit(const std::string &title, const std::string&, std::vector &result_tabs) { + puts(title.c_str()); + return PluginResult::OK; + } + + // static + void PipePage::load_body_items_from_stdin(BodyItems &items) { + std::string line; + while(std::getline(std::cin, line)) { + std::string name; + std::string filepath; + size_t split_index = line.find('|'); + if(split_index == std::string::npos) { + name = std::move(line); + } else { + name = line.substr(0, split_index); + filepath = line.substr(split_index + 1); + } + + auto body_item = BodyItem::create(std::move(name)); + if(!filepath.empty()) { + body_item->thumbnail_url = std::move(filepath); + body_item->thumbnail_is_local = true; + } + items.push_back(std::move(body_item)); + } + } +} \ No newline at end of file -- cgit v1.2.3