aboutsummaryrefslogtreecommitdiff
path: root/video_player/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2025-06-08 12:20:13 +0200
committerdec05eba <dec05eba@protonmail.com>2025-06-08 12:20:13 +0200
commitc5dec7a56157c71d124dafe191acfe95aa0fd4af (patch)
tree7ef0752d632221a4ef19ae23cc60fbb4265a0567 /video_player/src
parentc71a676edf4ccc583652e1f31c571f3cd898d60e (diff)
Add --theme option, system_mpv_profile config and press g in matrix to start /encrypt chat immediately
Diffstat (limited to 'video_player/src')
-rw-r--r--video_player/src/main.cpp38
1 files changed, 29 insertions, 9 deletions
diff --git a/video_player/src/main.cpp b/video_player/src/main.cpp
index e2a8629..15092d9 100644
--- a/video_player/src/main.cpp
+++ b/video_player/src/main.cpp
@@ -307,21 +307,27 @@ static bool string_looks_like_double(const char *str, size_t size) {
return true;
}
-static void mpv_set_before_init_options(mpv_handle *mpv_ctx, const Args &args) {
+static void set_mpv_properties(mpv_handle *mpv_ctx, const MpvProperty &property, bool is_string_property) {
long value_long = 0;
double value_double = 0;
+ if(!is_string_property && string_looks_like_int(property.value.c_str(), property.value.size()) && string_to_long(property.value.c_str(), value_long))
+ check_error(mpv_set_option(mpv_ctx, property.key.c_str(), MPV_FORMAT_INT64, &value_long), property.key.c_str());
+ else if(!is_string_property && string_looks_like_double(property.value.c_str(), property.value.size()) && string_to_double(property.value.c_str(), value_double))
+ check_error(mpv_set_option(mpv_ctx, property.key.c_str(), MPV_FORMAT_DOUBLE, &value_double), property.key.c_str());
+ else
+ check_error(mpv_set_option_string(mpv_ctx, property.key.c_str(), property.value.c_str()), property.key.c_str());
+}
- std::set<std::string> known_string_properties = { "start", "force-media-title" };
+static void mpv_set_before_init_options(mpv_handle *mpv_ctx, const Args &args) {
+ const std::set<std::string> known_string_properties = { "start", "force-media-title" };
+ const std::set<std::string> properties_to_ignore = { "profile" };
for(const MpvProperty &property : args.mpv_properties) {
- const bool is_string_property = known_string_properties.find(property.key) != known_string_properties.end();
+ if(properties_to_ignore.find(property.key) != properties_to_ignore.end())
+ continue;
- if(!is_string_property && string_looks_like_int(property.value.c_str(), property.value.size()) && string_to_long(property.value.c_str(), value_long))
- check_error(mpv_set_option(mpv_ctx, property.key.c_str(), MPV_FORMAT_INT64, &value_long), property.key.c_str());
- else if(!is_string_property && string_looks_like_double(property.value.c_str(), property.value.size()) && string_to_double(property.value.c_str(), value_double))
- check_error(mpv_set_option(mpv_ctx, property.key.c_str(), MPV_FORMAT_DOUBLE, &value_double), property.key.c_str());
- else
- check_error(mpv_set_option_string(mpv_ctx, property.key.c_str(), property.value.c_str()), property.key.c_str());
+ const bool is_string_property = known_string_properties.find(property.key) != known_string_properties.end();
+ set_mpv_properties(mpv_ctx, property, is_string_property);
}
if(args.audio_file) {
@@ -341,6 +347,19 @@ static void mpv_set_before_init_options(mpv_handle *mpv_ctx, const Args &args) {
}
}
+static void mpv_set_after_init_options(mpv_handle *mpv_ctx, const Args &args) {
+ const std::set<std::string> known_string_properties = { "profile" };
+ const std::set<std::string> properties_to_include = { "profile" };
+
+ for(const MpvProperty &property : args.mpv_properties) {
+ if(properties_to_include.find(property.key) == properties_to_include.end())
+ continue;
+
+ const bool is_string_property = known_string_properties.find(property.key) != known_string_properties.end();
+ set_mpv_properties(mpv_ctx, property, is_string_property);
+ }
+}
+
#define READ_END 0
#define WRITE_END 1
@@ -630,6 +649,7 @@ int main(int argc, char **argv) {
mpv_set_before_init_options(mpv_ctx, args);
check_error(mpv_initialize(mpv_ctx), "mpv_initialize");
+ mpv_set_after_init_options(mpv_ctx, args);
check_error(mpv_stream_cb_add_ro(mpv_ctx, "qm-yt", nullptr, open_fn), "mpv_stream_cb_add_ro");
check_error(mpv_observe_property(mpv_ctx, 0, "idle-active", MPV_FORMAT_FLAG), "observe idle-active");