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.
This commit is contained in:
polymorphicshade 2020-05-18 14:42:25 -06:00
parent 89e7128b35
commit abf9df36ad
6 changed files with 19 additions and 20 deletions

View file

@ -17,10 +17,14 @@ import java.util.concurrent.ExecutionException;
public class SponsorBlockApiTask extends AsyncTask<String, Void, JsonObject> {
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, Void, JsonObject> {
String responseBody =
DownloaderImpl
.getInstance()
.get(SPONSOR_BLOCK_API_URL + strings[0])
.get(apiUrl + strings[0])
.responseBody();
return JsonParser.object().from(responseBody);

View file

@ -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);

View file

@ -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

View file

@ -224,8 +224,8 @@
<string name="storage_use_saf" translatable="false">storage_use_saf</string>
<string name="sponsorblock_enable" translatable="false">skip_sponsors</string>
<string name="sponsorblock_custom_api_url" translatable="false">sponsorblock_custom_api_url</string>
<string name="sponsorblock_notifications" translatable="false">sponsorblock_notifications</string>
<string name="sponsorblock_status" translatable="false">sponsorblock_status</string>
<string name="sponsorblock_privacy" translatable="false">sponsorblock_privacy</string>
<!-- FileName Downloads -->

View file

@ -663,10 +663,10 @@
<!-- SponsorBlock -->
<string name="sponsorblock_enable_title">Skip Sponsors</string>
<string name="sponsorblock_enable_summary">Use the SponsorBlock API to automatically skip sponsors in videos.</string>
<string name="sponsorblock_custom_api_url_title">Custom API Url</string>
<string name="sponsorblock_custom_api_url_summary">The url to use when querying the SponsorBlock API. Leave empty to use the default.</string>
<string name="sponsorblock_notifications_title">Notify when sponsors are skipped</string>
<string name="sponsorblock_notifications_summary">Send a notification to your device when a sponsor is automatically skipped.</string>
<string name="sponsorblock_privacy_title">View Privacy Policy</string>
<string name="sponsorblock_privacy_summary">View the privacy policy of the SponsorBlock service.</string>
<string name="sponsorblock_status_title">View Online Status</string>
<string name="sponsorblock_status_summary">View the online status of the SponsorBlock servers.</string>
</resources>

View file

@ -137,16 +137,18 @@
android:title="@string/sponsorblock_notifications_title"
app:iconSpaceReserved="false" />
<EditTextPreference
android:dependency="@string/sponsorblock_enable"
android:key="@string/sponsorblock_custom_api_url"
android:summary="@string/sponsorblock_custom_api_url_summary"
android:title="@string/sponsorblock_custom_api_url_title"
app:iconSpaceReserved="false" />
<Preference
android:key="@string/sponsorblock_privacy"
android:summary="@string/sponsorblock_privacy_summary"
android:title="@string/sponsorblock_privacy_title"
app:iconSpaceReserved="false" />
<Preference
android:key="@string/sponsorblock_status"
android:summary="@string/sponsorblock_status_summary"
android:title="@string/sponsorblock_status_title"
app:iconSpaceReserved="false" />
</PreferenceCategory>
</PreferenceScreen>