Skip to content

Commit

Permalink
1.评论可选优先显示最热,且把推荐放到最后
Browse files Browse the repository at this point in the history
2.优化判断歌曲音质逻辑,减少匹配错误概率
  • Loading branch information
nining377 committed Nov 11, 2021
1 parent 2ade91a commit fb364cd
Show file tree
Hide file tree
Showing 17 changed files with 217 additions and 41 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.raincat.dolby_beta"
minSdkVersion 21
targetSdkVersion 29
versionCode 335
versionName "3.3.5"
versionCode 336
versionName "3.3.6"

externalNativeBuild {
cmake {
Expand Down
Binary file modified app/src/main/assets/UnblockNeteaseMusic.zip
Binary file not shown.
15 changes: 9 additions & 6 deletions app/src/main/java/com/raincat/dolby_beta/Hook.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.raincat.dolby_beta.hook.AutoSignInHook;
import com.raincat.dolby_beta.hook.BlackHook;
import com.raincat.dolby_beta.hook.CdnHook;
import com.raincat.dolby_beta.hook.CommentHotClickHook;
import com.raincat.dolby_beta.hook.DownloadMD5Hook;
import com.raincat.dolby_beta.hook.EAPIHook;
import com.raincat.dolby_beta.hook.GrayHook;
Expand Down Expand Up @@ -98,6 +99,12 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
new InternalDialogHook(context, versionCode);
// new TestHook(context);
ClassHelper.getCacheClassList(context, versionCode, () -> {
//获取账号信息
new UserProfileHook(context);
//网络访问
new EAPIHook(context);
//下载MD5校验
new DownloadMD5Hook(context);
//精简tab
new HideTabHook(context, versionCode);
//精简侧边栏
Expand All @@ -106,12 +113,8 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
new HideBannerHook(context, versionCode);
//隐藏小红点
new HideBubbleHook(context);
//获取账号信息
new UserProfileHook(context);
//网络访问
new EAPIHook(context);
//下载MD5校验
new DownloadMD5Hook(context);
//打开评论后优先显示最热评论
new CommentHotClickHook(context);
new CdnHook(context, versionCode);

mainProcessInit = true;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/raincat/dolby_beta/db/SignDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void saveSongList(List<Long> songIdList, String userId) {
/**
* 获取已打卡歌曲
*/
public HashMap<Long, Integer> getSong( String userId) {
public HashMap<Long, Integer> getSong(String userId) {
SQLiteDatabase db = dbHelper.getReadableDatabase();
HashMap<Long, Integer> longMap = new HashMap<>();
if (db.isOpen()) {
Expand Down
46 changes: 42 additions & 4 deletions app/src/main/java/com/raincat/dolby_beta/helper/ClassHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ public static Class<?> getClazz(Context context) {
.filter(c -> Stream.of(c.getDeclaredFields()).anyMatch(m -> m.getType() == String.class))
.filter(c -> Stream.of(c.getDeclaredFields()).anyMatch(m -> m.getType() == ArrayList.class))
.filter(c -> Stream.of(c.getDeclaredFields()).anyMatch(m -> m.getType() == boolean.class))
.filter(c -> Stream.of(c.getDeclaredMethods()).anyMatch(m -> m.getReturnType() == ArrayList.class))
.filter(c -> Stream.of(c.getDeclaredMethods()).anyMatch(m -> m.getReturnType() == String[].class))
.filter(c -> Stream.of(c.getDeclaredMethods()).anyMatch(m -> m.getReturnType() == ArrayList.class && Modifier.isFinal(m.getModifiers()) && m.getParameterTypes().length == 0))
.filter(c -> Stream.of(c.getDeclaredMethods()).anyMatch(m -> m.getReturnType() == String[].class && Modifier.isFinal(m.getModifiers()) && m.getParameterTypes().length == 0))
.findFirst()
.get();
} catch (NoSuchElementException e) {
Expand All @@ -298,20 +298,24 @@ public static Class<?> getClazz(Context context) {
return clazz;
}

public static Method getTabInitMethod() {
public static Method getTabInitMethod(Context context) {
if (initMethod == null) {
Method[] methods = findMethodsByExactParameters(clazz, ArrayList.class);
if (methods.length != 0)
initMethod = methods[0];
else
MessageHelper.sendNotification(context, MessageHelper.tabClassNotFoundCode);
}
return initMethod;
}

public static Method getTabRefreshMethod() {
public static Method getTabRefreshMethod(Context context) {
if (refreshMethod == null) {
Method[] methods = findMethodsByExactParameters(clazz, void.class, List.class);
if (methods.length != 0)
refreshMethod = methods[0];
else
MessageHelper.sendNotification(context, MessageHelper.tabClassNotFoundCode);
}
return refreshMethod;
}
Expand Down Expand Up @@ -348,6 +352,40 @@ public static Class<?> getClazz(Context context) {
}
}

/**
* 评论
*/
public static class CommentDataClass {
private static Class<?> clazz;

public static Class<?> getClazz(Context context) {
if (clazz == null) {
try {
Pattern pattern = Pattern.compile("^com\\.netease\\.cloudmusic\\.module\\.comment2\\.[a-z]\\.[a-z]$");
List<String> list = ClassHelper.getFilteredClasses(pattern, Collections.reverseOrder());
clazz = Stream.of(list)
.map(s -> findClass(s, classLoader))
.filter(c -> Modifier.isPublic(c.getModifiers()))
.filter(m -> !Modifier.isInterface(m.getModifiers()))
.filter(m -> !Modifier.isStatic(m.getModifiers()))
.filter(m -> !Modifier.isAbstract(m.getModifiers()))
.filter(c -> Stream.of(c.getDeclaredFields()).anyMatch(m -> m.getType() == int.class))
.filter(c -> Stream.of(c.getDeclaredFields()).anyMatch(m -> m.getType() == List.class))
.filter(c -> Stream.of(c.getDeclaredFields()).anyMatch(m -> m.getType() == ArrayList.class))
.filter(c -> Stream.of(c.getDeclaredFields()).anyMatch(m -> m.getType() == Intent.class))
.filter(c -> Stream.of(c.getDeclaredFields()).anyMatch(m -> m.getType() == String.class))
.filter(c -> Stream.of(c.getDeclaredFields()).anyMatch(m -> m.getType() == long.class))
.filter(c -> Stream.of(c.getDeclaredFields()).anyMatch(m -> m.getType() == boolean.class))
.findFirst()
.get();
} catch (NoSuchElementException e) {
e.printStackTrace();
}
}
return clazz;
}
}

public static class OKHttp3Response {
private static Class<?> clazz;

Expand Down
13 changes: 0 additions & 13 deletions app/src/main/java/com/raincat/dolby_beta/helper/EAPIHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ public static void uploadCloud(String data) {
}

private static final Pattern REX_TYPE = Pattern.compile("\"type\":\\d+");
private static final Pattern REX_PL = Pattern.compile("\"pl\":(?!999000)\\d+");
private static final Pattern REX_DL = Pattern.compile("\"dl\":(?!999000)\\d+");
private static final Pattern REX_SUBP = Pattern.compile("\"subp\":\\d+");

/**
* 音效
Expand All @@ -151,16 +148,6 @@ public static String modifyEffect(String originalContent) {
return originalContent;
}

/**
* 解除灰色歌曲无法播放及收藏
*/
public static String modifyByRegex(String originalContent) {
originalContent = REX_PL.matcher(originalContent).replaceAll("\"pl\":320000");
originalContent = REX_DL.matcher(originalContent).replaceAll("\"dl\":320000");
originalContent = REX_SUBP.matcher(originalContent).replaceAll("\"subp\":1");
return originalContent;
}

public static JSONObject decrypt(String params) throws Exception {
params = NeteaseAES2.Decrypt(params);
if (params != null && params.length() != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ExtraHelper {
public static final String SCRIPT_STATUS = "script_status";
//脚本运行重试
public static final String SCRIPT_RETRY = "script_retry";
//APP版本号
public static final String APP_VERSION = "app_version";

//初始化数据库
public static void init(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class MessageHelper {
public static void sendNotification(Context context, int code) {
if (!SettingHelper.getInstance().getSetting(SettingHelper.warn_key))
if (!SettingHelper.getInstance().isEnable(SettingHelper.warn_key))
return;
Intent intent = new Intent(Hook.msg_send_notification);
intent.putExtra("code", cookieClassNotFoundCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Intent;
import android.text.TextUtils;

import com.raincat.dolby_beta.BuildConfig;
import com.raincat.dolby_beta.Hook;
import com.raincat.dolby_beta.net.HTTPSTrustManager;
import com.raincat.dolby_beta.utils.Tools;
Expand Down Expand Up @@ -59,14 +60,15 @@ public class ScriptHelper {
*/
public static void initScript(Context context, boolean cover) {
File unblockFile = new File(getScriptPath(context));
if (cover || !unblockFile.exists()) {
if (cover || !unblockFile.exists() || !(BuildConfig.VERSION_CODE + "").equals(ExtraHelper.getExtraDate(ExtraHelper.APP_VERSION))) {
if (FileHelper.unzipFile(modulePath, getScriptPath(context), "assets", "UnblockNeteaseMusic.zip")) {
FileHelper.unzipFiles(getScriptPath(context) + "/UnblockNeteaseMusic.zip", getScriptPath(context));
}
String bit = context.getApplicationInfo().nativeLibraryDir.endsWith("64") ? "arm64-v8a" : "armeabi-v7a";
FileHelper.unzipFile(modulePath, getScriptPath(context), bit, "libc++_shared.so");
FileHelper.unzipFile(modulePath, getScriptPath(context), bit, "libnative-lib.so");
FileHelper.unzipFile(modulePath, getScriptPath(context), bit, "libnode.so");
ExtraHelper.setExtraDate(ExtraHelper.APP_VERSION, BuildConfig.VERSION_CODE);
}
initNative(context);
}
Expand Down Expand Up @@ -114,7 +116,7 @@ public static void startScript(Context context) {
if (loadSuccess) {
new Thread(() -> {
setEnv("ENABLE_FLAC", SettingHelper.getInstance().getSetting(SettingHelper.proxy_flac_key) + "");
setEnv("MIN_BR", "128000");
setEnv("MIN_BR", "96000");

String[] origin = SettingHelper.getInstance().getProxyOriginal().split(" ");
ArrayList<String> scriptList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public class SettingHelper {
public static final String beauty_banner_hide_key = "β_beauty_banner_hide_key";
public static final String beauty_banner_hide_title = "移除发现页与歌单广场Banner";

public static final String beauty_comment_hot_key = "β_beauty_comment_hot_key";
public static final String beauty_comment_hot_title = "评论区优先显示“最热”内容";

public static final String beauty_sidebar_hide_key = "β_beauty_sidebar_hide_key";
public static final String beauty_sidebar_hide_title = "精简侧边栏";
public static final String beauty_sidebar_hide_sub = "部分Item需配合“设置”->“侧边栏管理”开关生效";
Expand Down Expand Up @@ -143,6 +146,7 @@ public void refreshSetting(Context context) {
settingMap.put(beauty_tab_hide_key, sharedPreferences.getBoolean(beauty_tab_hide_key, false));
settingMap.put(beauty_bubble_hide_key, sharedPreferences.getBoolean(beauty_bubble_hide_key, false));
settingMap.put(beauty_banner_hide_key, sharedPreferences.getBoolean(beauty_banner_hide_key, false));
settingMap.put(beauty_comment_hot_key, sharedPreferences.getBoolean(beauty_comment_hot_key, false));
}

public void setSetting(String key, boolean value) {
Expand All @@ -154,6 +158,10 @@ public boolean getSetting(String key) {
return settingMap.get(key);
}

public boolean isEnable(String key) {
return settingMap.get(master_key) && settingMap.get(key);
}

public HashMap<String, Boolean> getSidebarSetting(LinkedHashMap<String, String> map) {
if (sidebarSettingMap == null) {
sidebarSettingMap = new HashMap<>();
Expand All @@ -169,10 +177,6 @@ public void setSidebarSetting(String key, boolean value) {
sharedPreferences.edit().putBoolean(key, value).apply();
}

public boolean isEnable(String key) {
return settingMap.get(master_key) && settingMap.get(key);
}

public String getSignId() {
return sharedPreferences.getString(SettingHelper.sign_id_key, "");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.raincat.dolby_beta.hook;

import android.content.Context;

import com.raincat.dolby_beta.helper.ClassHelper;
import com.raincat.dolby_beta.helper.SettingHelper;

import org.json.JSONArray;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;

/**
* <pre>
* author : RainCat
* e-mail : nining377@gmail.com
* time : 2020/05/30
* desc : 评论区优先显示“最热”内容
* version: 1.0
* </pre>
*/
public class CommentHotClickHook {
public CommentHotClickHook(Context context) {
if (!SettingHelper.getInstance().isEnable(SettingHelper.beauty_comment_hot_key))
return;
Class<?> commentDataClass = ClassHelper.CommentDataClass.getClazz(context);
if (commentDataClass != null) {
XposedBridge.hookAllConstructors(commentDataClass, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
Object object = param.thisObject;
Field[] fields = object.getClass().getDeclaredFields();
for (Field field : fields) {
if (Modifier.isPrivate(field.getModifiers()) && !Modifier.isFinal(field.getModifiers()) && field.getType() == int.class) {
field.setAccessible(true);
Object o = field.get(object);
if ((int) o == 0)
field.set(object, 2);
}
}
}
});

Class<?> sortTypeListClass = XposedHelpers.findClassIfExists("com.netease.cloudmusic.module.comment2.meta.SortTypeList", context.getClassLoader());
if (sortTypeListClass != null)
XposedHelpers.findAndHookMethod(sortTypeListClass, "parseList", JSONArray.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
JSONArray array = (JSONArray) param.args[0];
JSONArray array2 = new JSONArray();
array2.put(array.getJSONObject(1));
array2.put(array.getJSONObject(2));
array2.put(array.getJSONObject(0));
param.args[0] = array2;
}
});
}
}
}
4 changes: 0 additions & 4 deletions app/src/main/java/com/raincat/dolby_beta/hook/EAPIHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
original = original.replace("-\\", "").replace("\"\\/api\\/v1\\/content\\/exposure\\/comment\\/banner\\/get\":\"", "\"\\/api\\/v1\\/content\\/exposure\\/comment\\/banner\\/get\":")
.replace("\"message\":\"\"}\"", "\"message\":\"\"}");
}
original = EAPIHelper.modifyByRegex(original);
} else if (path.contains("upload/cloud/info/v2")) {
JSONObject jsonObject = new JSONObject(original);
jsonObject = jsonObject.getJSONObject("privateCloud");
Expand All @@ -85,9 +84,6 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
String songid = EAPIHelper.decrypt(ClassHelper.HttpParams.getParams(context, eapi).get("params")).getString("songid");
EAPIHelper.uploadCloud(songid);
original = CloudDao.getInstance(context).getSong(Integer.parseInt(songid));
} else if (path.contains("album") || path.contains("artist") || path.contains("play")
|| path.contains("radio") || path.contains("song") || path.contains("search")) {
original = EAPIHelper.modifyByRegex(original);
}

param.setResult(param.getResult() instanceof JSONObject ? new JSONObject(original) : original);
Expand Down
33 changes: 33 additions & 0 deletions app/src/main/java/com/raincat/dolby_beta/hook/GrayHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

import com.raincat.dolby_beta.helper.SettingHelper;

import java.lang.reflect.Field;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedHelpers;

import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import static de.robv.android.xposed.XposedHelpers.findClass;
Expand All @@ -23,5 +27,34 @@ public GrayHook(Context context) {
if (SettingHelper.getInstance().isEnable(SettingHelper.proxy_gray_key))
findAndHookMethod(findClass("com.netease.cloudmusic.meta.MusicInfo", context.getClassLoader()),
"hasCopyRight", XC_MethodReplacement.returnConstant(true));

if (SettingHelper.getInstance().isEnable(SettingHelper.proxy_master_key)) {
Class<?> songPrivilegeClass = XposedHelpers.findClassIfExists("com.netease.cloudmusic.meta.virtual.SongPrivilege", context.getClassLoader());
XposedHelpers.findAndHookMethod(XposedHelpers.findClass("com.netease.cloudmusic.meta.MusicInfo", context.getClassLoader()), "setSp", songPrivilegeClass, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
Object object = param.args[0];
Field[] fields = object.getClass().getDeclaredFields();
int maxbr = 0;
for (Field field : fields) {
if (field.getType() == int.class && field.getName().equals("maxbr")) {
field.setAccessible(true);
maxbr = (int) field.get(object);
break;
}
}
if (maxbr == 0)
maxbr = 999000;

XposedHelpers.callMethod(object, "setFreeLevel", maxbr);
XposedHelpers.callMethod(object, "setSubPriv", 1);
XposedHelpers.callMethod(object, "setDownMaxLevel", maxbr);
XposedHelpers.callMethod(object, "setPlayMaxLevel", maxbr);
XposedHelpers.callMethod(object, "setDownloadMaxbr", maxbr);
XposedHelpers.callMethod(object, "setPlayMaxbr", maxbr);
}
});
}
}
}
Loading

0 comments on commit fb364cd

Please sign in to comment.