From f0b029df06f9387d14fa79781c34d1da7f99e0f9 Mon Sep 17 00:00:00 2001 From: polymorphicshade Date: Sun, 19 Jul 2020 22:38:07 -0600 Subject: [PATCH] SponsorBlock: Now requires the API url to be set Added/rearranged/renamed some SponsorBlock settings. Now the API Url setting must be set for SponsorBlock to work. --- .../org/schabi/newpipe/player/BasePlayer.java | 22 +++++---- .../settings/ContentSettingsFragment.java | 12 ++++- app/src/main/res/values/settings_keys.xml | 5 +- app/src/main/res/values/strings.xml | 12 +++-- app/src/main/res/xml/content_settings.xml | 46 +++++++++++-------- 5 files changed, 59 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index 6ecb39393..e9ad75cb4 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -1048,15 +1048,19 @@ public abstract class BasePlayer implements initThumbnail(info.getThumbnailUrl()); registerView(); - if (info.getUrl().startsWith("https://www.youtube.com") - && mPrefs.getBoolean(context.getString(R.string.sponsorblock_enable), false)) { - try { - sponsorTimeInfo = new SponsorBlockApiTask( - mPrefs.getString(context.getString(R.string.sponsorblock_custom_api_url), - "https://sponsor.ajay.app/api/")) - .getYouTubeVideoSponsorTimes(info.getId()); - } catch (Exception e) { - Log.e("SPONSOR_BLOCK", "Error getting YouTube video sponsor times.", e); + if (info.getUrl().startsWith("https://www.youtube.com")) { + String apiUrl = mPrefs + .getString(context.getString(R.string.sponsorblock_api_url), null); + boolean isSponsorBlockEnabled = mPrefs + .getBoolean(context.getString(R.string.sponsorblock_enable), false); + + if (apiUrl != null && !apiUrl.isEmpty() && isSponsorBlockEnabled) { + try { + sponsorTimeInfo = new SponsorBlockApiTask(apiUrl) + .getYouTubeVideoSponsorTimes(info.getId()); + } catch (Exception e) { + Log.e("SPONSOR_BLOCK", "Error getting YouTube video sponsor times.", e); + } } } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 95bc154a4..45cc84d2c 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -140,9 +140,17 @@ public class ContentSettingsFragment extends BasePreferenceFragment { return true; }); - Preference sponsorblockPrivacyPreference = + Preference sponsorBlockWebsitePreference = + findPreference(getString(R.string.sponsorblock_home_page)); + sponsorBlockWebsitePreference.setOnPreferenceClickListener((Preference p) -> { + Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://sponsor.ajay.app/")); + startActivity(i); + return true; + }); + + Preference sponsorBlockPrivacyPreference = findPreference(getString(R.string.sponsorblock_privacy)); - sponsorblockPrivacyPreference.setOnPreferenceClickListener((Preference p) -> { + sponsorBlockPrivacyPreference.setOnPreferenceClickListener((Preference p) -> { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse( "https://gist.github.com/ajayyy/aa9f8ded2b573d4f73a3ffa0ef74f796" diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 468b08095..be0123f84 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -223,8 +223,9 @@ downloads_storage_ask storage_use_saf - skip_sponsors - sponsorblock_custom_api_url + sponsorblock_home_page + sponsorblock_enable + sponsorblock_custom_api_url sponsorblock_notifications sponsorblock_privacy diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1c5320c55..5e722f739 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -129,7 +129,7 @@ Other Debug Updates - SponsorBlock Beta (Third party service) + SponsorBlock (beta, third party service) Playing in background Playing in popup mode Queued on background player @@ -661,12 +661,14 @@ By %s Playlist page + View Website + View the official SponsorBlock website. Skip Sponsors - Use the SponsorBlock API to automatically skip sponsors in videos. - Custom API Url - The url to use when querying the SponsorBlock API. Leave empty to use the default. + Use the SponsorBlock API to automatically skip sponsors in videos. This currently only works for YouTube videos. + API Url + The url to use when querying the SponsorBlock API. This must be set for SponsorBlock to work. Notify when sponsors are skipped Show a toast notification when a sponsor is automatically skipped. View Privacy Policy - View the privacy policy of the SponsorBlock service. + View SponsorBlock\'s privacy policy. \ No newline at end of file diff --git a/app/src/main/res/xml/content_settings.xml b/app/src/main/res/xml/content_settings.xml index e3bddcc24..8efd57274 100644 --- a/app/src/main/res/xml/content_settings.xml +++ b/app/src/main/res/xml/content_settings.xml @@ -122,26 +122,10 @@ android:layout="@layout/settings_category_header_layout" android:title="@string/settings_category_sponsorblock"> - - - - - + + + + + +