From d0dda48e791e6f08f6be3936623a2c305caacb3c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 8 Sep 2022 20:31:30 +0200 Subject: Peertube: load known instances from config file --- src/Config.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++--- src/plugins/Peertube.cpp | 31 ++++++++++++++----------------- 2 files changed, 58 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/Config.cpp b/src/Config.cpp index c6c2a29..9272939 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -108,6 +108,28 @@ namespace QuickMedia { }); } + static void peertube_known_instances_fallback() { + config->peertube.known_instances.insert(config->peertube.known_instances.end(), { + "https://tube.midov.pl", + "https://videos.lukesmith.xyz", + "https://peertube.se", + "https://bittube.video", + "https://video.nobodyhasthe.biz", + "https://libre.tube", + "https://open.tube", + "https://runtube.re", + "https://tube.kenfm.de", + "https://tcode.kenfm.de", + "https://tube.querdenken-711.de", + "https://peertube.rage.lol", + "https://gegenstimme.tv", + "https://tv.poa.st", + "https://libre.video", + "https://gorf.tube", + "https://neogenesis.tv" + }); + } + static void config_load_fail_fallback() { matrix_known_homeservers_fallback(); } @@ -195,12 +217,12 @@ namespace QuickMedia { if(youtube_json.isObject()) get_json_value(youtube_json, "load_progress", config->youtube.load_progress); - bool has_known_homeservers_config = false; + bool has_known_matrix_homeservers_config = false; const Json::Value &matrix_json = json_root["matrix"]; if(matrix_json.isObject()) { const Json::Value &known_homeservers_json = matrix_json["known_homeservers"]; if(known_homeservers_json.isArray()) { - has_known_homeservers_config = true; + has_known_matrix_homeservers_config = true; for(const Json::Value &known_homeserver : known_homeservers_json) { if(!known_homeserver.isString()) { fprintf(stderr, "Warning: matrix.known_homeservers config contains non string value\n"); @@ -211,9 +233,28 @@ namespace QuickMedia { } } - if(!has_known_homeservers_config) + if(!has_known_matrix_homeservers_config) matrix_known_homeservers_fallback(); + bool has_known_peertube_homeservers_config = false; + const Json::Value &peertube_json = json_root["peertube"]; + if(peertube_json.isObject()) { + const Json::Value &known_instances_json = peertube_json["known_instances"]; + if(known_instances_json.isArray()) { + has_known_peertube_homeservers_config = true; + for(const Json::Value &known_instance : known_instances_json) { + if(!known_instance.isString()) { + fprintf(stderr, "Warning: peertube.known_instances config contains non string value\n"); + continue; + } + config->peertube.known_instances.push_back(known_instance.asString()); + } + } + } + + if(!has_known_peertube_homeservers_config) + peertube_known_instances_fallback(); + get_json_value(json_root, "use_system_fonts", config->use_system_fonts); get_json_value(json_root, "use_system_mpv_config", config->use_system_mpv_config); get_json_value(json_root, "enable_shaders", config->enable_shaders); diff --git a/src/plugins/Peertube.cpp b/src/plugins/Peertube.cpp index 4fb2ac4..6d55e16 100644 --- a/src/plugins/Peertube.cpp +++ b/src/plugins/Peertube.cpp @@ -3,6 +3,7 @@ #include "../../include/Notification.hpp" #include "../../include/Utils.hpp" #include "../../include/StringUtils.hpp" +#include "../../include/Config.hpp" #include namespace QuickMedia { @@ -27,23 +28,19 @@ namespace QuickMedia { } PluginResult PeertubeInstanceSelectionPage::lazy_fetch(BodyItems &result_items) { - result_items.push_back(create_instance_selection_item("tube.midov.pl", "https://tube.midov.pl")); - result_items.push_back(create_instance_selection_item("videos.lukesmith.xyz", "https://videos.lukesmith.xyz")); - result_items.push_back(create_instance_selection_item("peertube.se", "https://peertube.se")); - result_items.push_back(create_instance_selection_item("bittube.video", "https://bittube.video")); - result_items.push_back(create_instance_selection_item("video.nobodyhasthe.biz", "https://video.nobodyhasthe.biz")); - result_items.push_back(create_instance_selection_item("libre.tube", "https://libre.tube")); - result_items.push_back(create_instance_selection_item("open.tube", "https://open.tube")); - result_items.push_back(create_instance_selection_item("runtube.re", "https://runtube.re")); - result_items.push_back(create_instance_selection_item("tube.kenfm.de", "https://tube.kenfm.de")); - result_items.push_back(create_instance_selection_item("tcode.kenfm.de", "https://tcode.kenfm.de")); - result_items.push_back(create_instance_selection_item("tube.querdenken-711.de", "https://tube.querdenken-711.de")); - result_items.push_back(create_instance_selection_item("peertube.rage.lol", "https://peertube.rage.lol")); - result_items.push_back(create_instance_selection_item("gegenstimme.tv", "https://gegenstimme.tv")); - result_items.push_back(create_instance_selection_item("tv.poa.st", "https://tv.poa.st")); - result_items.push_back(create_instance_selection_item("libre.video", "https://libre.video")); - result_items.push_back(create_instance_selection_item("gorf.tube", "https://gorf.tube")); - result_items.push_back(create_instance_selection_item("neogenesis.tv", "https://neogenesis.tv")); + for(const std::string &known_instance : get_config().peertube.known_instances) { + std::string homeserver_name = known_instance; + if(!homeserver_name.empty() && homeserver_name.back() == '/') + homeserver_name.pop_back(); + + if(string_starts_with(homeserver_name, "http://")) + homeserver_name.erase(homeserver_name.begin(), homeserver_name.begin() + 7); + + if(string_starts_with(homeserver_name, "https://")) + homeserver_name.erase(homeserver_name.begin(), homeserver_name.begin() + 8); + + result_items.push_back(create_instance_selection_item(homeserver_name, known_instance)); + } return PluginResult::OK; } -- cgit v1.2.3