aboutsummaryrefslogtreecommitdiff
path: root/video_player
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-03-08 16:39:55 +0100
committerdec05eba <dec05eba@protonmail.com>2022-03-08 16:39:55 +0100
commita26d0fcc0a30a28ce0e458ea275fc0787c693bc6 (patch)
treeffe2212b81d9fdc93b49383c102e7c0ece0d225a /video_player
parent21c50903a68c253fa5fcb9ed5ac8ba5abb1142b9 (diff)
Save youtube watch progress and resume next time the video is played
Diffstat (limited to 'video_player')
-rw-r--r--video_player/README.md27
-rw-r--r--video_player/src/main.cpp19
2 files changed, 32 insertions, 14 deletions
diff --git a/video_player/README.md b/video_player/README.md
index 0d0adeb..247edff 100644
--- a/video_player/README.md
+++ b/video_player/README.md
@@ -19,12 +19,21 @@ Return seeking position in file in seconds
"request_id": 232, // Optional. Its provided if request_id was provided in the request
}
```
-### response on error
+## duration
+Return duration of file in seconds
+### request
```
{
- "status": "error",
- "message": "error message",
- "request_id": 233 // Optional. Its provided if request_id was provided in the request
+ "command": "duration",
+ "request_id": 232 // Optional
+}
+```
+### response on success
+```
+{
+ "status": "success",
+ "data": 112.432,
+ "request_id": 232, // Optional. Its provided if request_id was provided in the request
}
```
## sub-add
@@ -48,14 +57,6 @@ Add a subtitle file/url that is loaded asynchronously
"request_id": 233 // Optional. Its provided if request_id was provided in the request
}
```
-### response on error
-```
-{
- "status": "error",
- "message": "error message",
- "request_id": 233 // Optional. Its provided if request_id was provided in the request
-}
-```
## cycle-fullscreen
Return seeking position in file in seconds
### request
@@ -72,7 +73,7 @@ Return seeking position in file in seconds
"request_id": 232, // Optional. Its provided if request_id was provided in the request
}
```
-### response on error
+## Response on error in every command
```
{
"status": "error",
diff --git a/video_player/src/main.cpp b/video_player/src/main.cpp
index 33c4d96..91f2d4b 100644
--- a/video_player/src/main.cpp
+++ b/video_player/src/main.cpp
@@ -46,6 +46,21 @@ static Json::Value handle_json_command_time_pos(mpv_handle *mpv_ctx) {
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);
+
+ Json::Value response_json(Json::objectValue);
+ if(res < 0) {
+ response_json["status"] = "error";
+ response_json["message"] = mpv_error_string(res);
+ } else {
+ response_json["status"] = "success";
+ response_json["data"] = duration;
+ }
+ return response_json;
+}
+
static Json::Value handle_json_command_sub_add(mpv_handle *mpv_ctx, const Json::Value &json_root) {
Json::Value response_json(Json::objectValue);
@@ -163,6 +178,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(), "duration") == 0) {
+ response_json = handle_json_command_duration(mpv_ctx);
} else if(strcmp(command_json.asCString(), "sub-add") == 0) {
response_json = handle_json_command_sub_add(mpv_ctx, json_root);
} else if(strcmp(command_json.asCString(), "cycle-fullscreen") == 0) {
@@ -170,7 +187,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, sub-add or cycle-fullscreen";
+ response_json["message"] = "invalid command " + command_json.asString() + ", expected time-pos, duration, sub-add or cycle-fullscreen";
}
if(request_id)