Skip to content

Commit

Permalink
Remove the long broken google keys
Browse files Browse the repository at this point in the history
And adjust the logic that either NewPipe is used
or the user needs to provide his own key
  • Loading branch information
gzsombor committed Apr 29, 2024
1 parent 3ce8a2d commit 9cfb257
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 59 deletions.
21 changes: 3 additions & 18 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"'
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/free/rm/skytube/app/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -104,7 +104,7 @@ public boolean isVideoFilteringEnabled() {
* {@link NewPipeChannelVideos}.</p>
*/
public static GetYouTubeVideos createChannelVideosFetcher() {
if (NewPipeService.isPreferred()) {
if (SkyTubeApp.getSettings().isUseNewPipe()) {
return new NewPipeChannelVideos();
}
if (YouTubeAPIKey.get().isUserApiKeySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public synchronized static YouTubeAPIKey get() {
if (youTubeAPIKey == null) {
youTubeAPIKey = new YouTubeAPIKey();
}

return youTubeAPIKey;
}

Expand All @@ -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
Expand All @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static Single<Integer> refreshAllSubscriptions(Context context, @Nullable
}

public static Single<Integer> refreshSubscribedChannel(ChannelId channelId, @Nullable Consumer<Integer> 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)
Expand All @@ -98,7 +98,7 @@ public static Single<Integer> refreshSubscribedChannel(ChannelId channelId, @Nul
}

private static Single<Integer> refreshSubscriptions(@NonNull List<ChannelId> channelIds, @Nullable Consumer<Integer> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ protected void onPostExecute(List<CommentsInfoItem> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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();

Expand All @@ -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 <code>messageID</code> and force the user to restart the app by
* tapping on the restart button.
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 9cfb257

Please sign in to comment.