Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
fix(Default Video Quality): Video quality is not changeable if defaul…
Browse files Browse the repository at this point in the history
  • Loading branch information
YT-Advanced committed Feb 13, 2024
1 parent e6a20ba commit 6656f1a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static app.revanced.integrations.youtube.utils.StringRef.str;
import static app.revanced.integrations.youtube.utils.VideoHelpers.getCurrentQuality;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.lang.reflect.Field;
Expand All @@ -18,13 +19,30 @@ public class VideoQualityPatch {
private static final SettingsEnum mobileQualitySetting = SettingsEnum.DEFAULT_VIDEO_QUALITY_MOBILE;
private static final SettingsEnum wifiQualitySetting = SettingsEnum.DEFAULT_VIDEO_QUALITY_WIFI;

private static Boolean useCustomQuality = false;
@Nullable
private static int customQuality;

/**
* Injection point.
*
* @param ignoredVideoId id of the current video
*/
public static void initialize(@NonNull String ignoredVideoId) {
useCustomQuality = false;
customQuality = 0;
}

/**
* The available qualities of the current video in human readable form: [1080, 720, 480]
*/
@Nullable
private static List<Integer> videoQualities;

private static void changeDefaultQuality(final int defaultQuality) {
// When user manual change the quality, force this quality until video ended.
overrideCustomQuality(defaultQuality);

if (!SettingsEnum.ENABLE_SAVE_VIDEO_QUALITY.getBoolean())
return;

Expand All @@ -42,6 +60,27 @@ private static void changeDefaultQuality(final int defaultQuality) {
ReVancedUtils.showToastShort(str("revanced_save_video_quality_" + networkType.getName(), defaultQuality + "p"));
}

public static void overrideCustomQuality(final int defaultQuality) {
customQuality = defaultQuality;
useCustomQuality = true;
overrideQuality(defaultQuality);
}

public static void overideDefaultVideoQuality() {
final int preferredQuality =
ReVancedUtils.getNetworkType() == ReVancedUtils.NetworkType.MOBILE
? mobileQualitySetting.getInt()
: wifiQualitySetting.getInt();

if (preferredQuality == -2)
return;

ReVancedUtils.runOnMainThreadDelayed(() ->
setVideoQuality((useCustomQuality) ? customQuality
: preferredQuality)
, 300);
}

/**
* Injection point.
*
Expand Down Expand Up @@ -88,18 +127,6 @@ private static void setVideoQuality(int preferredQuality) {
overrideQuality(preferredQuality);
}

public static void forceVideoQuality() {
final int preferredQuality =
ReVancedUtils.getNetworkType() == ReVancedUtils.NetworkType.MOBILE
? mobileQualitySetting.getInt()
: wifiQualitySetting.getInt();

if (preferredQuality == -2)
return;

ReVancedUtils.runOnMainThreadDelayed(() -> setVideoQuality(preferredQuality), 300);
}

/**
* Injection point. New quality menu.
*
Expand All @@ -123,4 +150,4 @@ public static void userChangedQualityIndex(final int selectedQualityIndex) {

changeDefaultQuality(videoQualities.get(selectedQualityIndex));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void onQualityChanges(String quality) {
if (currentQuality == quality)
return;
currentQuality = quality;
VideoQualityPatch.forceVideoQuality();
VideoQualityPatch.overideDefaultVideoQuality();
}

public static void copyUrl(boolean withTimestamp) {
Expand Down

0 comments on commit 6656f1a

Please sign in to comment.