Skip to content

Commit

Permalink
Merge branch 'dev' into revanced-extended
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 committed Jan 7, 2025
2 parents ee0a7b5 + 2bed142 commit 1aaf03d
Show file tree
Hide file tree
Showing 156 changed files with 5,710 additions and 2,852 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ See the [documentation](https://github.com/inotia00/revanced-documentation#readm
| `Ambient mode control` | Adds options to disable Ambient mode and to bypass Ambient mode restrictions. | 18.29.38 ~ 19.44.39 |
| `Bypass image region restrictions` | Adds an option to use a different host for static images, so that images blocked in some countries can be received. | 18.29.38 ~ 19.44.39 |
| `Change player flyout menu toggles` | Adds an option to use text toggles instead of switch toggles within the additional settings menu. | 18.29.38 ~ 19.44.39 |
| `Change share sheet` | Add option to change from in-app share sheet to system share sheet. | 18.29.38 ~ 19.44.39 |
| `Change share sheet` | Adds an option to change the in-app share sheet to the system share sheet. | 18.29.38 ~ 19.44.39 |
| `Change start page` | Adds an option to set which page the app opens in instead of the homepage. | 18.29.38 ~ 19.44.39 |
| `Custom Shorts action buttons` | Changes, at compile time, the icon of the action buttons of the Shorts player. | 18.29.38 ~ 19.44.39 |
| `Custom branding icon for YouTube` | Changes the YouTube app icon to the icon specified in patch options. | 18.29.38 ~ 19.44.39 |
Expand Down Expand Up @@ -46,7 +46,7 @@ See the [documentation](https://github.com/inotia00/revanced-documentation#readm
| `Hide layout components` | Adds options to hide general layout components. | 18.29.38 ~ 19.44.39 |
| `Hide player buttons` | Adds options to hide buttons in the video player. | 18.29.38 ~ 19.44.39 |
| `Hide player flyout menu` | Adds options to hide player flyout menu components. | 18.29.38 ~ 19.44.39 |
| `Hide shortcuts` | Remove, at compile time, the app shortcuts that appears when app icon is long pressed. | 18.29.38 ~ 19.44.39 |
| `Hide shortcuts` | Remove, at compile time, the app shortcuts that appears when the app icon is long pressed. | 18.29.38 ~ 19.44.39 |
| `Hook YouTube Music actions` | Adds support for opening music in RVX Music using the in-app YouTube Music button. | 18.29.38 ~ 19.44.39 |
| `Hook download actions` | Adds support to download videos with an external downloader app using the in-app download button. | 18.29.38 ~ 19.44.39 |
| `Layout switch` | Adds an option to spoof the dpi in order to use a tablet or phone layout. | 18.29.38 ~ 19.44.39 |
Expand All @@ -68,7 +68,7 @@ See the [documentation](https://github.com/inotia00/revanced-documentation#readm
| `Spoof streaming data` | Adds options to spoof the streaming data to allow playback. | 18.29.38 ~ 19.44.39 |
| `Swipe controls` | Adds options for controlling volume and brightness with swiping, and whether to enter fullscreen when swiping down below the player. | 18.29.38 ~ 19.44.39 |
| `Theme` | Changes the app's theme to the values specified in patch options. | 18.29.38 ~ 19.44.39 |
| `Toolbar components` | Adds options to hide or change components located on the toolbar, such as toolbar buttons, search bar, and header. | 18.29.38 ~ 19.44.39 |
| `Toolbar components` | Adds options to hide or change components located on the toolbar, such as the search bar, header, and toolbar buttons. | 18.29.38 ~ 19.44.39 |
| `Translations for YouTube` | Add translations or remove string resources. | 18.29.38 ~ 19.44.39 |
| `Video playback` | Adds options to customize settings related to video playback, such as default video quality and playback speed. | 18.29.38 ~ 19.44.39 |
| `Visual preferences icons for YouTube` | Adds icons to specific preferences in the settings. | 18.29.38 ~ 19.44.39 |
Expand All @@ -80,19 +80,20 @@ See the [documentation](https://github.com/inotia00/revanced-documentation#readm

| 💊 Patch | 📜 Description | 🏹 Target Version |
|:--------:|:--------------:|:-----------------:|
| `Amoled` | Applies a pure black theme to some components. | 6.20.51 ~ 7.25.53 |
| `Bitrate default value` | Sets the audio quality to 'Always High' when you first install the app. | 6.20.51 ~ 7.25.53 |
| `Bypass image region restrictions` | Adds an option to use a different host for static images, so that images blocked in some countries can be received. | 6.20.51 ~ 7.25.53 |
| `Certificate spoof` | Enables YouTube Music to work with Android Auto by spoofing the YouTube Music certificate. | 6.20.51 ~ 7.25.53 |
| `Change share sheet` | Add option to change from in-app share sheet to system share sheet. | 6.20.51 ~ 7.25.53 |
| `Change share sheet` | Adds an option to change the in-app share sheet to the system share sheet. | 6.20.51 ~ 7.25.53 |
| `Change start page` | Adds an option to set which page the app opens in instead of the homepage. | 6.20.51 ~ 7.25.53 |
| `Custom branding icon for YouTube Music` | Changes the YouTube Music app icon to the icon specified in patch options. | 6.20.51 ~ 7.25.53 |
| `Custom branding name for YouTube Music` | Renames the YouTube Music app to the name specified in patch options. | 6.20.51 ~ 7.25.53 |
| `Custom header for YouTube Music` | Applies a custom header in the top left corner within the app. | 6.20.51 ~ 7.25.53 |
| `Dark theme` | Changes the app's dark theme to the values specified in patch options. | 6.20.51 ~ 7.25.53 |
| `Disable Cairo splash animation` | Adds an option to disable Cairo splash animation. | 7.06.54 ~ 7.25.53 |
| `Disable DRC audio` | Adds an option to disable DRC (Dynamic Range Compression) audio. | 6.20.51 ~ 7.25.53 |
| `Disable auto captions` | Adds an option to disable captions from being automatically enabled. | 6.20.51 ~ 7.25.53 |
| `Disable dislike redirection` | Adds an option to disable redirection to the next track when clicking the Dislike button. | 6.20.51 ~ 7.25.53 |
| `Disable music video in album` | Adds option to redirect music videos from albums for non-premium users. | 6.20.51 ~ 7.25.53 |
| `Enable OPUS codec` | Adds an options to enable the OPUS audio codec if the player response includes. | 6.20.51 ~ 7.25.53 |
| `Enable debug logging` | Adds an option to enable debug logging. | 6.20.51 ~ 7.25.53 |
| `Enable landscape mode` | Adds an option to enable landscape mode when rotating the screen on phones. | 6.20.51 ~ 7.25.53 |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
package app.revanced.extension.music.patches.misc;

import android.view.View;

import androidx.annotation.GuardedBy;
import androidx.annotation.NonNull;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

import app.revanced.extension.music.patches.misc.requests.PipedRequester;
import app.revanced.extension.music.settings.Settings;
import app.revanced.extension.music.shared.VideoInformation;
import app.revanced.extension.music.utils.VideoUtils;
import app.revanced.extension.shared.utils.Logger;

@SuppressWarnings("unused")
public class AlbumMusicVideoPatch {

public enum RedirectType {
REDIRECT,
ON_CLICK,
ON_LONG_CLICK
}

private static final RedirectType REDIRECT_TYPE =
Settings.DISABLE_MUSIC_VIDEO_IN_ALBUM_REDIRECT_TYPE.get();

private static final boolean DISABLE_MUSIC_VIDEO_IN_ALBUM =
Settings.DISABLE_MUSIC_VIDEO_IN_ALBUM.get();

private static final boolean REDIRECT = REDIRECT_TYPE == RedirectType.REDIRECT;

private static final boolean ON_CLICK = REDIRECT_TYPE == RedirectType.ON_CLICK;

private static final boolean ON_LONG_CLICK = REDIRECT_TYPE == RedirectType.ON_LONG_CLICK;

private static final String YOUTUBE_MUSIC_ALBUM_PREFIX = "OLAK";

private static final AtomicBoolean isVideoLaunched = new AtomicBoolean(false);

@NonNull
private static volatile String playerResponseVideoId = "";

@NonNull
private static volatile String currentVideoId = "";

@GuardedBy("itself")
private static final Map<String, String> lastVideoIds = new LinkedHashMap<>() {
private static final int NUMBER_OF_LAST_VIDEO_IDS_TO_TRACK = 10;

@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > NUMBER_OF_LAST_VIDEO_IDS_TO_TRACK;
}
};

/**
* Injection point.
*/
public static void newPlayerResponse(@NonNull String videoId, @NonNull String playlistId, final int playlistIndex) {
if (!DISABLE_MUSIC_VIDEO_IN_ALBUM) {
return;
}
if (!playlistId.startsWith(YOUTUBE_MUSIC_ALBUM_PREFIX)) {
return;
}
if (playlistIndex < 0) {
return;
}
if (playerResponseVideoId.equals(videoId)) {
return;
}
playerResponseVideoId = videoId;

// Fetch Piped instance.
PipedRequester.fetchRequestIfNeeded(videoId, playlistId, playlistIndex);
}

/**
* Injection point.
*/
public static void newVideoLoaded(@NonNull String videoId) {
if (!DISABLE_MUSIC_VIDEO_IN_ALBUM) {
return;
}
if (currentVideoId.equals(videoId)) {
return;
}
currentVideoId = videoId;
checkVideo(videoId);
}

private static void checkVideo(@NonNull String videoId) {
try {
PipedRequester request = PipedRequester.getRequestForVideoId(videoId);
if (request == null) {
return;
}
String songId = request.getStream();
if (songId == null) {
return;
}
synchronized (lastVideoIds) {
if (lastVideoIds.put(videoId, songId) == null) {
Logger.printDebug(() -> "Official song found, videoId: " + videoId + ", songId: " + songId);
if (REDIRECT) {
openMusic(songId);
}
}
}
} catch (Exception ex) {
Logger.printException(() -> "check failure", ex);
}
}

/**
* Injection point.
*/
public static boolean openMusic() {
if (DISABLE_MUSIC_VIDEO_IN_ALBUM && ON_CLICK) {
try {
String videoId = VideoInformation.getVideoId();
synchronized (lastVideoIds) {
String songId = lastVideoIds.get(videoId);
if (songId != null) {
openMusic(songId);
return true;
}
}
} catch (Exception ex) {
Logger.printException(() -> "openMusic failure", ex);
}
}
return false;
}

private static void openMusic(@NonNull String songId) {
try {
isVideoLaunched.compareAndSet(false, true);

// The newly opened video is not a music video.
// To prevent fetch requests from being sent, set the video id to the newly opened video
VideoUtils.runOnMainThreadDelayed(() -> {
playerResponseVideoId = songId;
currentVideoId = songId;
VideoUtils.openInYouTubeMusic(songId);
}, 500);

VideoUtils.runOnMainThreadDelayed(() -> isVideoLaunched.compareAndSet(true, false), 1500);
} catch (Exception ex) {
Logger.printException(() -> "openMusic failure", ex);
}
}

/**
* Injection point.
*/
public static void setAudioVideoSwitchToggleOnLongClickListener(View view) {
if (DISABLE_MUSIC_VIDEO_IN_ALBUM && ON_LONG_CLICK) {
view.setOnLongClickListener(v -> {
try {
String videoId = VideoInformation.getVideoId();
synchronized (lastVideoIds) {
String songId = lastVideoIds.get(videoId);
if (songId != null) {
openMusic(songId);
}
}
} catch (Exception ex) {
Logger.printException(() -> "onLongClickListener failure", ex);
}
return true;
});
}
}

/**
* Injection point.
*/
public static boolean hideSnackBar() {
return DISABLE_MUSIC_VIDEO_IN_ALBUM && isVideoLaunched.get();
}

}
Loading

0 comments on commit 1aaf03d

Please sign in to comment.