diff --git a/src/sponskrub/methods/chapter.d b/src/sponskrub/methods/chapter.d index 2cfd391..0b2574c 100644 --- a/src/sponskrub/methods/chapter.d +++ b/src/sponskrub/methods/chapter.d @@ -107,7 +107,7 @@ ClipChapterTime[] merge_sponsor_times_with_chapters(ClipTime[] sponsor_times, Ch next_terminal = chapter_times[chapter_index].end; chapter_index++; } - clip_chapters ~= ClipChapterTime(clip_terminal, next_terminal, "", chapter_title); + clip_chapters ~= ClipChapterTime(clip_terminal, next_terminal, Categories.Content, chapter_title); clip_terminal = next_terminal; } } diff --git a/src/sponskrub/methods/cut.d b/src/sponskrub/methods/cut.d index 00e6750..04a1f45 100644 --- a/src/sponskrub/methods/cut.d +++ b/src/sponskrub/methods/cut.d @@ -25,30 +25,15 @@ import std.array; import std.typecons; import sponsorblock; import ffwrap; +import chapter; -ClipTime[] timestamps_to_keep(ClipTime[] sponsor_times, string video_length) { - ClipTime[] clip_times; - sponsor_times.sort!((a, b) => a.start.to!float < b.start.to!float); - - //If the sponsorship is directly at the beginning don't add both content and the sponsor - if (sponsor_times[0].start != "0.000000") { - clip_times ~= ClipTime("0", sponsor_times[0].start, "content"); - } - - - for (auto i = 0; i < sponsor_times.length; i++) { - auto clip_start = ""; - auto clip_end = ""; - clip_start = sponsor_times[i].end; - if (i+1 < sponsor_times.length) { - clip_end = sponsor_times[i+1].start; - } else { - clip_end = video_length; - } - clip_times ~= ClipTime(clip_start, clip_end, "content"); - } - - return clip_times; +ClipTime[] timestamps_to_keep(ClipChapterTime[] chapters) { + //we can redo this so it just filters a bunch of chapter times and includes only content + return chapters + .sort!((a, b) => a.start.to!float < b.start.to!float) + .filter!(chapter => chapter.category == Categories.Content) + .map!(chapter => ClipTime(chapter.start, chapter.end, "")) //we need better types, this shouldn't need a category + .array; } string cut_and_cat_clips_filter(ClipTime[] timestamps, FileCategory category) { diff --git a/src/sponskrub/sponskrub.d b/src/sponskrub/sponskrub.d index e9dac81..6f1e307 100644 --- a/src/sponskrub/sponskrub.d +++ b/src/sponskrub/sponskrub.d @@ -141,28 +141,30 @@ Options: if (sponsor_times.length > 0) { bool ffmpeg_status; + ChapterTime[] chapter_times; + ClipChapterTime[] new_chapter_times; + + chapter_times = get_chapter_times(input_filename); + + if (chapter_times.length == 0) { + chapter_times = [ChapterTime("0", video_length, "sponskrub-content")]; + } + + new_chapter_times = merge_sponsor_times_with_chapters(sponsor_times, chapter_times); + if ("chapter" in parsed_arguments.flag_arguments) { writeln("Marking the shilling..."); - - ChapterTime[] chapter_times; - ClipChapterTime[] new_chapter_times; - - chapter_times = get_chapter_times(input_filename); - if (chapter_times.length == 0) { - chapter_times = [ChapterTime("0", video_length, "sponskrub-content")]; - } - - new_chapter_times = merge_sponsor_times_with_chapters(sponsor_times, chapter_times); - ffmpeg_status = add_ffmpeg_metadata( input_filename, output_filename, generate_chapters_metadata(new_chapter_times) ); } else { - auto content_times = timestamps_to_keep(sponsor_times, video_length); + //using the chapter data also means that in future we could also adjust + //preexisting chapter metadata to remain accurate after the cut writeln("Surgically removing the shilling..."); + auto content_times = timestamps_to_keep(new_chapter_times); ffmpeg_status = run_ffmpeg_filter( input_filename, diff --git a/src/sponskrub/sponsorblock.d b/src/sponskrub/sponsorblock.d index c7ac4ea..2f68644 100644 --- a/src/sponskrub/sponsorblock.d +++ b/src/sponskrub/sponsorblock.d @@ -31,7 +31,9 @@ enum Categories: string { Outro = "outro", Interaction = "interaction", SelfPromo = "selfpromo", - NonMusic = "music_offtopic" + NonMusic = "music_offtopic", + // + Content = "content" } alias ClipTime = Tuple!(string, "start", string, "end", string, "category");