Skip to content

Commit

Permalink
# 1.0
Browse files Browse the repository at this point in the history
* 网易云音乐全面更换为私有API(希望服务器没事.)
* 删除QQ音乐搜索源。
* 修复配置文件重复升级的问题。
* 网易云音乐添加登录功能,在配置文件设置账号密码后,可播放VIP音乐。
* 网易云歌单恢复只能导入1000首以内。
* 删除播放状态与循环状态变量。
  • Loading branch information
RealHeart committed Jul 30, 2020
1 parent 2c4ce3a commit 7a47f80
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 344 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# 0.10-beta | 2020-07-28
# 1.0 | 2020-07-30
* 网易云音乐全面更换为私有API(希望服务器没事.)
* 删除QQ音乐搜索源。
* 修复配置文件重复升级的问题。
* 网易云音乐添加登录功能,在配置文件设置账号密码后,可播放VIP音乐。
* 网易云歌单恢复只能导入1000首以内。
* 删除播放状态与循环状态变量。

# 0.10-beta | 2020-07-29
* 修复播放歌单时最大时间均为第一首的问题。
* 引入网易云加密算法。
* 修复歌单只能导入7首左右的问题。
Expand Down
6 changes: 6 additions & 0 deletions src/cn/iqianye/MinecraftPlugins/ZMusic/Config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class Config {
public static int latestVersion = 2;
// Debug
public static boolean debug;
// Account
public static String neteasePhone;
public static String neteasePassword;
// Music
public static int money;
public static int cooldown;
Expand Down Expand Up @@ -48,6 +51,9 @@ public static void load(FileConfiguration configuration) {
}
// Debug
debug = configuration.getBoolean("debug");
// Account
neteasePhone = configuration.getString("account.netease.phone");
neteasePassword = configuration.getString("account.netease.password");
// Music
money = configuration.getInt("music.money");
cooldown = configuration.getInt("music.cooldown");
Expand Down
1 change: 1 addition & 0 deletions src/cn/iqianye/MinecraftPlugins/ZMusic/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void onEnable() {
}
reloadConfig();
Config.load(getConfig());
OtherUtils.loginNetease();
LogUtils.sendNormalMessage("成功加载配置文件!");
LogUtils.sendNormalMessage("插件作者: 真心");
LogUtils.sendNormalMessage("博客:www.zhenxin.xyz");
Expand Down
23 changes: 21 additions & 2 deletions src/cn/iqianye/MinecraftPlugins/ZMusic/Music/LyricSendTimer.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package cn.iqianye.MinecraftPlugins.ZMusic.Music;

import cn.iqianye.MinecraftPlugins.ZMusic.Config.Config;
import cn.iqianye.MinecraftPlugins.ZMusic.Other.Val;
import cn.iqianye.MinecraftPlugins.ZMusic.Player.PlayerStatus;
import cn.iqianye.MinecraftPlugins.ZMusic.Utils.MessageUtils;
import cn.iqianye.MinecraftPlugins.ZMusic.Utils.MusicUtils;
import cn.iqianye.MinecraftPlugins.ZMusic.Utils.NetUtils;
import cn.iqianye.MinecraftPlugins.ZMusic.Utils.OtherUtils;
import com.connorlinfoot.actionbarapi.ActionBarAPI;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -46,8 +51,15 @@ public void run() {
if (!playListSetEd) {
time--;
String tempId = playList.get(0).getAsJsonObject().get("id").getAsString();
String tempUrl = "http://music.163.com/song/media/outer/url?id=" + tempId + ".mp3";
Gson gson = new GsonBuilder().create();
JsonObject tempUrlJson = gson.fromJson(NetUtils.getNetString(Val.apiRoot + "song/url?id=" + tempId + "&br=320000&" +
"cookie=" + Val.neteaseCookie, null), JsonObject.class);
String tempUrl = tempUrlJson.get("data").getAsJsonArray().get(0).getAsJsonObject().get("url").getAsString();
String tempName = playList.get(0).getAsJsonObject().get("name").getAsString() + "(" + playList.get(0).getAsJsonObject().get("singer").getAsString() + ")";
if (tempUrl == null) {
MessageUtils.sendErrorMessage("错误,无法获取当前音乐§r[§e" + tempName + "§r]§c,可能音乐无版权或为VIP音乐.", player);
return;
}
MessageUtils.sendNormalMessage("开始播放§r[§e" + tempName + "§r]§a.", player);
int tempMaxTime = playList.get(0).getAsJsonObject().get("time").getAsInt();
PlayerStatus.setPlayerMusicName(player, tempName);
Expand Down Expand Up @@ -125,8 +137,15 @@ public void run() {
cancel();
} else {
String tempId = playList.get(playListLocation).getAsJsonObject().get("id").getAsString();
String tempUrl = "http://music.163.com/song/media/outer/url?id=" + tempId + ".mp3";
Gson gson = new GsonBuilder().create();
JsonObject tempUrlJson = gson.fromJson(NetUtils.getNetString(Val.apiRoot + "song/url?id=" + tempId + "&br=320000&" +
"cookie=" + Val.neteaseCookie, null), JsonObject.class);
String tempUrl = tempUrlJson.get("data").getAsJsonArray().get(0).getAsJsonObject().get("url").getAsString();
String tempName = playList.get(playListLocation).getAsJsonObject().get("name").getAsString() + "(" + playList.get(playListLocation).getAsJsonObject().get("singer").getAsString() + ")";
if (tempUrl == null) {
MessageUtils.sendErrorMessage("错误,无法获取当前音乐§r[§e" + tempName + "§r]§c,可能音乐无版权或为VIP音乐.", player);
return;
}
MessageUtils.sendNormalMessage("开始播放§r[§e" + tempName + "§r]§a.", player);
int tempMaxTime = playList.get(playListLocation).getAsJsonObject().get("time").getAsInt();
PlayerStatus.setPlayerMusicName(player, tempName);
Expand Down
46 changes: 25 additions & 21 deletions src/cn/iqianye/MinecraftPlugins/ZMusic/Music/PlayList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.iqianye.MinecraftPlugins.ZMusic.Config.Config;
import cn.iqianye.MinecraftPlugins.ZMusic.Main;
import cn.iqianye.MinecraftPlugins.ZMusic.Music.SearchSource.NeteaseCloudMusic;
import cn.iqianye.MinecraftPlugins.ZMusic.Other.Val;
import cn.iqianye.MinecraftPlugins.ZMusic.Player.PlayerStatus;
import cn.iqianye.MinecraftPlugins.ZMusic.Utils.*;
import com.google.gson.*;
Expand All @@ -17,7 +17,6 @@

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;

Expand All @@ -36,35 +35,40 @@ public static void savePlayList() {
public static void importPlayList(String url, Player player) {
MessageUtils.sendNormalMessage("正在导入歌单,可能时间较长,请耐心等待...", player);
String playListId = url.split("playlist\\?id=")[1];
url = "http://music.163.com/weapi/v3/playlist/detail?csrf_token=";
String text = "{\"id\": " + playListId + ",\"n\": 100000, \"s\": 8}";
Map data = new HashMap();
try {
data = NCMEncryptUtils.getData(text);
} catch (Exception e) {
e.printStackTrace();
}
String s = "encSecKey=" + data.get("encSecKey").toString() + "&params=" + data.get("params").toString();
String jsonText = NetUtils.getNetStringPOST(url, "http://music.163.com/", s);
if (jsonText.isEmpty()) {
LogUtils.sendErrorMessage("错误: 获取歌单信息返回空,请等待2-5分钟后再试。");
MessageUtils.sendErrorMessage("错误: 获取歌单信息返回空,请等待2-5分钟后再试。", player);
}
url = Val.apiRoot + "playlist/detail?id=" + playListId;
String jsonText = NetUtils.getNetString(url, null);
File configFile = new File(JavaPlugin.getPlugin(Main.class).getDataFolder() + "/playlists", player.getName() + ".yml");
FileConfiguration config = YamlConfiguration.loadConfiguration(configFile);
Gson gson = new GsonBuilder().create();
JsonObject json = gson.fromJson(jsonText, JsonObject.class);
JsonArray trackIds = json.getAsJsonObject("playlist").getAsJsonArray("trackIds");
String songs = json.getAsJsonObject("playlist").get("trackCount").getAsString();
if (Integer.parseInt(songs) > 1000) {
MessageUtils.sendErrorMessage("错误: 请确保歌单歌曲数量不超过1000首。", player);
return;
}
String playListName = json.getAsJsonObject("playlist").get("name").getAsString();
config.set(playListId + ".info.name", playListName);
config.set(playListId + ".info.songs", songs);
StringBuilder sb = new StringBuilder();
String s;
for (JsonElement jsonElement : trackIds) {
JsonObject jsonObject = NeteaseCloudMusic.getMusicUrl(jsonElement.getAsJsonObject().get("id").getAsString());
String songName = jsonObject.get("name").getAsString();
int songTime = jsonObject.get("time").getAsInt();
String singer = jsonObject.get("singer").getAsString();
String songId = jsonObject.get("id").getAsString();
sb.append(jsonElement.getAsJsonObject().get("id").getAsString()).append(",");
}
s = sb.toString();
s = s.substring(0, s.length() - 1);
JsonObject playListInfo = gson.fromJson(NetUtils.getNetString(Val.apiRoot + "song/detail", null, "ids=" + s), JsonObject.class);
JsonArray songList = playListInfo.get("songs").getAsJsonArray();
for (JsonElement jsonElement : songList) {
String songName = jsonElement.getAsJsonObject().get("name").getAsString();
int songTime = jsonElement.getAsJsonObject().get("dt").getAsInt();
JsonArray ar = jsonElement.getAsJsonObject().get("ar").getAsJsonArray();
String singer = "";
for (JsonElement j : ar) {
singer += j.getAsJsonObject().get("name").getAsString() + "/";
}
singer = singer.substring(0, singer.length() - 1);
String songId = jsonElement.getAsJsonObject().get("id").getAsString();
config.set(playListId + "." + songId + ".name", songName);
config.set(playListId + "." + songId + ".singer", singer);
config.set(playListId + "." + songId + ".time", songTime);
Expand Down
5 changes: 0 additions & 5 deletions src/cn/iqianye/MinecraftPlugins/ZMusic/Music/PlayMusic.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import cn.iqianye.MinecraftPlugins.ZMusic.Music.SearchSource.KuGouMusic;
import cn.iqianye.MinecraftPlugins.ZMusic.Music.SearchSource.KuwoMusic;
import cn.iqianye.MinecraftPlugins.ZMusic.Music.SearchSource.NeteaseCloudMusic;
import cn.iqianye.MinecraftPlugins.ZMusic.Music.SearchSource.QQMusic;
import cn.iqianye.MinecraftPlugins.ZMusic.Player.PlayerStatus;
import cn.iqianye.MinecraftPlugins.ZMusic.Utils.MessageUtils;
import cn.iqianye.MinecraftPlugins.ZMusic.Utils.MusicUtils;
Expand Down Expand Up @@ -49,10 +48,6 @@ public static void play(String searchKey, String source, Player player, String t
try {
MessageUtils.sendNormalMessage("正在搜索中...", player);
switch (source) {
case "qq":
json = QQMusic.getMusicUrl(searchKey);
searchSourceName = "QQ音乐";
break;
case "163":
case "netease":
json = NeteaseCloudMusic.getMusicUrl(searchKey);
Expand Down
5 changes: 0 additions & 5 deletions src/cn/iqianye/MinecraftPlugins/ZMusic/Music/SearchMusic.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import cn.iqianye.MinecraftPlugins.ZMusic.Music.SearchSource.KuGouMusic;
import cn.iqianye.MinecraftPlugins.ZMusic.Music.SearchSource.KuwoMusic;
import cn.iqianye.MinecraftPlugins.ZMusic.Music.SearchSource.NeteaseCloudMusic;
import cn.iqianye.MinecraftPlugins.ZMusic.Music.SearchSource.QQMusic;
import cn.iqianye.MinecraftPlugins.ZMusic.Utils.MessageUtils;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
Expand All @@ -23,10 +22,6 @@ public class SearchMusic {
public static void sendList(String searchKey, String source, Player player) {
MessageUtils.sendNormalMessage("正在搜索中...", player);
switch (source) {
case "qq":
json = QQMusic.getMusicList(searchKey);
searchSourceName = "QQ音乐";
break;
case "163":
case "netease":
json = NeteaseCloudMusic.getMusicList(searchKey);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.iqianye.MinecraftPlugins.ZMusic.Music.SearchSource;

import cn.iqianye.MinecraftPlugins.ZMusic.Other.Val;
import cn.iqianye.MinecraftPlugins.ZMusic.Utils.NetUtils;
import com.google.gson.*;

Expand All @@ -19,26 +20,24 @@ public NeteaseCloudMusic() {
*/
public static JsonObject getMusicUrl(String musicName) {
try {
String getUrl =
"https://music.163.com/api/search/get/web?csrf_token=Referer="
+
"http://music.163.com/search/&hlposttag="
+
URLEncoder.encode("</span>&hlpretag=< span class=\"s-fc7\">", "utf-8")
+
"&limit=1&s="
+
URLEncoder.encode(musicName, "utf-8")
+
"&type=1";
String getUrl = Val.apiRoot + "search?keywords=" + URLEncoder.encode(musicName, "UTF-8") + "&limit=1&type=1";
Gson gson = new Gson();
String jsonText = NetUtils.getNetString(getUrl, null);
JsonObject json = gson.fromJson(jsonText, JsonObject.class);
JsonObject result = json.getAsJsonObject("result");
if (result != null || result.get("songCount").getAsInt() != 0) {
JsonObject jsonOut = result.getAsJsonArray("songs").get(0).getAsJsonObject();
int musicID = jsonOut.get("id").getAsInt();
String musicUrl = "http://music.163.com/song/media/outer/url?id=" + musicID + ".mp3";
JsonObject getUrlJson = gson.fromJson(NetUtils.getNetString(Val.apiRoot + "song/url?id=" + musicID + "&br=320000&" +
"cookie=" + Val.neteaseCookie, null), JsonObject.class);
String musicUrl = null;
try {
musicUrl = getUrlJson.get("data").getAsJsonArray().get(0).getAsJsonObject().get("url").getAsString();
} catch (Exception e) {
e.printStackTrace();
}


String lyricJsonText = NetUtils.getNetString("https://music.163.com/api/song/media?id=" + musicID, null);
JsonObject lyricJson = gson.fromJson(lyricJsonText, JsonObject.class);
String name = jsonOut.get("name").getAsString();
Expand Down Expand Up @@ -84,18 +83,7 @@ public static JsonObject getMusicUrl(String musicName) {
*/
public static JsonArray getMusicList(String musicName) {
try {
String getUrl =
"https://music.163.com/api/search/get/web?csrf_token=Referer="
+
"http://music.163.com/search/&hlposttag="
+
URLEncoder.encode("</span>&hlpretag=< span class=\"s-fc7\">", "utf-8")
+
"&limit=10&s="
+
URLEncoder.encode(musicName, "utf-8")
+
"&type=1";
String getUrl = Val.apiRoot + "search?keywords=" + URLEncoder.encode(musicName, "UTF-8") + "&limit=10&type=1&cookie=" + Val.neteaseCookie;
Gson gson = new GsonBuilder().create();
String jsonText = NetUtils.getNetString(getUrl, null);
JsonObject json = gson.fromJson(jsonText, JsonObject.class);
Expand Down
Loading

0 comments on commit 7a47f80

Please sign in to comment.