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 /src/plugins | |
parent | e8cf95fd56bb6cc16f937d06c3554260fd789a92 (diff) |
Autoskip youtube sponsors
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Youtube.cpp | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 482843e..bcb6cf6 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -3065,7 +3065,7 @@ namespace QuickMedia { video_details.duration = 0.0; } - static void sponsorblock_add_chapters(Page *page, const std::string &url, int min_votes, std::vector<MediaChapter> &chapters) { + static void sponsorblock_add_chapters(Page *page, const std::string &url, int min_votes, std::vector<SponsorSegment> &sponsor_segments) { std::string video_id; if(!youtube_url_extract_id(url, video_id)) { fprintf(stderr, "Failed to extract youtube id from %s\n", url.c_str()); @@ -3103,19 +3103,11 @@ namespace QuickMedia { if(votes_json.asInt() < min_votes) continue; - MediaChapter ad_start; - ad_start.start_seconds = segment_json[0].asDouble(); - ad_start.title = "Ad start"; - chapters.push_back(std::move(ad_start)); - - MediaChapter ad_end; - ad_end.start_seconds = segment_json[1].asDouble(); - ad_end.title = "Ad end"; - chapters.push_back(std::move(ad_end)); + sponsor_segments.push_back({segment_json[0].asDouble(), segment_json[1].asDouble()}); } } - PluginResult YoutubeVideoPage::parse_video_response(const Json::Value &json_root, std::string &title, std::string &channel_url, std::vector<MediaChapter> &chapters, std::string &err_str) { + PluginResult YoutubeVideoPage::parse_video_response(const Json::Value &json_root, std::string &title, std::string &channel_url, std::vector<MediaChapter> &chapters, std::vector<SponsorSegment> &sponsor_segments, std::string &err_str) { livestream_url.clear(); video_formats.clear(); audio_formats.clear(); @@ -3123,6 +3115,7 @@ namespace QuickMedia { title.clear(); channel_url.clear(); chapters.clear(); + sponsor_segments.clear(); youtube_dl_video_fallback_url.clear(); youtube_dl_audio_fallback_url.clear(); video_details_clear(video_details); @@ -3202,7 +3195,7 @@ namespace QuickMedia { fprintf(stderr, "Failed to load youtube video, trying with yt-dlp instead\n"); if(program->youtube_dl_extract_url(url, youtube_dl_video_fallback_url, youtube_dl_audio_fallback_url)) { if(get_config().youtube.sponsorblock.enable) - sponsorblock_add_chapters(this, url, get_config().youtube.sponsorblock.min_votes, chapters); + sponsorblock_add_chapters(this, url, get_config().youtube.sponsorblock.min_votes, sponsor_segments); use_youtube_dl_fallback = true; return PluginResult::OK; } else { @@ -3246,7 +3239,7 @@ namespace QuickMedia { }); if(get_config().youtube.sponsorblock.enable) - sponsorblock_add_chapters(this, url, get_config().youtube.sponsorblock.min_votes, chapters); + sponsorblock_add_chapters(this, url, get_config().youtube.sponsorblock.min_votes, sponsor_segments); return PluginResult::OK; } @@ -3290,7 +3283,7 @@ R"END( if(download_result != DownloadResult::OK) continue; - PluginResult result = parse_video_response(json_root, video_info.title, video_info.channel_url, video_info.chapters, err_str); + PluginResult result = parse_video_response(json_root, video_info.title, video_info.channel_url, video_info.chapters, video_info.sponsor_segments, err_str); if(result == PluginResult::OK) { err_str.clear(); video_info.duration = video_details.duration; |