aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-10-25 06:46:11 +0200
committerdec05eba <dec05eba@protonmail.com>2022-10-25 06:58:01 +0200
commit162502874dc266bce6a73d5cd70e06c3829ead28 (patch)
treed49bda878ef7c91dd2b776fbecec66bfee19bc4d
parent765a45b84eedaf27a69776b9be3852ea26e9b176 (diff)
Properly update watch progress at end of file
-rw-r--r--example-config.json4
-rw-r--r--src/QuickMedia.cpp82
-rw-r--r--src/main.cpp1
3 files changed, 59 insertions, 28 deletions
diff --git a/example-config.json b/example-config.json
index 810842f..56e7279 100644
--- a/example-config.json
+++ b/example-config.json
@@ -19,7 +19,7 @@
"font_size": 16
},
"video": {
- "max_height": 2160
+ "max_height": 0
},
"local_manga": {
"directory": "",
@@ -80,4 +80,4 @@
"scale": 1.0,
"font_scale": 1.0,
"spacing_scale": 1.0
-} \ No newline at end of file
+}
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 4b441ec..3e41899 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3232,6 +3232,44 @@ namespace QuickMedia {
std::string audio_url;
bool has_embedded_audio = true;
+ auto update_video_duration_handler = [&]() {
+ if(!video_player)
+ return;
+
+ if(update_duration) {
+ update_duration = false;
+ successfully_fetched_video_duration = true;
+ double file_duration = 0.0;
+ video_player->get_duration_in_file(&file_duration);
+ video_info.duration = std::max(video_info.duration, file_duration);
+ if(video_info.duration > 0.001)//
+ successfully_fetched_video_duration = true;//
+ }
+ };
+
+ auto update_time_pos_handler = [&](bool force) {
+ if(!video_player)
+ return;
+
+ if(force) {
+ video_time_pos_clock.restart();
+ update_time_pos = true;
+ }
+
+ if(video_time_pos_clock.get_elapsed_time_seconds() >= 5.0) {
+ video_time_pos_clock.restart();
+ update_time_pos = true;
+ }
+
+ if(update_time_pos) {
+ update_time_pos = false;
+ if(video_player->get_time_in_file(&video_time_pos) == VideoPlayer::Error::OK)
+ successfully_fetched_time_pos = true;
+ }
+
+ update_video_duration_handler();
+ };
+
auto load_video_error_check = [&](std::string start_time = "", bool reuse_media_source = false) mutable {
video_player.reset();
video_info.channel_url.clear();
@@ -3240,6 +3278,9 @@ namespace QuickMedia {
successfully_fetched_time_pos = false;
video_player_window = None;
video_info.duration = 0.0;
+ video_time_pos_clock.restart();
+ update_time_pos = false;
+ video_time_pos = 0.0;
bool is_audio_only = no_video;
const int video_max_height = video_get_max_height();
@@ -3346,6 +3387,8 @@ namespace QuickMedia {
const bool is_resume_go_back = !start_time.empty();
if(start_time.empty())
start_time = video_page->get_url_timestamp();
+
+ fprintf(stderr, "start time: %s\n", start_time.c_str());
watched_videos.insert(video_page->get_url());
// TODO: Sync sequences
@@ -3456,6 +3499,9 @@ namespace QuickMedia {
update_time_pos = true;
} else if(strcmp(event_name, "fullscreen") == 0 && args.size() == 1) {
window_set_fullscreen(disp, window.get_system_handle(), args[0] == "yes" ? WindowFullscreenState::SET : WindowFullscreenState::UNSET);
+ } else if(strcmp(event_name, "end-file") == 0) {
+ if(successfully_fetched_time_pos && successfully_fetched_video_duration)
+ video_page->set_watch_progress(video_time_pos, video_info.duration);
}
//fprintf(stderr, "event name: %s\n", event_name);
@@ -3494,7 +3540,7 @@ namespace QuickMedia {
} else if(event.type == mgl::Event::Resized) {
window_size.x = event.size.width;
window_size.y = event.size.height;
- } else if(event.type == mgl::Event::KeyPressed && (event.key.code == mgl::Keyboard::Escape || event.key.code == mgl::Keyboard::Q || event.key.code == mgl::Keyboard::Backspace)) {
+ } else if(event.type == mgl::Event::KeyPressed && (event.key.code == mgl::Keyboard::Escape || event.key.code == mgl::Keyboard::Backspace)) {
// To be able to close the video player while the video is loading
if(window_is_fullscreen(disp, window.get_system_handle())) {
if(video_player && video_player_window && event.key.code != mgl::Keyboard::Escape)
@@ -3503,6 +3549,9 @@ namespace QuickMedia {
current_page = previous_page;
go_to_previous_page = true;
}
+ } else if(event.type == mgl::Event::KeyPressed && event.key.code == mgl::Keyboard::Q) {
+ current_page = previous_page;
+ go_to_previous_page = true;
} else if(event.type == mgl::Event::KeyPressed && event.key.code == mgl::Keyboard::C && event.key.control && !video_page->is_local()) {
save_video_url_to_clipboard();
} else if(event.type == mgl::Event::KeyPressed && event.key.code == mgl::Keyboard::F5 && !video_page->is_local()) {
@@ -3538,8 +3587,10 @@ namespace QuickMedia {
KeySym pressed_keysym = XKeycodeToKeysym(disp, xev.xkey.keycode, 0);
#pragma GCC diagnostic pop
bool pressing_ctrl = (CLEANMASK(xev.xkey.state) == ControlMask);
- if(pressed_keysym == XK_q && pressing_ctrl) {
- window.close();
+ if(pressed_keysym == XK_q) {
+ current_page = previous_page;
+ go_to_previous_page = true;
+ break;
} else if(pressed_keysym == XK_Escape || pressed_keysym == XK_q || pressed_keysym == XK_BackSpace) {
if(window_is_fullscreen(disp, window.get_system_handle())) {
if(pressed_keysym != XK_Escape)
@@ -3600,6 +3651,7 @@ namespace QuickMedia {
show_video_player_window(video_player_window);
show_notification("QuickMedia", "Failed to get related pages", Urgency::CRITICAL);
} else if(related_pages_result == TaskResult::TRUE && !related_pages.empty()) {
+ update_time_pos_handler(true);
if(successfully_fetched_time_pos && successfully_fetched_video_duration)
video_page->set_watch_progress(video_time_pos, video_info.duration);
@@ -3776,28 +3828,8 @@ namespace QuickMedia {
continue;
}
- if(video_player) {
- if(video_time_pos_clock.get_elapsed_time_seconds() >= 5.0) {
- video_time_pos_clock.restart();
- update_time_pos = true;
- }
-
- if(update_time_pos) {
- update_time_pos = false;
- if(video_player->get_time_in_file(&video_time_pos) == VideoPlayer::Error::OK)
- successfully_fetched_time_pos = true;
- }
-
- if(update_duration) {
- update_duration = false;
- successfully_fetched_video_duration = true;
- double file_duration = 0.0;
- video_player->get_duration_in_file(&file_duration);
- video_info.duration = std::max(video_info.duration, file_duration);
- if(video_info.duration > 0.001)
- successfully_fetched_video_duration = true;
- }
- }
+ if(video_player)
+ update_time_pos_handler(false);
if(video_player_window) {
if(!cursor_visible) {
diff --git a/src/main.cpp b/src/main.cpp
index f0dca82..52cb374 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3,7 +3,6 @@
#include <X11/Xlib.h>
int main(int argc, char **argv) {
- setenv("__GL_THREADED_OPTIMIZATIONS", "0", 1);
XInitThreads();
setlocale(LC_ALL, "C"); // Sigh... stupid C
QuickMedia::Program program;