aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index c57540c..ac236b4 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3252,6 +3252,17 @@ namespace QuickMedia {
return url.find("yt_live_broadcast") != std::string::npos || url.find("manifest/") != std::string::npos;
}
+ static bool find_sponsor_segment_end(const std::vector<SponsorSegment> &sponsor_segments, double current_time_seconds, double &end_time_seconds) {
+ // TODO: Optimize
+ for(const SponsorSegment &sponsor_segments : sponsor_segments) {
+ if(current_time_seconds >= sponsor_segments.start_seconds && current_time_seconds <= sponsor_segments.end_seconds) {
+ end_time_seconds = sponsor_segments.end_seconds;
+ return true;
+ }
+ }
+ return false;
+ }
+
int Program::video_get_max_height() {
if(video_max_height > 0)
return video_max_height;
@@ -3326,13 +3337,15 @@ namespace QuickMedia {
update_duration = false;
successfully_fetched_video_duration = false;
double file_duration = 0.0;
- video_player->get_duration_in_file(&file_duration);
+ video_player->get_duration(&file_duration);
video_info.duration = std::max(video_info.duration, file_duration);
if(video_info.duration > 0.001)
successfully_fetched_video_duration = true;
}
};
+ const bool use_sponsorblock = get_config().youtube.sponsorblock.enable;
+ mgl::Clock sponsorblock_update_clock;
auto update_time_pos_handler = [&](bool force) {
if(!video_player)
return;
@@ -3356,6 +3369,18 @@ namespace QuickMedia {
video_page->set_watch_progress(video_time_pos, video_info.duration);
}
}
+
+ if(use_sponsorblock && (force || sponsorblock_update_clock.get_elapsed_time_seconds() >= 1.0)) {
+ sponsorblock_update_clock.restart();
+ double time_pos = 0.0;
+ if(video_player->get_time_in_file(&time_pos) == VideoPlayer::Error::OK) {
+ double sponsor_end = 0.0;
+ if(find_sponsor_segment_end(video_info.sponsor_segments, time_pos, sponsor_end)) {
+ fprintf(stderr, "Info: skipped sponsor segment\n");
+ video_player->set_time_in_file(sponsor_end);
+ }
+ }
+ }
update_video_duration_handler();
};
@@ -3492,7 +3517,7 @@ namespace QuickMedia {
startup_args.use_youtube_dl = use_youtube_dl && !video_page->is_local();
startup_args.title = video_title;
startup_args.start_time = start_time;
- startup_args.chapters = std::move(video_info.chapters);
+ startup_args.chapters = video_info.chapters;
startup_args.plugin_name = plugin_name;
startup_args.cache_on_disk = !video_page->is_local();
startup_args.referer = video_info.referer;