diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-04-03 20:49:37 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-04-03 20:49:37 +0200 |
commit | 4c37a5463c23fcdb165228aae096f2bb0a25b98b (patch) | |
tree | 6b863d102551e1d19e93d0864b3f3598f86724b4 /video_player | |
parent | e8cf95fd56bb6cc16f937d06c3554260fd789a92 (diff) |
Autoskip youtube sponsors
Diffstat (limited to 'video_player')
-rw-r--r-- | video_player/src/main.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/video_player/src/main.cpp b/video_player/src/main.cpp index 0342b45..54b5bb4 100644 --- a/video_player/src/main.cpp +++ b/video_player/src/main.cpp @@ -51,6 +51,27 @@ static Json::Value handle_json_command_time_pos(mpv_handle *mpv_ctx) { return response_json; } +static Json::Value handle_json_command_set_time_pos(mpv_handle *mpv_ctx, const Json::Value &json_root) { + Json::Value response_json(Json::objectValue); + + const Json::Value &data_json = json_root["data"]; + if(!data_json.isDouble()) { + response_json["status"] = "error"; + response_json["message"] = "expected \"data\" to be a double"; + return response_json; + } + + double time_pos = data_json.asDouble(); + const int res = mpv_set_property_async(mpv_ctx, 0, "time-pos", MPV_FORMAT_DOUBLE, &time_pos); + if(res < 0) { + response_json["status"] = "error"; + response_json["message"] = std::string("set-time-pos: ") + mpv_error_string(res); + } else { + response_json["status"] = "success"; + } + return response_json; +} + static Json::Value handle_json_command_duration(mpv_handle *mpv_ctx) { double duration = 0.0; const int res = mpv_get_property(mpv_ctx, "duration", MPV_FORMAT_DOUBLE, &duration); @@ -183,6 +204,8 @@ static void handle_json_command(mpv_handle *mpv_ctx, const Json::Value &json_roo Json::Value response_json; if(strcmp(command_json.asCString(), "time-pos") == 0) { response_json = handle_json_command_time_pos(mpv_ctx); + } else if(strcmp(command_json.asCString(), "set-time-pos") == 0) { + response_json = handle_json_command_set_time_pos(mpv_ctx, json_root); } else if(strcmp(command_json.asCString(), "duration") == 0) { response_json = handle_json_command_duration(mpv_ctx); } else if(strcmp(command_json.asCString(), "sub-add") == 0) { @@ -192,7 +215,7 @@ static void handle_json_command(mpv_handle *mpv_ctx, const Json::Value &json_roo } else { response_json = Json::Value(Json::objectValue); response_json["status"] = "error"; - response_json["message"] = "invalid command " + command_json.asString() + ", expected time-pos, duration, sub-add or cycle-fullscreen"; + response_json["message"] = "invalid command " + command_json.asString() + ", expected time-pos, set-time-pos, duration, sub-add or cycle-fullscreen"; } if(request_id) |