refactor: remove unused classes

This commit is contained in:
oSumAtrIX 2022-11-05 03:19:09 +01:00
parent 8e36da0b19
commit 98eaf9c3f2
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
25 changed files with 25 additions and 1290 deletions

View File

@ -1,4 +1,4 @@
package app.revanced.integrations.whitelist.requests;
package app.revanced.integrations.requests;
import org.json.JSONArray;
import org.json.JSONObject;
@ -18,9 +18,9 @@ public class Requester {
String url = apiUrl + route.compile(params).getCompiledRoute();
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod(route.getMethod().name());
if (route != WhitelistRoutes.GET_CHANNEL_DETAILS) {
connection.setRequestProperty("User-agent", System.getProperty("http.agent") + ";vanced");
}
// TODO: change the user agent string
connection.setRequestProperty("User-agent", System.getProperty("http.agent") + ";vanced");
return connection;
}

View File

@ -1,4 +1,4 @@
package app.revanced.integrations.whitelist.requests;
package app.revanced.integrations.requests;
public class Route {
private final String route;

View File

@ -1,8 +1,5 @@
package app.revanced.integrations.returnyoutubedislike;
import static app.revanced.integrations.videoplayer.VideoInformation.currentVideoId;
import static app.revanced.integrations.videoplayer.VideoInformation.dislikeCount;
import android.content.Context;
import android.icu.text.CompactDecimalFormat;
import android.os.Build;
@ -19,6 +16,9 @@ import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.utils.SharedPrefHelper;
public class ReturnYouTubeDislike {
private static String currentVideoId;
public static Integer dislikeCount;
private static boolean isEnabled;
private static boolean segmentedButton;
@ -74,6 +74,8 @@ public class ReturnYouTubeDislike {
dislikeCount = null;
if (!isEnabled) return;
currentVideoId = videoId;
try {
if (_dislikeFetchThread != null && _dislikeFetchThread.getState() != Thread.State.TERMINATED) {
LogHelper.debug(ReturnYouTubeDislike.class, "Interrupting the thread. Current state " + _dislikeFetchThread.getState());

View File

@ -1,7 +1,6 @@
package app.revanced.integrations.returnyoutubedislike.requests;
import static app.revanced.integrations.videoplayer.VideoInformation.dislikeCount;
import static app.revanced.integrations.whitelist.requests.Requester.parseJson;
import static app.revanced.integrations.requests.Requester.parseJson;
import org.json.JSONObject;
@ -11,10 +10,11 @@ import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import app.revanced.integrations.returnyoutubedislike.ReturnYouTubeDislike;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.returnyoutubedislike.Registration;
import app.revanced.integrations.whitelist.requests.Requester;
import app.revanced.integrations.whitelist.requests.Route;
import app.revanced.integrations.requests.Requester;
import app.revanced.integrations.requests.Route;
public class ReturnYouTubeDislikeApi {
private static final String RYD_API_URL = "https://returnyoutubedislikeapi.com/";
@ -29,14 +29,13 @@ public class ReturnYouTubeDislikeApi {
connection.setConnectTimeout(1000);
if (connection.getResponseCode() == 200) {
JSONObject json = getJSONObject(connection);
dislikeCount = json.getInt("dislikes");
LogHelper.debug(ReturnYouTubeDislikeApi.class, "dislikes fetched - " + dislikeCount);
ReturnYouTubeDislike.dislikeCount = json.getInt("dislikes");
LogHelper.debug(ReturnYouTubeDislikeApi.class, "dislikes fetched - " + ReturnYouTubeDislike.dislikeCount);
} else {
LogHelper.debug(ReturnYouTubeDislikeApi.class, "dislikes fetch response was " + connection.getResponseCode());
}
connection.disconnect();
} catch (Exception ex) {
dislikeCount = null;
LogHelper.printException(ReturnYouTubeDislikeApi.class, "Failed to fetch dislikes", ex);
}
}

View File

@ -1,9 +1,9 @@
package app.revanced.integrations.returnyoutubedislike.requests;
import static app.revanced.integrations.whitelist.requests.Route.Method.GET;
import static app.revanced.integrations.whitelist.requests.Route.Method.POST;
import static app.revanced.integrations.requests.Route.Method.GET;
import static app.revanced.integrations.requests.Route.Method.POST;
import app.revanced.integrations.whitelist.requests.Route;
import app.revanced.integrations.requests.Route;
public class ReturnYouTubeDislikeRoutes {
public static final Route SEND_VOTE = new Route(POST, "interact/vote");

View File

@ -27,7 +27,6 @@ import java.lang.ref.WeakReference;
import java.text.DecimalFormat;
import java.util.ArrayList;
import app.revanced.integrations.whitelist.WhitelistType;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.sponsorblock.SponsorBlockSettings;
import app.revanced.integrations.sponsorblock.SponsorBlockUtils;
@ -267,25 +266,6 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
screen.addPreference(preference);
}
{
Preference preference = new SwitchPreference(context);
preference.setTitle(str("general_whitelisting"));
preference.setSummary(str("general_whitelisting_sum"));
preference.setKey(WhitelistType.SPONSORBLOCK.getPreferenceEnabledName());
preferencesToDisableWhenSBDisabled.add(preference);
screen.addPreference(preference);
}
{
Preference preference = new SwitchPreference(context);
preference.setTitle(str("general_browser_button"));
preference.setSummary(str("general_browser_button_sum"));
preference.setKey(SettingsEnum.SB_SHOW_BROWSER_BUTTON.getPath());
preference.setDefaultValue(SettingsEnum.SB_SHOW_BROWSER_BUTTON.getDefaultValue());
preferencesToDisableWhenSBDisabled.add(preference);
screen.addPreference(preference);
}
{
EditTextPreference preference = new EditTextPreference(context);
preference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);

View File

@ -25,8 +25,6 @@ import app.revanced.integrations.sponsorblock.objects.SponsorSegment;
import app.revanced.integrations.sponsorblock.requests.SBRequester;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.videoplayer.VideoInformation;
import app.revanced.integrations.whitelist.Whitelist;
@SuppressLint({"LongLogTag"})
public class PlayerController {
@ -86,7 +84,6 @@ public class PlayerController {
*/
public static void initialize(Object _o) {
lastKnownVideoTime = 0;
VideoInformation.lastKnownVideoTime = 0;
SkipSegmentView.hide();
NewSegmentHelperLayout.hide();
}
@ -94,7 +91,7 @@ public class PlayerController {
public static void executeDownloadSegments(String videoId) {
videoHasSegments = false;
timeWithoutSegments = "";
if (Whitelist.isChannelSBWhitelisted() || shorts_playing) {
if (shorts_playing) {
return;
}
SponsorSegment[] segments = SBRequester.getSegments(videoId);
@ -113,7 +110,6 @@ public class PlayerController {
*/
public static void setCurrentVideoTime(long millis) {
LogHelper.debug(PlayerController.class, "setCurrentVideoTime: current video time: " + millis);
VideoInformation.lastKnownVideoTime = millis;
if (!SettingsEnum.SB_ENABLED.getBoolean()) return;
lastKnownVideoTime = millis;
if (millis <= 0) return;
@ -145,7 +141,6 @@ public class PlayerController {
public void run() {
skipSponsorTask = null;
lastKnownVideoTime = segment.start + 1;
VideoInformation.lastKnownVideoTime = lastKnownVideoTime;
new Handler(Looper.getMainLooper()).post(findAndSkipSegmentRunnable);
}
};
@ -202,7 +197,6 @@ public class PlayerController {
}
if (lastKnownVideoTime > 0) {
lastKnownVideoTime = millis;
VideoInformation.lastKnownVideoTime = lastKnownVideoTime;
} else
setCurrentVideoTime(millis);
}
@ -336,7 +330,6 @@ public class PlayerController {
try {
LogHelper.debug(PlayerController.class, "Skipping to millis=" + finalMillisecond);
lastKnownVideoTime = finalMillisecond;
VideoInformation.lastKnownVideoTime = lastKnownVideoTime;
PlayerControllerPatch.seekTo(finalMillisecond);
} catch (Exception e) {
LogHelper.printException(PlayerController.class, "Cannot skip to millisecond", e);

View File

@ -1,51 +0,0 @@
package app.revanced.integrations.sponsorblock.player;
import android.content.Context;
import android.widget.Toast;
import static app.revanced.integrations.sponsorblock.StringRef.str;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.videoplayer.VideoInformation;
public class VideoHelpers {
public static void copyVideoUrlToClipboard() {
generateVideoUrl(false);
}
public static void copyVideoUrlWithTimeStampToClipboard() {
generateVideoUrl(true);
}
private static void generateVideoUrl(boolean appendTimeStamp) {
try {
String videoId = VideoInformation.currentVideoId;
if (videoId == null || videoId.isEmpty()) {
LogHelper.debug(VideoHelpers.class, "VideoId was empty");
return;
}
String videoUrl = String.format("https://youtu.be/%s", videoId);
if (appendTimeStamp) {
long videoTime = VideoInformation.lastKnownVideoTime;
videoUrl += String.format("?t=%s", (videoTime / 1000));
}
LogHelper.debug(VideoHelpers.class, "Video URL: " + videoUrl);
setClipboard(ReVancedUtils.getContext(), videoUrl);
Toast.makeText(ReVancedUtils.getContext(), str("share_copy_url_success"), Toast.LENGTH_SHORT).show();
} catch (Exception ex) {
LogHelper.printException(VideoHelpers.class, "Couldn't generate video url", ex);
}
}
private static void setClipboard(Context context, String text) {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("link", text);
clipboard.setPrimaryClip(clip);
}
}

View File

@ -1,69 +0,0 @@
package app.revanced.integrations.sponsorblock.player.ui;
import static app.revanced.integrations.videoplayer.VideoInformation.currentVideoId;
import static app.revanced.integrations.sponsorblock.StringRef.str;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.videoplayer.VideoInformation;
import app.revanced.integrations.whitelist.Whitelist;
import app.revanced.integrations.whitelist.WhitelistType;
import app.revanced.integrations.whitelist.requests.WhitelistRequester;
import app.revanced.integrations.utils.SharedPrefHelper;
import app.revanced.integrations.utils.ReVancedUtils;
public class AdButton extends SlimButton {
public AdButton(Context context, ViewGroup container) {
super(context, container, SlimButton.SLIM_METADATA_BUTTON_ID,
SharedPrefHelper.getBoolean(context, SharedPrefHelper.SharedPrefNames.YOUTUBE, WhitelistType.ADS.getPreferenceEnabledName(), false));
initialize();
}
private void initialize() {
this.button_icon.setImageResource(ReVancedUtils.getIdentifier("revanced_yt_ad_button", "drawable"));
this.button_text.setText(str("action_ads"));
changeEnabled(Whitelist.shouldShowAds());
}
public void changeEnabled(boolean enabled) {
LogHelper.debug(AdButton.class, "changeEnabled " + enabled);
this.button_icon.setEnabled(enabled);
}
@Override
public void onClick(View view) {
this.view.setEnabled(false);
if (this.button_icon.isEnabled()) {
removeFromWhitelist();
return;
}
//this.button_icon.setEnabled(!this.button_icon.isEnabled());
addToWhiteList(this.view, this.button_icon);
}
private void removeFromWhitelist() {
try {
Whitelist.removeFromWhitelist(WhitelistType.ADS, this.context, VideoInformation.channelName);
changeEnabled(false);
} catch (Exception ex) {
LogHelper.printException(AdButton.class, "Failed to remove from whitelist", ex);
return;
}
this.view.setEnabled(true);
}
private void addToWhiteList(View view, ImageView buttonIcon) {
new Thread(() -> {
LogHelper.debug(AdButton.class, "Fetching channelId for " + currentVideoId);
WhitelistRequester.addChannelToWhitelist(WhitelistType.ADS, view, buttonIcon, this.context);
}).start();
}
}

View File

@ -1,28 +0,0 @@
package app.revanced.integrations.sponsorblock.player.ui;
import static app.revanced.integrations.sponsorblock.StringRef.str;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import app.revanced.integrations.sponsorblock.player.VideoHelpers;
import app.revanced.integrations.utils.ReVancedUtils;
public class CopyButton extends SlimButton {
public CopyButton(Context context, ViewGroup container) {
super(context, container, SlimButton.SLIM_METADATA_BUTTON_ID, ButtonVisibility.isVisibleInContainer(context, "pref_copy_video_url_button_list"));
initialize();
}
private void initialize() {
this.button_icon.setImageResource(ReVancedUtils.getIdentifier("revanced_yt_copy_icon", "drawable"));
this.button_text.setText(str("action_copy"));
}
@Override
public void onClick(View view) {
VideoHelpers.copyVideoUrlToClipboard();
}
}

View File

@ -1,28 +0,0 @@
package app.revanced.integrations.sponsorblock.player.ui;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import app.revanced.integrations.sponsorblock.player.VideoHelpers;
import app.revanced.integrations.utils.ReVancedUtils;
import static app.revanced.integrations.sponsorblock.StringRef.str;
public class CopyWithTimestamp extends SlimButton {
public CopyWithTimestamp(Context context, ViewGroup container) {
super(context, container, SlimButton.SLIM_METADATA_BUTTON_ID, ButtonVisibility.isVisibleInContainer(context, "pref_copy_video_url_timestamp_button_list"));
initialize();
}
private void initialize() {
this.button_icon.setImageResource(ReVancedUtils.getIdentifier("revanced_yt_copy_icon_with_time", "drawable"));
this.button_text.setText(str("action_tcopy"));
}
@Override
public void onClick(View view) {
VideoHelpers.copyVideoUrlWithTimeStampToClipboard();
}
}

View File

@ -1,37 +0,0 @@
package app.revanced.integrations.sponsorblock.player.ui;
import static app.revanced.integrations.sponsorblock.StringRef.str;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.videoplayer.VideoInformation;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.sponsorblock.SponsorBlockUtils;
public class SBBrowserButton extends SlimButton {
private static final String BROWSER_URL = "https://sb.ltn.fi/video/";
public SBBrowserButton(Context context, ViewGroup container) {
super(context, container, SLIM_METADATA_BUTTON_ID,
SponsorBlockUtils.isSBButtonEnabled(context, SettingsEnum.SB_SHOW_BROWSER_BUTTON.getPath()));
initialize();
}
private void initialize() {
this.button_icon.setImageResource(ReVancedUtils.getIdentifier("revanced_sb_browser", "drawable"));
this.button_text.setText(str("action_browser"));
}
@Override
public void onClick(View v) {
Uri uri = Uri.parse(BROWSER_URL + VideoInformation.currentVideoId);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
context.startActivity(intent);
}
}

View File

@ -1,69 +0,0 @@
package app.revanced.integrations.sponsorblock.player.ui;
import static app.revanced.integrations.videoplayer.VideoInformation.currentVideoId;
import static app.revanced.integrations.sponsorblock.StringRef.str;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.videoplayer.VideoInformation;
import app.revanced.integrations.whitelist.Whitelist;
import app.revanced.integrations.whitelist.WhitelistType;
import app.revanced.integrations.whitelist.requests.WhitelistRequester;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.sponsorblock.SponsorBlockUtils;
public class SBWhitelistButton extends SlimButton {
public SBWhitelistButton(Context context, ViewGroup container) {
super(context, container, SlimButton.SLIM_METADATA_BUTTON_ID,
SponsorBlockUtils.isSBButtonEnabled(context, WhitelistType.SPONSORBLOCK.getPreferenceEnabledName()));
initialize();
}
private void initialize() {
this.button_icon.setImageResource(ReVancedUtils.getIdentifier("revanced_yt_sb_button", "drawable"));
this.button_text.setText(str("action_segments"));
changeEnabled(Whitelist.isChannelSBWhitelisted());
}
public void changeEnabled(boolean enabled) {
LogHelper.debug(SBWhitelistButton.class, "changeEnabled " + enabled);
this.button_icon.setEnabled(!enabled); // enabled == true -> strikethrough (no segments), enabled == false -> clear (segments)
}
@Override
public void onClick(View view) {
this.view.setEnabled(false);
if (Whitelist.isChannelSBWhitelisted()) {
removeFromWhitelist();
return;
}
//this.button_icon.setEnabled(!this.button_icon.isEnabled());
addToWhiteList(this.view, this.button_icon);
}
private void removeFromWhitelist() {
try {
Whitelist.removeFromWhitelist(WhitelistType.SPONSORBLOCK, this.context, VideoInformation.channelName);
changeEnabled(false);
} catch (Exception ex) {
LogHelper.printException(SBWhitelistButton.class, "Failed to remove from whitelist", ex);
return;
}
this.view.setEnabled(true);
}
private void addToWhiteList(View view, ImageView buttonIcon) {
new Thread(() -> {
LogHelper.debug(SBWhitelistButton.class, "Fetching channelId for " + currentVideoId);
WhitelistRequester.addChannelToWhitelist(WhitelistType.SPONSORBLOCK, view, buttonIcon, this.context);
}).start();
}
}

View File

@ -1,134 +0,0 @@
package app.revanced.integrations.sponsorblock.player.ui;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.AttributeSet;
import android.view.ViewGroup;
import com.google.android.apps.youtube.app.ui.SlimMetadataScrollableButtonContainerLayout;
import app.revanced.integrations.whitelist.Whitelist;
import app.revanced.integrations.whitelist.WhitelistType;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.SharedPrefHelper;
import app.revanced.integrations.utils.ReVancedUtils;
public class SlimButtonContainer extends SlimMetadataScrollableButtonContainerLayout {
private ViewGroup container;
private CopyButton copyButton;
private CopyWithTimestamp copyWithTimestampButton;
public static AdButton adBlockButton;
public static SBWhitelistButton sbWhitelistButton;
private SBBrowserButton sbBrowserButton;
private final Context context;
SharedPreferences.OnSharedPreferenceChangeListener listener;
public SlimButtonContainer(Context context) {
super(context);
this.context = context;
this.initialize(context);
}
public SlimButtonContainer(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
this.initialize(context);
}
public SlimButtonContainer(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
this.initialize(context);
}
public void initialize(Context context) {
try {
container = this.findViewById(ReVancedUtils.getIdentifier("button_container_vanced", "id"));
if (container == null)
throw new Exception("Unable to initialize the button container because the button_container_vanced couldn't be found");
copyButton = new CopyButton(context, this);
copyWithTimestampButton = new CopyWithTimestamp(context, this);
adBlockButton = new AdButton(context, this);
sbWhitelistButton = new SBWhitelistButton(context, this);
sbBrowserButton = new SBBrowserButton(context, this);
new SponsorBlockVoting(context, this);
addSharedPrefsChangeListener();
} catch (Exception ex) {
LogHelper.printException(SlimButtonContainer.class, "Unable to initialize the button container", ex);
}
}
private void addSharedPrefsChangeListener() {
listener = (sharedPreferences, key) -> {
try {
LogHelper.debug(SlimButtonContainer.class, String.format("SharedPreference changed with key %s", key));
if ("pref_copy_video_url_button_list".equals(key) && copyButton != null) {
copyButton.setVisible(ButtonVisibility.isVisibleInContainer(context, "pref_copy_video_url_button_list"));
return;
}
if ("pref_copy_video_url_timestamp_button_list".equals(key) && copyWithTimestampButton != null) {
copyWithTimestampButton.setVisible(ButtonVisibility.isVisibleInContainer(context, "pref_copy_video_url_timestamp_button_list"));
return;
}
if (SettingsEnum.SB_ENABLED.getPath().equals(key)) {
if (sbWhitelistButton != null) {
if (SettingsEnum.SB_ENABLED.getBoolean()) {
toggleWhitelistButton();
} else {
Whitelist.setEnabled(WhitelistType.SPONSORBLOCK, false);
sbWhitelistButton.setVisible(false);
}
}
if (sbBrowserButton != null) {
if (SettingsEnum.SB_ENABLED.getBoolean()) {
toggleBrowserButton();
} else {
sbBrowserButton.setVisible(false);
}
}
}
if (SettingsEnum.SB_SHOW_BROWSER_BUTTON.getPath().equals(key) && sbBrowserButton != null) {
toggleBrowserButton();
return;
}
WhitelistType whitelistAds = WhitelistType.ADS;
String adsEnabledPreferenceName = whitelistAds.getPreferenceEnabledName();
if (adsEnabledPreferenceName.equals(key) && adBlockButton != null) {
boolean enabled = SharedPrefHelper.getBoolean(context, SharedPrefHelper.SharedPrefNames.YOUTUBE, adsEnabledPreferenceName, false);
Whitelist.setEnabled(whitelistAds, enabled);
adBlockButton.setVisible(enabled);
return;
}
if (WhitelistType.SPONSORBLOCK.getPreferenceEnabledName().equals(key) && sbWhitelistButton != null) {
toggleWhitelistButton();
return;
}
} catch (Exception ex) {
LogHelper.printException(SlimButtonContainer.class, "Error handling shared preference change", ex);
}
};
context.getSharedPreferences(WhitelistType.ADS.getSharedPreferencesName().getName(), Context.MODE_PRIVATE)
.registerOnSharedPreferenceChangeListener(listener);
context.getSharedPreferences(WhitelistType.SPONSORBLOCK.getSharedPreferencesName().getName(), Context.MODE_PRIVATE)
.registerOnSharedPreferenceChangeListener(listener);
}
private void toggleWhitelistButton() {
WhitelistType whitelistSB = WhitelistType.SPONSORBLOCK;
String sbEnabledPreferenceName = whitelistSB.getPreferenceEnabledName();
boolean enabled = SharedPrefHelper.getBoolean(context, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, sbEnabledPreferenceName, false);
Whitelist.setEnabled(whitelistSB, enabled);
sbWhitelistButton.setVisible(enabled);
}
private void toggleBrowserButton() {
sbBrowserButton.setVisible(SettingsEnum.SB_SHOW_BROWSER_BUTTON.getBoolean());
}
}

View File

@ -22,8 +22,8 @@ import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import app.revanced.integrations.whitelist.requests.Requester;
import app.revanced.integrations.whitelist.requests.Route;
import app.revanced.integrations.requests.Requester;
import app.revanced.integrations.requests.Route;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.sponsorblock.PlayerController;
import app.revanced.integrations.sponsorblock.SponsorBlockSettings;

View File

@ -1,9 +1,9 @@
package app.revanced.integrations.sponsorblock.requests;
import static app.revanced.integrations.whitelist.requests.Route.Method.GET;
import static app.revanced.integrations.whitelist.requests.Route.Method.POST;
import static app.revanced.integrations.requests.Route.Method.GET;
import static app.revanced.integrations.requests.Route.Method.POST;
import app.revanced.integrations.whitelist.requests.Route;
import app.revanced.integrations.requests.Route;
public class SBRoutes {
public static final Route IS_USER_VIP = new Route(GET, "isUserVIP?userID={user_id}");

View File

@ -1,142 +0,0 @@
package app.revanced.integrations.videoplayer;
import android.content.Context;
import android.support.constraint.ConstraintLayout;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.utils.SharedPrefHelper;
import java.lang.ref.WeakReference;
/* loaded from: classes6.dex */
//ToDo: Refactor
public class AutoRepeat {
static WeakReference<ImageView> _autoRepeatBtn = new WeakReference<>(null);
static ConstraintLayout _constraintLayout;
static int fadeDurationFast;
static int fadeDurationScheduled;
static Animation fadeIn;
static Animation fadeOut;
public static boolean isAutoRepeatBtnEnabled;
static boolean isShowing;
public static void initializeAutoRepeat(Object constraintLayout) {
try {
LogHelper.debug(AutoRepeat.class, "initializing auto repeat");
CopyWithTimeStamp.initializeCopyButtonWithTimeStamp(constraintLayout);
Copy.initializeCopyButton(constraintLayout);
_constraintLayout = (ConstraintLayout) constraintLayout;
isAutoRepeatBtnEnabled = shouldBeShown();
ImageView imageView = _constraintLayout.findViewById(getIdentifier("autoreplay_button", "id"));
if (imageView == null) {
LogHelper.debug(AutoRepeat.class, "Couldn't find imageView with tag \"autoreplay_button\"");
}
if (imageView != null) {
imageView.setSelected(shouldBeSelected());
imageView.setOnClickListener(new View.OnClickListener() { // from class: app.revanced.integrations.videoplayer.Autorepeat.AutoRepeat.1
@Override // android.view.View.OnClickListener
public void onClick(View v) {
LogHelper.debug(AutoRepeat.class, "Auto repeat button clicked");
AutoRepeat.changeSelected(!v.isSelected());
}
});
_autoRepeatBtn = new WeakReference<>(imageView);
fadeDurationFast = getInteger("fade_duration_fast");
fadeDurationScheduled = getInteger("fade_duration_scheduled");
fadeIn = getAnimation("fade_in");
fadeIn.setDuration(fadeDurationFast);
fadeOut = getAnimation("fade_out");
fadeOut.setDuration(fadeDurationScheduled);
isShowing = true;
changeVisibility(false);
}
} catch (Exception ex) {
LogHelper.printException(AutoRepeat.class, "Unable to set FrameLayout", ex);
}
}
public static void changeVisibility(boolean visible) {
CopyWithTimeStamp.changeVisibility(visible);
Copy.changeVisibility(visible);
if (isShowing != visible) {
isShowing = visible;
ImageView iView = _autoRepeatBtn.get();
if (_constraintLayout != null && iView != null) {
if (visible && isAutoRepeatBtnEnabled) {
LogHelper.debug(AutoRepeat.class, "Fading in");
iView.setVisibility(View.VISIBLE);
iView.startAnimation(fadeIn);
} else if (iView.getVisibility() == View.VISIBLE) {
LogHelper.debug(AutoRepeat.class, "Fading out");
iView.startAnimation(fadeOut);
iView.setVisibility(View.GONE);
}
}
}
}
public static void changeSelected(boolean selected) {
changeSelected(selected, false);
}
public static void changeSelected(boolean selected, boolean onlyView) {
ImageView iView = _autoRepeatBtn.get();
if (_constraintLayout != null && iView != null) {
if (SettingsEnum.DEBUG.getBoolean()) {
StringBuilder sb = new StringBuilder();
sb.append("Changing selected state to: ");
sb.append(selected ? "SELECTED" : "NONE");
LogHelper.debug(AutoRepeat.class, sb.toString());
}
iView.setSelected(selected);
if (!onlyView) {
setSelected(selected);
}
}
}
private static boolean shouldBeSelected() {
Context context = ReVancedUtils.getContext();
if (context == null) {
LogHelper.printException(AutoRepeat.class, "ChangeSelected - context is null!");
return false;
}
return SharedPrefHelper.getBoolean(context, SharedPrefHelper.SharedPrefNames.YOUTUBE, "pref_auto_repeat", false);
}
private static void setSelected(boolean selected) {
Context context = ReVancedUtils.getContext();
SharedPrefHelper.saveBoolean(context, SharedPrefHelper.SharedPrefNames.YOUTUBE, "pref_auto_repeat", selected);
}
private static boolean shouldBeShown() {
Context context = ReVancedUtils.getContext();
if (context == null) {
LogHelper.printException(AutoRepeat.class, "ChangeSelected - context is null!");
return false;
}
return SharedPrefHelper.getBoolean(context, SharedPrefHelper.SharedPrefNames.YOUTUBE, "pref_auto_repeat_button", false);
}
private static int getIdentifier(String name, String defType) {
Context context = ReVancedUtils.getContext();
return context.getResources().getIdentifier(name, defType, context.getPackageName());
}
private static int getInteger(String name) {
Context context = ReVancedUtils.getContext();
return context.getResources().getInteger(getIdentifier(name, "integer"));
}
private static Animation getAnimation(String name) {
Context context = ReVancedUtils.getContext();
return AnimationUtils.loadAnimation(context, getIdentifier(name, "anim"));
}
}

View File

@ -1,108 +0,0 @@
package app.revanced.integrations.videoplayer;
import android.content.Context;
import android.support.constraint.ConstraintLayout;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.sponsorblock.player.VideoHelpers;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.utils.SharedPrefHelper;
import java.lang.ref.WeakReference;
/* loaded from: classes6.dex */
//ToDo: Refactor
public class Copy {
static WeakReference<ImageView> _button = new WeakReference<>(null);
static ConstraintLayout _constraintLayout;
static int fadeDurationFast;
static int fadeDurationScheduled;
static Animation fadeIn;
static Animation fadeOut;
public static boolean isCopyButtonEnabled;
static boolean isShowing;
public static void initializeCopyButton(Object obj) {
try {
LogHelper.debug(Copy.class, "initializing");
_constraintLayout = (ConstraintLayout) obj;
isCopyButtonEnabled = shouldBeShown();
ImageView imageView = _constraintLayout.findViewById(getIdentifier("copy_button", "id"));
if (imageView == null) {
LogHelper.debug(Copy.class, "Couldn't find imageView with id \"copy_button\"");
return;
}
imageView.setOnClickListener(view -> {
LogHelper.debug(Copy.class, "Button clicked");
VideoHelpers.copyVideoUrlToClipboard();
});
_button = new WeakReference<>(imageView);
fadeDurationFast = getInteger("fade_duration_fast");
fadeDurationScheduled = getInteger("fade_duration_scheduled");
Animation animation = getAnimation("fade_in");
fadeIn = animation;
animation.setDuration(fadeDurationFast);
Animation animation2 = getAnimation("fade_out");
fadeOut = animation2;
animation2.setDuration(fadeDurationScheduled);
isShowing = true;
changeVisibility(false);
} catch (Exception e) {
LogHelper.printException(Copy.class, "Unable to set FrameLayout", e);
}
}
public static void changeVisibility(boolean z) {
if (isShowing != z) {
isShowing = z;
ImageView imageView = _button.get();
if (_constraintLayout != null && imageView != null) {
if (z && isCopyButtonEnabled) {
LogHelper.debug(Copy.class, "Fading in");
imageView.setVisibility(View.VISIBLE);
imageView.startAnimation(fadeIn);
} else if (imageView.getVisibility() == View.VISIBLE) {
LogHelper.debug(Copy.class, "Fading out");
imageView.startAnimation(fadeOut);
imageView.setVisibility(View.GONE);
}
}
}
}
public static void refreshShouldBeShown() {
isCopyButtonEnabled = shouldBeShown();
}
private static boolean shouldBeShown() {
Context appContext = ReVancedUtils.getContext();
if (appContext == null) {
LogHelper.printException(Copy.class, "shouldBeShown - context is null!");
return false;
}
String string = SharedPrefHelper.getString(appContext, SharedPrefHelper.SharedPrefNames.YOUTUBE, "pref_copy_video_url_button_list", null);
if (string == null || string.isEmpty()) {
return false;
}
return string.equalsIgnoreCase("PLAYER") || string.equalsIgnoreCase("BOTH");
}
private static int getIdentifier(String str, String str2) {
Context appContext = ReVancedUtils.getContext();
return appContext.getResources().getIdentifier(str, str2, appContext.getPackageName());
}
private static int getInteger(String str) {
return ReVancedUtils.getContext().getResources().getInteger(getIdentifier(str, "integer"));
}
private static Animation getAnimation(String str) {
return AnimationUtils.loadAnimation(ReVancedUtils.getContext(), getIdentifier(str, "anim"));
}
}

View File

@ -1,112 +0,0 @@
package app.revanced.integrations.videoplayer;
import android.content.Context;
import android.support.constraint.ConstraintLayout;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.sponsorblock.player.VideoHelpers;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.utils.SharedPrefHelper;
import java.lang.ref.WeakReference;
/* loaded from: classes6.dex */
//ToDo: Refactor
public class CopyWithTimeStamp {
static WeakReference<ImageView> _button = new WeakReference<>(null);
static ConstraintLayout _constraintLayout;
static int fadeDurationFast;
static int fadeDurationScheduled;
static Animation fadeIn;
static Animation fadeOut;
public static boolean isCopyButtonWithTimeStampEnabled;
static boolean isShowing;
public static void initializeCopyButtonWithTimeStamp(Object obj) {
try {
LogHelper.debug(CopyWithTimeStamp.class, "initializing");
_constraintLayout = (ConstraintLayout) obj;
isCopyButtonWithTimeStampEnabled = shouldBeShown();
ImageView imageView = (ImageView) _constraintLayout.findViewById(getIdentifier("copy_with_timestamp_button", "id"));
if (imageView == null) {
LogHelper.debug(CopyWithTimeStamp.class, "Couldn't find imageView with id \"copy_with_timestamp_button\"");
}
if (imageView != null) {
imageView.setOnClickListener(new View.OnClickListener() { // from class: app.revanced.integrations.videoplayer.VideoUrl.CopyWithTimeStamp.1
@Override // android.view.View.OnClickListener
public void onClick(View view) {
LogHelper.debug(CopyWithTimeStamp.class, "Button clicked");
VideoHelpers.copyVideoUrlWithTimeStampToClipboard();
}
});
_button = new WeakReference<>(imageView);
fadeDurationFast = getInteger("fade_duration_fast");
fadeDurationScheduled = getInteger("fade_duration_scheduled");
Animation animation = getAnimation("fade_in");
fadeIn = animation;
animation.setDuration(fadeDurationFast);
Animation animation2 = getAnimation("fade_out");
fadeOut = animation2;
animation2.setDuration(fadeDurationScheduled);
isShowing = true;
changeVisibility(false);
}
} catch (Exception e) {
LogHelper.printException(CopyWithTimeStamp.class, "Unable to set FrameLayout", e);
}
}
public static void changeVisibility(boolean z) {
if (isShowing != z) {
isShowing = z;
ImageView imageView = _button.get();
if (_constraintLayout != null && imageView != null) {
if (z && isCopyButtonWithTimeStampEnabled) {
LogHelper.debug(CopyWithTimeStamp.class, "Fading in");
imageView.setVisibility(View.VISIBLE);
imageView.startAnimation(fadeIn);
} else if (imageView.getVisibility() == View.VISIBLE) {
LogHelper.debug(CopyWithTimeStamp.class, "Fading out");
imageView.startAnimation(fadeOut);
imageView.setVisibility(View.GONE);
}
}
}
}
public static void refreshShouldBeShown() {
isCopyButtonWithTimeStampEnabled = shouldBeShown();
}
private static boolean shouldBeShown() {
Context appContext = ReVancedUtils.getContext();
if (appContext == null) {
LogHelper.printException(CopyWithTimeStamp.class, "shouldBeShown - context is null!");
return false;
}
String string = SharedPrefHelper.getString(appContext, SharedPrefHelper.SharedPrefNames.YOUTUBE, "pref_copy_video_url_timestamp_button_list", null);
if (string == null || string.isEmpty()) {
return false;
}
return string.equalsIgnoreCase("PLAYER") || string.equalsIgnoreCase("BOTH");
}
private static int getIdentifier(String str, String str2) {
Context appContext = ReVancedUtils.getContext();
return appContext.getResources().getIdentifier(str, str2, appContext.getPackageName());
}
private static int getInteger(String str) {
return ReVancedUtils.getContext().getResources().getInteger(getIdentifier(str, "integer"));
}
private static Animation getAnimation(String str) {
return AnimationUtils.loadAnimation(ReVancedUtils.getContext(), getIdentifier(str, "anim"));
}
}

View File

@ -1,71 +0,0 @@
package app.revanced.integrations.videoplayer;
import app.revanced.integrations.utils.LogHelper;
public class VideoInformation {
public static String currentVideoId;
public static Integer dislikeCount;
public static String channelName;
public static long lastKnownVideoTime = -1L;
private static boolean tempInfoSaved = false;
private static String tempVideoId;
private static Integer tempDislikeCount;
// Call hook in the YT code when the video changes
public static void setCurrentVideoId(final String videoId) {
if (videoId == null) {
LogHelper.debug(VideoInformation.class, "setCurrentVideoId - new id was null - currentVideoId was" + currentVideoId);
clearInformation(true);
return;
}
// Restore temporary information that was stored from the last watched video
if (tempInfoSaved) {
restoreTempInformation();
}
if (videoId.equals(currentVideoId)) {
LogHelper.debug(VideoInformation.class, "setCurrentVideoId - new and current video were equal - " + videoId);
return;
}
LogHelper.debug(VideoInformation.class, "setCurrentVideoId - video id updated from " + currentVideoId + " to " + videoId);
currentVideoId = videoId;
}
// Call hook in the YT code when the video ends
public static void videoEnded() {
saveTempInformation();
clearInformation(false);
}
// Information is cleared once a video ends
// It's cleared because the setCurrentVideoId isn't called for Shorts
// so Shorts would otherwise use the information from the last watched video
private static void clearInformation(boolean full) {
if (full) {
currentVideoId = null;
dislikeCount = null;
}
channelName = null;
}
// Temporary information is saved once a video ends
// so that if the user watches the same video again,
// the information can be restored without having to fetch again
private static void saveTempInformation() {
tempVideoId = currentVideoId;
tempDislikeCount = dislikeCount;
tempInfoSaved = true;
}
private static void restoreTempInformation() {
currentVideoId = tempVideoId;
dislikeCount = tempDislikeCount;
tempVideoId = null;
tempDislikeCount = null;
tempInfoSaved = false;
}
}

View File

@ -1,61 +0,0 @@
package app.revanced.integrations.whitelist;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import app.revanced.integrations.utils.LogHelper;
public class ObjectSerializer {
public static String serialize(Serializable obj) throws IOException {
if (obj == null) return "";
try {
ByteArrayOutputStream serialObj = new ByteArrayOutputStream();
ObjectOutputStream objStream = new ObjectOutputStream(serialObj);
objStream.writeObject(obj);
objStream.close();
return encodeBytes(serialObj.toByteArray());
} catch (Exception e) {
LogHelper.printException(ObjectSerializer.class, "Serialization error: " + e.getMessage(), e);
throw new IOException(e);
}
}
public static Object deserialize(String str) throws IOException {
if (str == null || str.length() == 0) return null;
try {
ByteArrayInputStream serialObj = new ByteArrayInputStream(decodeBytes(str));
ObjectInputStream objStream = new ObjectInputStream(serialObj);
return objStream.readObject();
} catch (Exception e) {
LogHelper.printException(ObjectSerializer.class, "Deserialization error: " + e.getMessage(), e);
throw new IOException(e);
}
}
private static String encodeBytes(byte[] bytes) {
StringBuffer strBuf = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
strBuf.append((char) (((bytes[i] >> 4) & 0xF) + ((int) 'a')));
strBuf.append((char) (((bytes[i]) & 0xF) + ((int) 'a')));
}
return strBuf.toString();
}
private static byte[] decodeBytes(String str) {
byte[] bytes = new byte[str.length() / 2];
for (int i = 0; i < str.length(); i += 2) {
char c = str.charAt(i);
bytes[i / 2] = (byte) ((c - 'a') << 4);
c = str.charAt(i + 1);
bytes[i / 2] += (c - 'a');
}
return bytes;
}
}

View File

@ -1,177 +0,0 @@
package app.revanced.integrations.whitelist;
import static app.revanced.integrations.videoplayer.VideoInformation.channelName;
import static app.revanced.integrations.sponsorblock.player.ui.SlimButtonContainer.adBlockButton;
import static app.revanced.integrations.sponsorblock.player.ui.SlimButtonContainer.sbWhitelistButton;
import static app.revanced.integrations.sponsorblock.StringRef.str;
import android.content.Context;
import android.content.SharedPreferences;
import android.widget.Toast;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.sponsorblock.player.ChannelModel;
import app.revanced.integrations.videoplayer.VideoInformation;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.utils.SharedPrefHelper;
public class Whitelist {
private static final Map<WhitelistType, ArrayList<ChannelModel>> whitelistMap = parseWhitelist(ReVancedUtils.getContext());
private static final Map<WhitelistType, Boolean> enabledMap = parseEnabledMap(ReVancedUtils.getContext());
private Whitelist() {
}
// injected calls
public static boolean shouldShowAds() {
return isWhitelisted(WhitelistType.ADS);
}
public static void setChannelName(String channelName) {
LogHelper.debug(Whitelist.class, "channel name set to " + channelName);
VideoInformation.channelName = channelName;
if (enabledMap.containsKey(WhitelistType.ADS) && enabledMap.get(WhitelistType.ADS) && adBlockButton != null) {
adBlockButton.changeEnabled(shouldShowAds());
}
if (enabledMap.containsKey(WhitelistType.SPONSORBLOCK) && enabledMap.get(WhitelistType.SPONSORBLOCK) && sbWhitelistButton != null) {
sbWhitelistButton.changeEnabled(isChannelSBWhitelisted());
}
}
// the rest
public static boolean isChannelSBWhitelisted() {
return isWhitelisted(WhitelistType.SPONSORBLOCK);
}
private static Map<WhitelistType, ArrayList<ChannelModel>> parseWhitelist(Context context) {
if (context == null) {
return Collections.emptyMap();
}
WhitelistType[] whitelistTypes = WhitelistType.values();
Map<WhitelistType, ArrayList<ChannelModel>> whitelistMap = new EnumMap<>(WhitelistType.class);
for (WhitelistType whitelistType : whitelistTypes) {
SharedPreferences preferences = SharedPrefHelper.getPreferences(context, whitelistType.getPreferencesName());
String serializedChannels = preferences.getString("channels", null);
if (serializedChannels == null) {
LogHelper.debug(Whitelist.class, String.format("channels string was null for %s whitelisting", whitelistType));
whitelistMap.put(whitelistType, new ArrayList<>());
continue;
}
try {
ArrayList<ChannelModel> deserializedChannels = (ArrayList<ChannelModel>) ObjectSerializer.deserialize(serializedChannels);
if (SettingsEnum.DEBUG.getBoolean()) {
LogHelper.debug(Whitelist.class, serializedChannels);
for (ChannelModel channel : deserializedChannels) {
LogHelper.debug(Whitelist.class, String.format("Whitelisted channel %s (%s) for type %s", channel.getAuthor(), channel.getChannelId(), whitelistType));
}
}
whitelistMap.put(whitelistType, deserializedChannels);
} catch (Exception ex) {
ex.printStackTrace();
}
}
return whitelistMap;
}
private static Map<WhitelistType, Boolean> parseEnabledMap(Context context) {
if (context == null) {
return Collections.emptyMap();
}
Map<WhitelistType, Boolean> enabledMap = new EnumMap<>(WhitelistType.class);
for (WhitelistType whitelistType : WhitelistType.values()) {
enabledMap.put(whitelistType, SharedPrefHelper.getBoolean(context, whitelistType.getSharedPreferencesName(), whitelistType.getPreferenceEnabledName(), false));
}
return enabledMap;
}
private static boolean isWhitelisted(WhitelistType whitelistType) {
boolean isEnabled = false;
if (enabledMap.containsKey(whitelistType) && enabledMap.get(whitelistType) != null) {
isEnabled = enabledMap.get(whitelistType);
}
if (!isEnabled) {
return false;
}
if (channelName == null || channelName.trim().isEmpty()) {
LogHelper.debug(Whitelist.class, String.format("Can't check whitelist status for %s because channel name was missing", whitelistType));
return false;
}
List<ChannelModel> whitelistedChannels = whitelistMap.get(whitelistType);
for (ChannelModel channel : whitelistedChannels) {
if (channel.getAuthor().equals(channelName)) {
LogHelper.debug(Whitelist.class, String.format("Whitelist for channel %s for type %s", channelName, whitelistType));
return true;
}
}
return false;
}
public static boolean addToWhitelist(WhitelistType whitelistType, Context context, ChannelModel channel) {
ArrayList<ChannelModel> whitelisted = whitelistMap.get(whitelistType);
for (ChannelModel whitelistedChannel : whitelisted) {
String channelId = channel.getChannelId();
if (whitelistedChannel.getChannelId().equals(channelId)) {
LogHelper.debug(Whitelist.class, String.format("Tried whitelisting an existing channel again. Old info (%1$s | %2$s) - New info (%3$s | %4$s)",
whitelistedChannel.getAuthor(), channelId, channelName, channelId));
return true;
}
}
whitelisted.add(channel);
return updateWhitelist(whitelistType, whitelisted, context);
}
public static void removeFromWhitelist(WhitelistType whitelistType, Context context, String channelName) {
ArrayList<ChannelModel> channels = whitelistMap.get(whitelistType);
Iterator<ChannelModel> iterator = channels.iterator();
while (iterator.hasNext()) {
ChannelModel channel = iterator.next();
if (channel.getAuthor().equals(channelName)) {
iterator.remove();
break;
}
}
boolean success = updateWhitelist(whitelistType, channels, context);
String friendlyName = whitelistType.getFriendlyName();
if (success) {
Toast.makeText(context, str("revanced_whitelisting_removed", channelName, friendlyName), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, str("revanced_whitelisting_remove_failed", channelName, friendlyName), Toast.LENGTH_SHORT).show();
}
}
private static boolean updateWhitelist(WhitelistType whitelistType, ArrayList<ChannelModel> channels, Context context) {
if (context == null) {
return false;
}
SharedPreferences preferences = SharedPrefHelper.getPreferences(context, whitelistType.getPreferencesName());
SharedPreferences.Editor editor = preferences.edit();
try {
editor.putString("channels", ObjectSerializer.serialize(channels));
editor.apply();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public static void setEnabled(WhitelistType whitelistType, boolean enabled) {
enabledMap.put(whitelistType, enabled);
}
}

View File

@ -1,39 +0,0 @@
package app.revanced.integrations.whitelist;
import static app.revanced.integrations.sponsorblock.StringRef.str;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.SharedPrefHelper;
public enum WhitelistType {
ADS(SharedPrefHelper.SharedPrefNames.YOUTUBE, SettingsEnum.ENABLE_WHITELIST.getPath()),
SPONSORBLOCK(SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, "revanced_whitelist_sb_enabled");
private final String friendlyName;
private final String preferencesName;
private final String preferenceEnabledName;
private final SharedPrefHelper.SharedPrefNames name;
WhitelistType(SharedPrefHelper.SharedPrefNames name, String preferenceEnabledName) {
this.friendlyName = str("revanced_whitelisting_" + name().toLowerCase());
this.name = name;
this.preferencesName = "whitelist_" + name();
this.preferenceEnabledName = preferenceEnabledName;
}
public String getFriendlyName() {
return friendlyName;
}
public SharedPrefHelper.SharedPrefNames getSharedPreferencesName() {
return name;
}
public String getPreferencesName() {
return preferencesName;
}
public String getPreferenceEnabledName() {
return preferenceEnabledName;
}
}

View File

@ -1,103 +0,0 @@
package app.revanced.integrations.whitelist.requests;
import static app.revanced.integrations.videoplayer.VideoInformation.currentVideoId;
import static app.revanced.integrations.utils.ReVancedUtils.runOnMainThread;
import static app.revanced.integrations.sponsorblock.StringRef.str;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import org.json.JSONObject;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.sponsorblock.player.ChannelModel;
import app.revanced.integrations.whitelist.Whitelist;
import app.revanced.integrations.whitelist.WhitelistType;
import app.revanced.integrations.BuildConfig;
public class WhitelistRequester {
private static final String YT_API_URL = "https://www.youtube.com/youtubei/v1/";
private WhitelistRequester() {
}
public static void addChannelToWhitelist(WhitelistType whitelistType, View view, ImageView buttonIcon, Context context) {
try {
HttpURLConnection connection = getConnectionFromRoute(WhitelistRoutes.GET_CHANNEL_DETAILS, BuildConfig.YT_API_KEY);
connection.setRequestProperty("Content-Type", "application/json; utf-8");
connection.setRequestProperty("Accept", "application/json");
connection.setDoOutput(true);
connection.setConnectTimeout(2 * 1000);
String versionName = getVersionName(context);
String jsonInputString = "{\"context\": {\"client\": { \"clientName\": \"Android\", \"clientVersion\": \"" + versionName + "\" } }, \"videoId\": \"" + currentVideoId + "\"}";
try (OutputStream os = connection.getOutputStream()) {
byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
int responseCode = connection.getResponseCode();
if (responseCode == 200) {
JSONObject json = getJSONObject(connection);
JSONObject videoInfo = json.getJSONObject("videoDetails");
ChannelModel channelModel = new ChannelModel(videoInfo.getString("author"), videoInfo.getString("channelId"));
String author = channelModel.getAuthor();
LogHelper.debug(WhitelistRequester.class, "channelId " + channelModel.getChannelId() + " fetched for author " + author);
boolean success = Whitelist.addToWhitelist(whitelistType, context, channelModel);
String whitelistTypeName = whitelistType.getFriendlyName();
runOnMainThread(() -> {
if (success) {
buttonIcon.setEnabled(whitelistType != WhitelistType.SPONSORBLOCK);
Toast.makeText(context, str("revanced_whitelisting_added", author, whitelistTypeName), Toast.LENGTH_SHORT).show();
} else {
buttonIcon.setEnabled(whitelistType == WhitelistType.SPONSORBLOCK);
Toast.makeText(context, str("revanced_whitelisting_add_failed", author, whitelistTypeName), Toast.LENGTH_SHORT).show();
}
view.setEnabled(true);
});
} else {
LogHelper.debug(WhitelistRequester.class, "player fetch response was " + responseCode);
runOnMainThread(() -> {
Toast.makeText(context, str("revanced_whitelisting_fetch_failed", responseCode), Toast.LENGTH_SHORT).show();
buttonIcon.setEnabled(true);
view.setEnabled(true);
});
}
connection.disconnect();
} catch (Exception ex) {
LogHelper.printException(WhitelistRequester.class, "Failed to fetch channelId", ex);
runOnMainThread(() -> view.setEnabled(true));
}
}
// helpers
private static HttpURLConnection getConnectionFromRoute(Route route, String... params) throws IOException {
return Requester.getConnectionFromRoute(YT_API_URL, route, params);
}
private static JSONObject getJSONObject(HttpURLConnection connection) throws Exception {
return Requester.getJSONObject(connection);
}
private static String getVersionName(Context context) {
try {
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
String version = pInfo.versionName;
return (version);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return ("17.24.34");
}
}

View File

@ -1,10 +0,0 @@
package app.revanced.integrations.whitelist.requests;
import static app.revanced.integrations.whitelist.requests.Route.Method.POST;
public class WhitelistRoutes {
public static final Route GET_CHANNEL_DETAILS = new Route(POST, "player?key={api_key}");
private WhitelistRoutes() {
}
}