From 9cfb25709df12382615fb2c1e453d7db2871d7de Mon Sep 17 00:00:00 2001
From: Zsombor Gegesy
Date: Mon, 29 Apr 2024 09:59:51 +0200
Subject: [PATCH] Remove the long broken google keys
And adjust the logic that either NewPipe is used
or the user needs to provide his own key
---
app/build.gradle | 21 ++---------
.../java/free/rm/skytube/app/Settings.java | 9 +++--
.../businessobjects/VideoCategory.java | 4 +--
.../YouTube/POJOs/YouTubeAPIKey.java | 15 +++++---
.../businessobjects/YouTube/YouTubeTasks.java | 4 +--
.../YouTube/newpipe/NewPipeService.java | 8 -----
.../adapters/CommentsAdapter.java | 2 +-
.../fragments/ChannelPlaylistsFragment.java | 2 +-
.../preferences/OthersPreferenceFragment.java | 35 ++++++++-----------
9 files changed, 41 insertions(+), 59 deletions(-)
diff --git a/app/build.gradle b/app/build.gradle
index 6d890c104d..c8626e9083 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -15,14 +15,8 @@ android {
versionName "2.987" // digits of the *fractional part* shall NOT be > than "9"
versionCode 47
// Third party devs: pls be ethical and change the below keys
- //buildConfigField 'String', 'YOUTUBE_API_KEYS_DEBUG', '"AIzaSyDU-ZZCyOB_kYkiMSZ6ooSipUZRukHU4ik"'
- buildConfigField 'String', 'YOUTUBE_API_KEYS_DEBUG', '"hidden:A0C0B03EED58193F4CD52DF668495D523A5229C6B66B0ED6282AE09BD8FF08CD5AF9A6B52C214F"'
- buildConfigField 'String[]', 'YOUTUBE_API_KEYS',
- '{' +
- '"hidden:A0C0B03EED581E1E18E900CF3E365C70253320C5D8040BF53818F2EAF4D62AEC6FA7E68F5F2175",' +
- '"hidden:A0C0B03EED581E277FCC2BD47E75526C06401FB4F66E3EDB2A2BE2B7F9C606896DDEF9875F3804",' +
- '"hidden:A0C0B03EED58183878F501C639336957395D24B2CC7C2FD43919CB92F682408C4CBEC1C2280F4B"' +
- '}'
+ buildConfigField 'String', 'YOUTUBE_API_KEYS_DEBUG', '""'
+ buildConfigField 'String[]', 'YOUTUBE_API_KEYS', '{}'
buildConfigField 'String', 'SKYTUBE_WEBSITE', '"https://github.com/SkyTubeTeam/SkyTube"'
buildConfigField 'String', 'SKYTUBE_WEBSITE_CREDITS', '"https://raw.githubusercontent.com/SkyTubeTeam/SkyTube/master/contributors.txt"'
buildConfigField 'String', 'SKYTUBE_ISSUES_URL', '"https://github.com/SkyTubeTeam/SkyTube/issues/new/choose"'
@@ -55,16 +49,7 @@ android {
resValue "string", "app_name", "SkyTube"
resValue "string", "app_flavor", "OSS"
dimension "skytube"
- buildConfigField 'String[]', 'YOUTUBE_API_KEYS',
- '{' + // new keys
- '"hidden:A0C0B03EED581E1E18E900CF3E365C70253320C5D8040BF53818F2EAF4D62AEC6FA7E68F5F2175",' +
- '"hidden:A0C0B03EED581E277FCC2BD47E75526C06401FB4F66E3EDB2A2BE2B7F9C606896DDEF9875F3804",' +
- '"hidden:A0C0B03EED58183878F501C639336957395D24B2CC7C2FD43919CB92F682408C4CBEC1C2280F4B",' +
- // old keys, but this can be used with FDroid
- '"AIzaSyC27jgPDHkQsQK8TW4ngrQprSCnlMTJ04w",' +
- '"AIzaSyCmXsaE6ZW14-1vM5zceWnGWnB73FkY7U4",' +
- '"AIzaSyBd3Loyy_XN2tPHPfc1E7EkSkdCqfzTHxg"' +
- '}'
+ buildConfigField 'String[]', 'YOUTUBE_API_KEYS', '{}'
}
// 99% Open-source edition: uses the YouTube Player Jar [i.e. proprietary module - optional usage]
extra {
diff --git a/app/src/main/java/free/rm/skytube/app/Settings.java b/app/src/main/java/free/rm/skytube/app/Settings.java
index a2f0b5cbfc..30f04f0d85 100644
--- a/app/src/main/java/free/rm/skytube/app/Settings.java
+++ b/app/src/main/java/free/rm/skytube/app/Settings.java
@@ -17,8 +17,6 @@
package free.rm.skytube.app;
-import static free.rm.skytube.app.SkyTubeApp.getStr;
-
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Environment;
@@ -373,6 +371,13 @@ public void setDisplayedReleaseNoteTag(String newValue) {
setPreference(LATEST_RELEASE_NOTES_DISPLAYED, newValue);
}
+ /**
+ * @return true, if NewPipe is the preferred backend API
+ */
+ public boolean isUseNewPipe() {
+ return getPreference(R.string.pref_use_default_newpipe_backend, true);
+ }
+
public float getDefaultPlaybackSpeed() {
try {
return Float.parseFloat(getPreference(R.string.pref_key_playback_speed, "1.0"));
diff --git a/app/src/main/java/free/rm/skytube/businessobjects/VideoCategory.java b/app/src/main/java/free/rm/skytube/businessobjects/VideoCategory.java
index 21cfae1aa6..f433ce855f 100644
--- a/app/src/main/java/free/rm/skytube/businessobjects/VideoCategory.java
+++ b/app/src/main/java/free/rm/skytube/businessobjects/VideoCategory.java
@@ -19,6 +19,7 @@
import android.util.Log;
+import free.rm.skytube.app.SkyTubeApp;
import free.rm.skytube.businessobjects.YouTube.GetBookmarksVideos;
import free.rm.skytube.businessobjects.YouTube.GetChannelVideosFull;
import free.rm.skytube.businessobjects.YouTube.GetDownloadedVideos;
@@ -28,7 +29,6 @@
import free.rm.skytube.businessobjects.YouTube.NewPipePlaylistVideos;
import free.rm.skytube.businessobjects.YouTube.NewPipeVideoBySearch;
import free.rm.skytube.businessobjects.YouTube.POJOs.YouTubeAPIKey;
-import free.rm.skytube.businessobjects.YouTube.newpipe.NewPipeService;
import free.rm.skytube.businessobjects.YouTube.newpipe.NewPipeTrendingItems;
import free.rm.skytube.businessobjects.db.Tasks.GetSubscriptionsVideosFromDb;
@@ -104,7 +104,7 @@ public boolean isVideoFilteringEnabled() {
* {@link NewPipeChannelVideos}.
*/
public static GetYouTubeVideos createChannelVideosFetcher() {
- if (NewPipeService.isPreferred()) {
+ if (SkyTubeApp.getSettings().isUseNewPipe()) {
return new NewPipeChannelVideos();
}
if (YouTubeAPIKey.get().isUserApiKeySet()) {
diff --git a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/POJOs/YouTubeAPIKey.java b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/POJOs/YouTubeAPIKey.java
index 8ef0041bd3..34bc573736 100644
--- a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/POJOs/YouTubeAPIKey.java
+++ b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/POJOs/YouTubeAPIKey.java
@@ -71,7 +71,6 @@ public synchronized static YouTubeAPIKey get() {
if (youTubeAPIKey == null) {
youTubeAPIKey = new YouTubeAPIKey();
}
-
return youTubeAPIKey;
}
@@ -92,13 +91,20 @@ public String getYouTubeAPIKey() {
if (BuildConfig.DEBUG) {
return debugKey;
} else {
- // else we are going to choose one of the defaults keys at random
- int i = random.nextInt(apiKeys.length);
- return apiKeys[i];
+ if (apiKeys.length > 0) {
+ // else we are going to choose one of the defaults keys at random
+ int i = random.nextInt(apiKeys.length);
+ return apiKeys[i];
+ } else {
+ return null;
+ }
}
}
}
+ public boolean isAnyKeyValid() {
+ return isUserApiKeySet() || apiKeys.length > 0;
+ }
/**
* @return True if the user has set his own YouTube API key (via the
@@ -108,7 +114,6 @@ public boolean isUserApiKeySet() {
return (userAPIKey != null);
}
-
/**
* @return User's YouTube API key (if set). If the user did not set a key, then it will return null.
*/
diff --git a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/YouTubeTasks.java b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/YouTubeTasks.java
index 9bdeae52b7..073ed1d451 100644
--- a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/YouTubeTasks.java
+++ b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/YouTubeTasks.java
@@ -89,7 +89,7 @@ public static Single refreshAllSubscriptions(Context context, @Nullable
}
public static Single refreshSubscribedChannel(ChannelId channelId, @Nullable Consumer newVideosFound) {
- if (NewPipeService.isPreferred() || !YouTubeAPIKey.get().isUserApiKeySet()) {
+ if (SkyTubeApp.getSettings().isUseNewPipe() || !YouTubeAPIKey.get().isUserApiKeySet()) {
return YouTubeTasks.getBulkSubscriptionVideos(Collections.singletonList(channelId), newVideosFound);
} else {
return YouTubeTasks.getChannelVideos(channelId, null, false, newVideosFound)
@@ -98,7 +98,7 @@ public static Single refreshSubscribedChannel(ChannelId channelId, @Nul
}
private static Single refreshSubscriptions(@NonNull List channelIds, @Nullable Consumer newVideosFound) {
- if (NewPipeService.isPreferred() || !YouTubeAPIKey.get().isUserApiKeySet()) {
+ if (SkyTubeApp.getSettings().isUseNewPipe() || !YouTubeAPIKey.get().isUserApiKeySet()) {
return YouTubeTasks.getBulkSubscriptionVideos(channelIds, newVideosFound);
} else {
return YouTubeTasks.getSubscriptionVideos(channelIds, newVideosFound);
diff --git a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/NewPipeService.java b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/NewPipeService.java
index 4f65022176..72741308a7 100644
--- a/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/NewPipeService.java
+++ b/app/src/main/java/free/rm/skytube/businessobjects/YouTube/newpipe/NewPipeService.java
@@ -62,7 +62,6 @@
import java.util.Objects;
import free.rm.skytube.BuildConfig;
-import free.rm.skytube.R;
import free.rm.skytube.app.Settings;
import free.rm.skytube.app.SkyTubeApp;
import free.rm.skytube.businessobjects.Logger;
@@ -562,11 +561,4 @@ public static void setCountry(String countryCodeStr) {
Log.i("NewPipeService", "set preferred content country to " + contentCountry);
NewPipe.setPreferredContentCountry(contentCountry);
}
-
- /**
- * @return true, if it's the preferred backend API
- */
- public static boolean isPreferred() {
- return SkyTubeApp.getPreferenceManager().getBoolean(SkyTubeApp.getStr(R.string.pref_use_default_newpipe_backend), true);
- }
}
diff --git a/app/src/main/java/free/rm/skytube/gui/businessobjects/adapters/CommentsAdapter.java b/app/src/main/java/free/rm/skytube/gui/businessobjects/adapters/CommentsAdapter.java
index dfb2774a22..34da27f450 100644
--- a/app/src/main/java/free/rm/skytube/gui/businessobjects/adapters/CommentsAdapter.java
+++ b/app/src/main/java/free/rm/skytube/gui/businessobjects/adapters/CommentsAdapter.java
@@ -398,7 +398,7 @@ protected void onPostExecute(List newComments) {
}
public static BaseExpandableListAdapter createAdapter(Context context, Linker.CurrentActivity currentActivity, String videoId, ExpandableListView expandableListView, View commentsProgressBar, View noVideoCommentsView, View disabledCommentsView) {
- if (NewPipeService.isPreferred()) {
+ if (SkyTubeApp.getSettings().isUseNewPipe()) {
return new CommentsAdapter(context, currentActivity, videoId, expandableListView, commentsProgressBar, noVideoCommentsView, disabledCommentsView);
} else {
return new LegacyCommentsAdapter(context, videoId, expandableListView, commentsProgressBar, noVideoCommentsView);
diff --git a/app/src/main/java/free/rm/skytube/gui/fragments/ChannelPlaylistsFragment.java b/app/src/main/java/free/rm/skytube/gui/fragments/ChannelPlaylistsFragment.java
index d9810ddc46..67bd4bd861 100644
--- a/app/src/main/java/free/rm/skytube/gui/fragments/ChannelPlaylistsFragment.java
+++ b/app/src/main/java/free/rm/skytube/gui/fragments/ChannelPlaylistsFragment.java
@@ -53,7 +53,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
}
private YouTubeTasks.ChannelPlaylistFetcher createFetcher(YouTubeChannel channel) {
- if (NewPipeService.isPreferred()) {
+ if (SkyTubeApp.getSettings().isUseNewPipe()) {
return new GetPlaylistsForChannel(channel);
} else {
return new LegacyGetChannelPlaylists(channel);
diff --git a/app/src/main/java/free/rm/skytube/gui/fragments/preferences/OthersPreferenceFragment.java b/app/src/main/java/free/rm/skytube/gui/fragments/preferences/OthersPreferenceFragment.java
index 28cb93873f..8f43b10486 100644
--- a/app/src/main/java/free/rm/skytube/gui/fragments/preferences/OthersPreferenceFragment.java
+++ b/app/src/main/java/free/rm/skytube/gui/fragments/preferences/OthersPreferenceFragment.java
@@ -19,15 +19,13 @@
import android.content.SharedPreferences;
import android.os.Bundle;
-import android.util.Log;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
+import androidx.preference.CheckBoxPreference;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
import androidx.preference.MultiSelectListPreference;
-import androidx.preference.PreferenceFragmentCompat;
-import androidx.preference.PreferenceManager;
import java.util.ArrayList;
import java.util.HashSet;
@@ -80,11 +78,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
MultiSelectListPreference hiddenTabsPref = findPreference(getString(R.string.pref_key_hide_tabs));
hiddenTabsPref.setEntries(tabListLabels);
-// ListPreference feedNotificationPref = (ListPreference) findPreference(getString(R.string.pref_feed_notification_key));
-// if(feedNotificationPref.getValue() == null) {
-// feedNotificationPref.setValueIndex(0);
-// }
-// feedNotificationPref.setSummary(String.format(getString(R.string.pref_summary_feed_notification), feedNotificationPref.getEntry()));
+ setNewPipeBackendFlags(YouTubeAPIKey.get().isUserApiKeySet(), SkyTubeApp.getSettings().isUseNewPipe());
}
@Override
@@ -104,6 +98,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
EditTextPreference youtubeAPIKeyPref = (EditTextPreference) findPreference(getString(R.string.pref_youtube_api_key));
String youtubeAPIKey = youtubeAPIKeyPref.getText();
+
if (youtubeAPIKey != null) {
youtubeAPIKey = youtubeAPIKey.trim();
@@ -112,24 +107,20 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
new ValidateYouTubeAPIKeyTask(youtubeAPIKey).executeInParallel();
}
else {
- // inform the user that we are going to use the default YouTube API key and
- // that we need to restart the app
- displayRestartDialog(R.string.pref_youtube_api_key_default,false);
+ setNewPipeBackendFlags(false, true);
}
}
} else if (key.equals(getString(R.string.pref_key_subscriptions_alphabetical_order))) {
EventBus.getInstance().notifyMainTabChanged(EventBus.SettingChange.SUBSCRIPTION_LIST_CHANGED);
- } /*else if (key.equals(getString(R.string.pref_feed_notification_key))) {
- ListPreference feedNotificationPref = (ListPreference) findPreference(key);
- feedNotificationPref.setSummary(String.format(getString(R.string.pref_summary_feed_notification), feedNotificationPref.getEntry()));
-
- int interval = Integer.parseInt(feedNotificationPref.getValue());
-
- SkyTubeApp.setFeedUpdateInterval(interval);
- }*/
+ }
}
}
+ private void setNewPipeBackendFlags(boolean enabled, boolean checked) {
+ CheckBoxPreference newPipeBackend = findPreference(getString(R.string.pref_use_default_newpipe_backend));
+ newPipeBackend.setEnabled(enabled);
+ newPipeBackend.setChecked(checked);
+ }
/**
* Display a dialog with message messageID
and force the user to restart the app by
* tapping on the restart button.
@@ -177,15 +168,19 @@ protected void onPostExecute(Boolean isKeyValid) {
if (!isKeyValid) {
// if the validation failed, reset the preference to null
((EditTextPreference) findPreference(getString(R.string.pref_youtube_api_key))).setText(null);
+ setNewPipeBackendFlags(false, true);
+
} else {
YouTubeAPIKey key = YouTubeAPIKey.reset();
if (key.isUserApiKeySet()) {
// if the key is valid, then inform the user that the custom API key is valid and
// that he needs to restart the app in order to use it
+ setNewPipeBackendFlags(true, false);
displayRestartDialog(R.string.pref_youtube_api_key_custom, false);
} else {
- displayRestartDialog(R.string.pref_youtube_api_key_default, false);
+ setNewPipeBackendFlags(true, true);
+// displayRestartDialog(R.string.pref_youtube_api_key_default, false);
}
}