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.
This commit is contained in:
polymorphicshade 2020-07-19 22:38:07 -06:00
parent 41479dc37c
commit f0b029df06
5 changed files with 59 additions and 38 deletions

View file

@ -1048,15 +1048,19 @@ public abstract class BasePlayer implements
initThumbnail(info.getThumbnailUrl()); initThumbnail(info.getThumbnailUrl());
registerView(); registerView();
if (info.getUrl().startsWith("https://www.youtube.com") if (info.getUrl().startsWith("https://www.youtube.com")) {
&& mPrefs.getBoolean(context.getString(R.string.sponsorblock_enable), false)) { String apiUrl = mPrefs
try { .getString(context.getString(R.string.sponsorblock_api_url), null);
sponsorTimeInfo = new SponsorBlockApiTask( boolean isSponsorBlockEnabled = mPrefs
mPrefs.getString(context.getString(R.string.sponsorblock_custom_api_url), .getBoolean(context.getString(R.string.sponsorblock_enable), false);
"https://sponsor.ajay.app/api/"))
.getYouTubeVideoSponsorTimes(info.getId()); if (apiUrl != null && !apiUrl.isEmpty() && isSponsorBlockEnabled) {
} catch (Exception e) { try {
Log.e("SPONSOR_BLOCK", "Error getting YouTube video sponsor times.", e); sponsorTimeInfo = new SponsorBlockApiTask(apiUrl)
.getYouTubeVideoSponsorTimes(info.getId());
} catch (Exception e) {
Log.e("SPONSOR_BLOCK", "Error getting YouTube video sponsor times.", e);
}
} }
} }
} }

View file

@ -140,9 +140,17 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
return true; 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)); findPreference(getString(R.string.sponsorblock_privacy));
sponsorblockPrivacyPreference.setOnPreferenceClickListener((Preference p) -> { sponsorBlockPrivacyPreference.setOnPreferenceClickListener((Preference p) -> {
Intent i = new Intent(Intent.ACTION_VIEW, Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse( Uri.parse(
"https://gist.github.com/ajayyy/aa9f8ded2b573d4f73a3ffa0ef74f796" "https://gist.github.com/ajayyy/aa9f8ded2b573d4f73a3ffa0ef74f796"

View file

@ -223,8 +223,9 @@
<string name="downloads_storage_ask" translatable="false">downloads_storage_ask</string> <string name="downloads_storage_ask" translatable="false">downloads_storage_ask</string>
<string name="storage_use_saf" translatable="false">storage_use_saf</string> <string name="storage_use_saf" translatable="false">storage_use_saf</string>
<string name="sponsorblock_enable" translatable="false">skip_sponsors</string> <string name="sponsorblock_home_page" translatable="false">sponsorblock_home_page</string>
<string name="sponsorblock_custom_api_url" translatable="false">sponsorblock_custom_api_url</string> <string name="sponsorblock_enable" translatable="false">sponsorblock_enable</string>
<string name="sponsorblock_api_url" translatable="false">sponsorblock_custom_api_url</string>
<string name="sponsorblock_notifications" translatable="false">sponsorblock_notifications</string> <string name="sponsorblock_notifications" translatable="false">sponsorblock_notifications</string>
<string name="sponsorblock_privacy" translatable="false">sponsorblock_privacy</string> <string name="sponsorblock_privacy" translatable="false">sponsorblock_privacy</string>

View file

@ -129,7 +129,7 @@
<string name="settings_category_other_title">Other</string> <string name="settings_category_other_title">Other</string>
<string name="settings_category_debug_title">Debug</string> <string name="settings_category_debug_title">Debug</string>
<string name="settings_category_updates_title">Updates</string> <string name="settings_category_updates_title">Updates</string>
<string name="settings_category_sponsorblock">SponsorBlock Beta (Third party service)</string> <string name="settings_category_sponsorblock">SponsorBlock (beta, third party service)</string>
<string name="background_player_playing_toast">Playing in background</string> <string name="background_player_playing_toast">Playing in background</string>
<string name="popup_playing_toast">Playing in popup mode</string> <string name="popup_playing_toast">Playing in popup mode</string>
<string name="background_player_append">Queued on background player</string> <string name="background_player_append">Queued on background player</string>
@ -661,12 +661,14 @@
<string name="video_detail_by">By %s</string> <string name="video_detail_by">By %s</string>
<string name="playlist_page_summary">Playlist page</string> <string name="playlist_page_summary">Playlist page</string>
<!-- SponsorBlock --> <!-- SponsorBlock -->
<string name="sponsorblock_home_page_title">View Website</string>
<string name="sponsorblock_home_page_summary">View the official SponsorBlock website.</string>
<string name="sponsorblock_enable_title">Skip Sponsors</string> <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_enable_summary">Use the SponsorBlock API to automatically skip sponsors in videos. This currently only works for YouTube videos.</string>
<string name="sponsorblock_custom_api_url_title">Custom API Url</string> <string name="sponsorblock_api_url_title">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_api_url_summary">The url to use when querying the SponsorBlock API. This must be set for SponsorBlock to work.</string>
<string name="sponsorblock_notifications_title">Notify when sponsors are skipped</string> <string name="sponsorblock_notifications_title">Notify when sponsors are skipped</string>
<string name="sponsorblock_notifications_summary">Show a toast notification when a sponsor is automatically skipped.</string> <string name="sponsorblock_notifications_summary">Show a toast notification when a sponsor is automatically skipped.</string>
<string name="sponsorblock_privacy_title">View Privacy Policy</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_privacy_summary">View SponsorBlock\'s privacy policy.</string>
</resources> </resources>

View file

@ -122,26 +122,10 @@
android:layout="@layout/settings_category_header_layout" android:layout="@layout/settings_category_header_layout"
android:title="@string/settings_category_sponsorblock"> android:title="@string/settings_category_sponsorblock">
<SwitchPreference <Preference
android:defaultValue="false" android:key="@string/sponsorblock_home_page"
android:key="@string/sponsorblock_enable" android:summary="@string/sponsorblock_home_page_summary"
android:summary="@string/sponsorblock_enable_summary" android:title="@string/sponsorblock_home_page_title"
android:title="@string/sponsorblock_enable_title"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="true"
android:dependency="@string/sponsorblock_enable"
android:key="@string/sponsorblock_notifications"
android:summary="@string/sponsorblock_notifications_summary"
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" /> app:iconSpaceReserved="false" />
<Preference <Preference
@ -150,5 +134,27 @@
android:title="@string/sponsorblock_privacy_title" android:title="@string/sponsorblock_privacy_title"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<EditTextPreference
android:key="@string/sponsorblock_api_url"
android:summary="@string/sponsorblock_api_url_summary"
android:title="@string/sponsorblock_api_url_title"
app:iconSpaceReserved="false" />
<SwitchPreference
android:dependency="@string/sponsorblock_api_url"
android:defaultValue="false"
android:key="@string/sponsorblock_enable"
android:summary="@string/sponsorblock_enable_summary"
android:title="@string/sponsorblock_enable_title"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="true"
android:dependency="@string/sponsorblock_api_url"
android:key="@string/sponsorblock_notifications"
android:summary="@string/sponsorblock_notifications_summary"
android:title="@string/sponsorblock_notifications_title"
app:iconSpaceReserved="false" />
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>