aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-09-08 20:31:30 +0200
committerdec05eba <dec05eba@protonmail.com>2022-09-08 20:31:30 +0200
commitd0dda48e791e6f08f6be3936623a2c305caacb3c (patch)
tree0e1289c3034ad30235f84df54a4884661aee0c23 /src
parent215ac920166087ffcf917c293caf6497adf50c3d (diff)
Peertube: load known instances from config file
Diffstat (limited to 'src')
-rw-r--r--src/Config.cpp47
-rw-r--r--src/plugins/Peertube.cpp31
2 files changed, 58 insertions, 20 deletions
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 <json/value.h>
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;
}