From a2c36449b0bf24da597688bcffb71d02ba19f34f Mon Sep 17 00:00:00 2001 From: Ming Di Leom <43627182+curbengh@users.noreply.github.com> Date: Sat, 30 Aug 2025 01:57:18 +0000 Subject: [PATCH] feat(sponsorblock): add "hook" category https://github.com/ajayyy/SponsorBlock/commit/f4d25588564e216ad109cfe0253640af75d7a8de --- .../sponsorblock/SponsorBlockFragment.java | 2 + .../org/schabi/newpipe/player/Player.java | 3 ++ ...ponsorBlockCategoriesSettingsFragment.java | 9 +++++ .../schabi/newpipe/util/ExtractorHelper.java | 3 ++ .../newpipe/util/SponsorBlockHelper.java | 11 ++++++ app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/settings_keys.xml | 5 ++- app/src/main/res/values/strings.xml | 5 ++- .../xml/sponsor_block_category_settings.xml | 38 ++++++++++++++++++- 9 files changed, 74 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/sponsorblock/SponsorBlockFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/sponsorblock/SponsorBlockFragment.java index c4aaba710a..9962189bec 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/sponsorblock/SponsorBlockFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/sponsorblock/SponsorBlockFragment.java @@ -330,6 +330,8 @@ private void doSubmitPendingSegment() { context, SponsorBlockCategory.NON_MUSIC), SponsorBlockHelper.convertCategoryToFriendlyName( context, SponsorBlockCategory.PREVIEW), + SponsorBlockHelper.convertCategoryToFriendlyName( + context, SponsorBlockCategory.HOOK), SponsorBlockHelper.convertCategoryToFriendlyName( context, SponsorBlockCategory.FILLER) }, (dialog, which) -> { diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index 5d01dfdcd6..25af24d0d5 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -2622,6 +2622,9 @@ private SponsorBlockSecondaryMode getSecondaryMode(final SponsorBlockSegment seg case PREVIEW -> prefs.getString( context.getString(R.string.sponsor_block_category_preview_mode_key), defaultValue); + case HOOK -> prefs.getString( + context.getString(R.string.sponsor_block_category_hook_mode_key), + defaultValue); case FILLER -> prefs.getString( context.getString(R.string.sponsor_block_category_filler_mode_key), defaultValue); diff --git a/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockCategoriesSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockCategoriesSettingsFragment.java index 20cd7ceb42..de5348febd 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockCategoriesSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockCategoriesSettingsFragment.java @@ -42,6 +42,8 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro findPreference(getString(R.string.sponsor_block_category_non_music_key)); final SwitchPreference previewCategoryPreference = findPreference(getString(R.string.sponsor_block_category_preview_key)); + final SwitchPreference hookCategoryPreference = + findPreference(getString(R.string.sponsor_block_category_hook_key)); final SwitchPreference fillerCategoryPreference = findPreference(getString(R.string.sponsor_block_category_filler_key)); @@ -53,6 +55,7 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro selfPromoCategoryPreference.setChecked(true); nonMusicCategoryPreference.setChecked(true); previewCategoryPreference.setChecked(true); + hookCategoryPreference.setChecked(true); fillerCategoryPreference.setChecked(true); return true; @@ -77,6 +80,8 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro findPreference(getString(R.string.sponsor_block_category_non_music_key)); final SwitchPreference previewCategoryPreference = findPreference(getString(R.string.sponsor_block_category_preview_key)); + final SwitchPreference hookCategoryPreference = + findPreference(getString(R.string.sponsor_block_category_hook_key)); final SwitchPreference fillerCategoryPreference = findPreference(getString(R.string.sponsor_block_category_filler_key)); @@ -88,6 +93,7 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro selfPromoCategoryPreference.setChecked(false); nonMusicCategoryPreference.setChecked(false); previewCategoryPreference.setChecked(false); + hookCategoryPreference.setChecked(false); fillerCategoryPreference.setChecked(false); return true; @@ -128,6 +134,9 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro setColorPreference(editor, R.string.sponsor_block_category_preview_color_key, R.color.preview_segment); + setColorPreference(editor, + R.string.sponsor_block_category_hook_color_key, + R.color.hook_segment); setColorPreference(editor, R.string.sponsor_block_category_filler_color_key, R.color.filler_segment); diff --git a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java index 0d11622212..e91602c5f6 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java @@ -423,6 +423,9 @@ private static String capitalizeIfAllUppercase(final String text) { result.includePreviewCategory = prefs.getBoolean(context .getString(R.string.sponsor_block_category_preview_key), false); + result.includeHookCategory = + prefs.getBoolean(context + .getString(R.string.sponsor_block_category_hook_key), false); result.includeFillerCategory = prefs.getBoolean(context .getString(R.string.sponsor_block_category_filler_key), false); diff --git a/app/src/main/java/org/schabi/newpipe/util/SponsorBlockHelper.java b/app/src/main/java/org/schabi/newpipe/util/SponsorBlockHelper.java index 77b7ebf68c..643d2c88d8 100644 --- a/app/src/main/java/org/schabi/newpipe/util/SponsorBlockHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/SponsorBlockHelper.java @@ -84,6 +84,13 @@ public static Integer convertCategoryToColor( ? context.getResources().getColor(R.color.preview_segment) : Color.parseColor(colorStr); } + case HOOK -> { + key = context.getString(R.string.sponsor_block_category_hook_color_key); + colorStr = prefs.getString(key, null); + return colorStr == null + ? context.getResources().getColor(R.color.hook_segment) + : Color.parseColor(colorStr); + } case FILLER -> { key = context.getString(R.string.sponsor_block_category_filler_color_key); colorStr = prefs.getString(key, null); @@ -156,6 +163,8 @@ public static String convertCategoryToFriendlyName(final Context context, R.string.sponsor_block_category_non_music); case PREVIEW -> context.getString( R.string.sponsor_block_category_preview); + case HOOK -> context.getString( + R.string.sponsor_block_category_hook); case FILLER -> context.getString( R.string.sponsor_block_category_filler); case PENDING -> context.getString( @@ -181,6 +190,8 @@ public static String convertCategoryToSkipMessage(final Context context, .getString(R.string.sponsor_block_skip_non_music_toast); case PREVIEW -> context .getString(R.string.sponsor_block_skip_preview_toast); + case HOOK -> context + .getString(R.string.sponsor_block_skip_hook_toast); case FILLER -> context .getString(R.string.sponsor_block_skip_filler_toast); case PENDING -> context diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index cc9aa955d2..1d3465893d 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -93,6 +93,7 @@ #ffff00 #ff9900 #008fd6 + #395699 #7300ff #ffffff diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index db69deadd3..8319d1018b 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -265,7 +265,7 @@ 5 10 - + middle_gesture_area_width .3333 @@ -1594,6 +1594,9 @@ sponsor_block_category_preview sponsor_block_category_preview_mode sponsor_block_category_preview_color + sponsor_block_category_hook + sponsor_block_category_hook_mode + sponsor_block_category_hook_color sponsor_block_category_filler sponsor_block_category_filler_mode sponsor_block_category_filler_color diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 699d8e6d76..fc231ed195 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -892,7 +892,8 @@ Unpaid/Self Promotion Music: Non-Music Section Preview/Recap - Filler Tangent/Jokes + Hook/Greetings + Tangent/Jokes Pending View Website View the official SponsorBlock website. @@ -916,6 +917,7 @@ Skipped unpaid/self promo Skipped non-music Skipped preview/recap + Skipped hook Skipped filler Skipped pending segment Toggle skipping sponsors @@ -963,6 +965,7 @@ Similar to "sponsor" except for unpaid or self promotion. This includes sections about merchandise, donations, or information about who they collaborated with. Only for use in music videos. This includes introductions or outros in music videos. Quick recap of previous episodes, or a preview of what\'s coming up later in the current video. Meant for edited together clips, not for spoken summaries. + For narrative hooks that tease upcoming moments in a video, plus dedicated greetings and goodbyes. This is for tangential scenes added only for filler or humor that are not required to understand the main content of the video. Represents a new segment ready to be submitted. Submit diff --git a/app/src/main/res/xml/sponsor_block_category_settings.xml b/app/src/main/res/xml/sponsor_block_category_settings.xml index e9e2fb60f5..5a8529b17d 100644 --- a/app/src/main/res/xml/sponsor_block_category_settings.xml +++ b/app/src/main/res/xml/sponsor_block_category_settings.xml @@ -291,6 +291,42 @@ + + + + + + + + + + + + @@ -343,4 +379,4 @@ android:title="@string/settings_category_sponsor_block_category_color"/> - \ No newline at end of file +