From abf9df36ad062d76b4e5d65ad7ecedd697eff2ab Mon Sep 17 00:00:00 2001 From: polymorphicshade Date: Mon, 18 May 2020 14:42:25 -0600 Subject: [PATCH] SponsorBlock: Added the ability to customize the server url A setting was added to allow the user to change the base SponsorBlock API server url. --- .../java/org/schabi/newpipe/SponsorBlockApiTask.java | 8 ++++++-- .../java/org/schabi/newpipe/player/BasePlayer.java | 4 +++- .../newpipe/settings/ContentSettingsFragment.java | 9 --------- app/src/main/res/values/settings_keys.xml | 2 +- app/src/main/res/values/strings.xml | 4 ++-- app/src/main/res/xml/content_settings.xml | 12 +++++++----- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/SponsorBlockApiTask.java b/app/src/main/java/org/schabi/newpipe/SponsorBlockApiTask.java index 3755dd26f..97dc73ee6 100644 --- a/app/src/main/java/org/schabi/newpipe/SponsorBlockApiTask.java +++ b/app/src/main/java/org/schabi/newpipe/SponsorBlockApiTask.java @@ -17,10 +17,14 @@ import java.util.concurrent.ExecutionException; public class SponsorBlockApiTask extends AsyncTask { private static final Application APP = App.getApp(); - private static final String SPONSOR_BLOCK_API_URL = "https://sponsor.ajay.app/api/"; + private String apiUrl; private static final String TAG = SponsorBlockApiTask.class.getSimpleName(); private static final boolean DEBUG = MainActivity.DEBUG; + public SponsorBlockApiTask(final String apiUrl) { + this.apiUrl = apiUrl; + } + public SponsorTimeInfo getYouTubeVideoSponsorTimes(final String videoId) throws ExecutionException, InterruptedException { @@ -53,7 +57,7 @@ public class SponsorBlockApiTask extends AsyncTask { String responseBody = DownloaderImpl .getInstance() - .get(SPONSOR_BLOCK_API_URL + strings[0]) + .get(apiUrl + strings[0]) .responseBody(); return JsonParser.object().from(responseBody); 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 5f30b1e94..2222870c9 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -1063,7 +1063,9 @@ public abstract class BasePlayer implements if (info.getUrl().startsWith("https://www.youtube.com") && mPrefs.getBoolean(context.getString(R.string.sponsorblock_enable), false)) { try { - sponsorTimeInfo = new SponsorBlockApiTask() + 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); 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 1f57eceda..95bc154a4 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -150,15 +150,6 @@ public class ContentSettingsFragment extends BasePreferenceFragment { startActivity(i); return true; }); - - Preference sponsorblockStatusPreference = - findPreference(getString(R.string.sponsorblock_status)); - sponsorblockStatusPreference.setOnPreferenceClickListener((Preference p) -> { - Intent i = new Intent(Intent.ACTION_VIEW, - Uri.parse("https://status.sponsor.ajay.app/")); - startActivity(i); - return true; - }); } @Override diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 371c280f3..468b08095 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -224,8 +224,8 @@ storage_use_saf skip_sponsors + sponsorblock_custom_api_url sponsorblock_notifications - sponsorblock_status sponsorblock_privacy diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 780b93db5..0e028fb17 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -663,10 +663,10 @@ 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. Notify when sponsors are skipped Send a notification to your device when a sponsor is automatically skipped. View Privacy Policy View the privacy policy of the SponsorBlock service. - View Online Status - View the online status of the SponsorBlock servers. \ 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 64f976058..e3bddcc24 100644 --- a/app/src/main/res/xml/content_settings.xml +++ b/app/src/main/res/xml/content_settings.xml @@ -137,16 +137,18 @@ android:title="@string/sponsorblock_notifications_title" app:iconSpaceReserved="false" /> + + -