ktv mode
This commit is contained in:
Color_yr committed 2023-01-08 14:31:20 +08:00
1 parent 82aef4c018
commit fa839a8ea6
19 files changed
+339 -55

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@ plugins {
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '6.1.0'
}
version = "2.17.4"
version = "2.17.5"
repositories {
mavenCentral()
+3 -3
View File
@@ -39,15 +39,15 @@ public class AllMusic {
/**
* 插件版本号
*/
public static final String version = "2.17.4";
public static final String version = "2.17.5";
/**
* 配置文件版本号
*/
public static final String configVersion = "101";
public static final String configVersion = "102";
/**
* 语言文件配置版本号
*/
public static final String messageVersion = "101";
public static final String messageVersion = "102";
/**
* 搜歌结果
@@ -43,11 +43,13 @@ public class CommandEX {
* @return 结果
*/
private static boolean checkMoney(Object sender, String name, int cost) {
if (AllMusic.getConfig().UseCost && AllMusic.economy != null) {
if (!AllMusic.economy.check(name, cost)) {
AllMusic.side.sendMessage(sender, AllMusic.getMessage().Cost.NoMoney);
return true;
}
if (!AllMusic.getConfig().UseCost || AllMusic.economy == null) {
return false;
}
if (!AllMusic.economy.check(name, cost)) {
AllMusic.side.sendMessage(sender, AllMusic.getMessage().Cost.NoMoney);
return true;
}
return false;
}
@@ -61,6 +63,10 @@ public class CommandEX {
* @return 结果
*/
private static boolean cost(Object sender, String name, int cost, String message) {
if (!AllMusic.getConfig().UseCost || AllMusic.economy == null){
return false;
}
if (AllMusic.economy.cost(name, cost)) {
AllMusic.side.sendMessage(sender, message
.replace("%Cost%", "" + cost));
@@ -151,10 +151,19 @@ public class HudUtils {
if (showobj == null) {
info = AllMusic.getMessage().Hud.NoLyric;
} else {
info = AllMusic.getMessage().Hud.Lyric
.replace("%Lyric%", showobj.getLyric() == null ? "" : showobj.getLyric())
.replace("%Tlyric%", (showobj.isHaveT() && showobj.getTlyric() != null) ?
showobj.getTlyric() : "");
String lyric = showobj.getLyric();
String tLyric = showobj.getTlyric();
String kLyric = showobj.getKly();
if (!AllMusic.getConfig().KtvMode || !showobj.isHaveK()) {
info = AllMusic.getMessage().Hud.Lyric
.replace("%Lyric%", lyric == null ? "" : lyric)
.replace("%Tlyric%", tLyric != null ? tLyric : "");
} else {
info = AllMusic.getMessage().Hud.Ktv
.replace("%Lyric%", lyric != null ? lyric : "")
.replace("%KLyric%", kLyric != null ? kLyric : "")
.replace("%Tlyric%", tLyric != null ? tLyric : "");
}
}
AllMusic.side.sendHudLyric(info);
@@ -230,11 +230,16 @@ public class APIMain {
LyricSaveObj Lyric = new LyricSaveObj();
JsonObject params = new JsonObject();
params.addProperty("id", id);
params.addProperty("lv", -1);
params.addProperty("kv", -1);
params.addProperty("tv", -1);
params.addProperty("rv", -1);
HttpResObj res = HttpClientUtil.post("https://music.163.com/api/song/lyric?_nmclfl=1", params, EncryptType.API, null);
params.addProperty("cp", false);
params.addProperty("tv", 0);
params.addProperty("lv", 0);
params.addProperty("rv", 0);
params.addProperty("kv", 0);
params.addProperty("yv", 0);
params.addProperty("ytv", 0);
params.addProperty("rtv", 0);
HttpResObj res = HttpClientUtil.post("https://interface3.music.163.com/eapi/song/lyric/v1",
params, EncryptType.EAPI, "/api/song/lyric/v1");
if (res != null && res.ok) {
try {
WLyricOBJ obj = AllMusic.gson.fromJson(res.data, WLyricOBJ.class);
@@ -8,6 +8,20 @@ import coloryr.allmusic.utils.Function;
import java.util.*;
public class LyricDo {
private static class KL {
public char k;
public Map<Integer, Character> v;
public KL(char k, Map<Integer, Character> v) {
this.k = k;
this.v = v;
}
@Override
public String toString() {
return String.valueOf(k);
}
}
private final Map<Integer, LyricItemObj> temp = new HashMap<>();
public boolean isHave = false;
@@ -18,6 +32,7 @@ public class LyricDo {
/**
* 检查歌词
*
* @param obj 歌词
* @return 结果
*/
@@ -25,47 +40,82 @@ public class LyricDo {
String[] lyric;
boolean haveT = false;
boolean haveK = false;
if (!obj.isOk())
return true;
else if (obj.isNone())
return false;
lyric = obj.getLyric().split("\n");
List<String> Tlyric = new ArrayList<>();
if (obj.getTlyric() != null) {
Tlyric = Arrays.asList(obj.getTlyric().split("\n"));
haveT = true;
}
List<KL> temp2 = new ArrayList<>();
Map<Integer, String> temp = getTime(Arrays.asList(lyric));
if (haveT) {
Map<Integer, String> temp1 = getTime(Tlyric);
for (Map.Entry<Integer, String> item : temp.entrySet()) {
this.temp.put(item.getKey(), new LyricItemObj(haveT,
item.getValue(), temp1.get(item.getKey())));
}
} else {
for (Map.Entry<Integer, String> item : temp.entrySet()) {
this.temp.put(item.getKey(), new LyricItemObj(haveT,
item.getValue(), null));
}
Map<Integer, String> temp1 = new HashMap<>();
if (obj.getTlyric() != null) {
List<String> tlyric = Arrays.asList(obj.getTlyric().split("\n"));
haveT = true;
temp1 = getTime(tlyric);
}
if (obj.getKlyric() != null && !obj.getKlyric().isEmpty()) {
String[] klyric = obj.getKlyric().split("\n");
char[] temp3 = new char[1];
for (String item : klyric) {
Map<Integer, Character> temp4 = getKTime(item, temp3);
if (temp4 != null) {
temp2.add(new KL(temp3[0], temp4));
}
}
haveK = true;
}
int index = 0;
for (Map.Entry<Integer, String> item : temp.entrySet()) {
Map<Integer, Character> temp6 = null;
if (haveK) {
char temp7 = item.getValue().charAt(0);
if (index == temp2.size()) {
index = 0;
}
while (index < temp2.size()) {
KL temp5 = temp2.get(index);
if (temp5.k == temp7) {
temp6 = temp5.v;
index++;
break;
}
index++;
}
}
this.temp.put(item.getKey(), new LyricItemObj(item.getKey(), haveT,
item.getValue(), temp1.get(item.getKey()), temp6, temp6 != null));
}
isHave = true;
return false;
}
/**
* 将歌词转换成时间 字
*
* @param lyric 歌词
* @return 结果
*/
private Map<Integer, String> getTime(List<String> lyric) {
Map<Integer, String> res = new HashMap<>();
Map<Integer, String> res = new LinkedHashMap<>();
String min;
String sec;
String mil;
int time;
int milt;
for (String s : lyric) {
if (Function.countChar(Function.getString(s, "[", "]"), ':') > 1) {
if (!s.startsWith("["))
continue;
String temp = Function.getString(s, "[", "]");
if (!temp.contains(".") || !temp.contains(":"))
continue;
if (Function.countChar(temp, ':') > 1) {
String[] a = s.split(":");
min = a[0].substring(1);
sec = a[1];
@@ -94,4 +144,30 @@ public class LyricDo {
}
return res;
}
private Map<Integer, Character> getKTime(String lyric, char[] time1) {
Map<Integer, Character> res = new HashMap<>();
if (!lyric.startsWith("[") || !lyric.contains("]("))
return null;
String[] temp1 = lyric.split("\\(");
if (temp1.length == 1)
return null;
int now = 0;
for (int a = 1; a < temp1.length; a++) {
String time = temp1[a];
int temp2 = time.indexOf(')');
String temp3 = time.substring(2, temp2);
int temp5 = Integer.parseInt(temp3) / 10 * 10;
char temp6 = time.charAt(temp2 + 1);
if (a == 1) {
time1[0] = temp6;
}
res.put(now, temp6);
now += temp5;
}
return res;
}
}
@@ -6,6 +6,7 @@ import coloryr.allmusic.objs.music.LyricItemObj;
import coloryr.allmusic.objs.music.LyricSaveObj;
import coloryr.allmusic.objs.music.MusicObj;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@@ -99,19 +100,31 @@ public class PlayGo {
}
private static void time2() {
LyricItemObj show = PlayMusic.lyric.checkTime(PlayMusic.musicNowTime);
if (show != null) {
PlayMusic.lyricItem = show;
times = 0;
HudUtils.sendHudLyricData(show);
AllMusic.side.updateLyric();
} else {
times++;
if (times == 500 && PlayMusic.lyricItem != null) {
try {
LyricItemObj show = PlayMusic.lyric.checkTime(PlayMusic.musicNowTime);
if (show != null) {
PlayMusic.lyricItem = show;
times = 0;
HudUtils.sendHudLyricData(PlayMusic.lyricItem);
HudUtils.sendHudLyricData(show);
AllMusic.side.updateLyric();
} else {
if (PlayMusic.lyricItem != null &&
AllMusic.getConfig().KtvMode && PlayMusic.lyricItem.isHaveK()) {
if (PlayMusic.lyricItem.ktv(PlayMusic.musicNowTime)) {
HudUtils.sendHudLyricData(PlayMusic.lyricItem);
AllMusic.side.updateLyric();
}
} else {
times++;
if (times == 500 && PlayMusic.lyricItem != null) {
times = 0;
HudUtils.sendHudLyricData(PlayMusic.lyricItem);
AllMusic.side.updateLyric();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@@ -105,6 +105,10 @@ public class ConfigOBJ {
* 将信息限制在bar处
*/
public boolean ShowInBar;
/**
* K歌歌词
*/
public boolean KtvMode;
/**
* 登录的用户
@@ -165,6 +169,8 @@ public class ConfigOBJ {
Economy = new EconomyObj();
KtvMode = true;
Version = AllMusic.version;
}
@@ -3,6 +3,7 @@ package coloryr.allmusic.objs.api.music.lyric;
public class WLyricOBJ {
private lrc lrc;
private tlyric tlyric;
private klyric klyric;
private boolean nolyric;
private boolean uncollected;
@@ -20,6 +21,12 @@ public class WLyricOBJ {
return tlyric.getLyric();
}
public String getKlyric() {
if (klyric == null)
return null;
return klyric.getLyric();
}
public boolean isNone() {
return nolyric || uncollected;
}
@@ -39,4 +46,13 @@ class tlyric {
public String getLyric() {
return lyric;
}
}
class klyric
{
private String lyric;
public String getLyric() {
return lyric == null ? "" : lyric;
}
}
@@ -11,6 +11,7 @@ public class HudOBJ {
public String Music;
public String Lyric;
public String List;
public String Ktv;
public HudOBJ() {
State = "§d[ALLMusic]§2设置信息位置:%Hud%,状态:%State%";
@@ -22,6 +23,7 @@ public class HudOBJ {
PicSize = "§d[ALLMusic]§2设置图片尺寸为%Size%";
Music = "%Name% %AllTime%/%NowTime%\n%Author%\n%Alia%\n%Al%\nby: %Player%";
Lyric = "%Lyric%\n%Tlyric%";
Ktv = "§e%KLyric%§f%Lyric%§r\n%Tlyric%";
List = "播放列表里面有%Size%首歌\n%List%";
}
@@ -46,6 +48,9 @@ public class HudOBJ {
return true;
if (List == null)
return true;
if (Ktv == null)
return true;
return false;
}
@@ -2,19 +2,69 @@ package coloryr.allmusic.objs.music;
import coloryr.allmusic.AllMusic;
import java.util.Map;
public class LyricItemObj {
protected boolean haveT;
protected boolean haveK;
protected String lyric;
protected String tlyric;
protected Map<Integer, Character> klyric;
protected int start;
protected int last;
protected String kly;
protected String lly;
protected int lastIndex = 0;
public LyricItemObj(boolean haveT, String lyric, String tlyric) {
public LyricItemObj(int start, boolean haveT, String lyric, String tlyric,
Map<Integer, Character> klyric, boolean haveK) {
this.start = start;
this.haveT = haveT;
this.lyric = lyric;
this.tlyric = tlyric;
this.klyric = klyric;
this.haveK = haveK;
this.lly = lyric;
if (haveK) {
kly = "";
}
}
public boolean isHaveT() {
return haveT;
public boolean ktv(int time) {
if (last == time || klyric == null)
return false;
Character temp = klyric.get(time - start);
if (temp != null) {
if (lastIndex >= lyric.length()) {
kly = lyric;
lly = "";
} else {
int index = lyric.indexOf(temp, lastIndex);
if (index == lyric.length() - 1) {
kly = lyric;
lly = "";
lastIndex = lyric.length();
} else if (index != -1) {
lastIndex = index + 1;
kly = lyric.substring(0, index + 1);
lly = lyric.substring(index + 1);
}
}
last = time;
return true;
}
return false;
}
public String getKly() {
return kly;
}
public boolean isHaveK() {
return haveK;
}
public String getTlyric() {
@@ -22,7 +72,7 @@ public class LyricItemObj {
}
public String getLyric() {
return lyric;
return lly;
}
public String getString() {
@@ -4,7 +4,7 @@ import coloryr.allmusic.objs.music.LyricItemObj;
public class TopLyricItemObj extends LyricItemObj {
public TopLyricItemObj() {
super(false, null, null);
super(0, false, null, null, null, false);
}
public void setTlyric(String data) {
@@ -15,7 +15,21 @@ public class TopLyricItemObj extends LyricItemObj {
lyric = data;
}
public void setKly(String data) {
kly = data;
}
public void setHaveK(boolean data) {
haveK = data;
if (!haveK) {
kly = null;
}
}
public void setHaveT(boolean data) {
haveT = data;
if (!haveT) {
tlyric = null;
}
}
}
@@ -356,7 +356,20 @@ public class SideBC implements ISide {
out = ByteStreams.newDataOutput();
out.writeInt(9);
out.writeBoolean(PlayMusic.lyricItem != null && PlayMusic.lyricItem.isHaveT());
out.writeBoolean(PlayMusic.lyricItem != null && PlayMusic.lyricItem.getTlyric() != null);
server.sendData(AllMusic.channelBC, out.toByteArray());
out = ByteStreams.newDataOutput();
out.writeInt(10);
if (PlayMusic.lyricItem == null || PlayMusic.lyricItem.getKly() == null)
out.writeUTF("");
else
out.writeUTF(PlayMusic.lyricItem.getTlyric());
server.sendData(AllMusic.channelBC, out.toByteArray());
out = ByteStreams.newDataOutput();
out.writeInt(11);
out.writeBoolean(PlayMusic.lyricItem != null && PlayMusic.lyricItem.getKly() != null);
server.sendData(AllMusic.channelBC, out.toByteArray());
}
@@ -91,6 +91,12 @@ public class PluginMessage implements PluginMessageListener {
case 9:
lyric.setHaveT(in.readBoolean());
break;
case 10:
lyric.setKly(in.readUTF());
break;
case 11:
lyric.setHaveK(in.readBoolean());
break;
}
}
}
@@ -91,6 +91,9 @@ public class AllMusicPAPI extends PlaceholderExpansion {
case "tlyric": {
return PlayMusic.lyricItem.getTlyric();
}
case "klyric": {
return PlayMusic.lyricItem.getKly();
}
}
} else {
switch (identifier) {
@@ -140,6 +143,11 @@ public class AllMusicPAPI extends PlaceholderExpansion {
return "";
return PlayMusic.lyricItem.getTlyric();
}
case "klyric": {
if (PlayMusic.lyricItem == null)
return "";
return PlayMusic.lyricItem.getKly();
}
}
}
return null;
@@ -359,7 +359,20 @@ public class SideVelocity implements ISide {
out = ByteStreams.newDataOutput();
out.writeInt(9);
out.writeBoolean(PlayMusic.lyricItem != null && PlayMusic.lyricItem.isHaveT());
out.writeBoolean(PlayMusic.lyricItem != null && PlayMusic.lyricItem.getTlyric() != null);
server.sendPluginMessage(AllMusicVelocity.channelBC, out.toByteArray());
out = ByteStreams.newDataOutput();
out.writeInt(10);
if (PlayMusic.lyricItem == null || PlayMusic.lyricItem.getKly() == null)
out.writeUTF("");
else
out.writeUTF(PlayMusic.lyricItem.getTlyric());
server.sendPluginMessage(AllMusicVelocity.channelBC, out.toByteArray());
out = ByteStreams.newDataOutput();
out.writeInt(11);
out.writeBoolean(PlayMusic.lyricItem != null && PlayMusic.lyricItem.getKly() != null);
server.sendPluginMessage(AllMusicVelocity.channelBC, out.toByteArray());
}
+2 -1
View File
@@ -49,6 +49,7 @@
"SearchCost": 20,
"AddMusicCost": 10,
"MaxMusicTime": 600,
"KtvMode": true,
"MusicBR": "320000",
"Version": "101"
"Version": "102"
}
+2 -1
View File
@@ -68,6 +68,7 @@
"PicSize": "§d[ALLMusic]§e设置图片尺寸为%Size%",
"Music": "%Name% %AllTime%/%NowTime%\n%Author%\n%Alia%\n%Al%\nby: %Player%",
"Lyric": "%Lyric%\n%Tlyric%",
"Ktv": "§e%KLyric%§f%Lyric%§r\n%Tlyric%",
"List": "播放列表里面有%Size%首歌\n%List%"
},
"Command": {
@@ -122,5 +123,5 @@
"Login": "§d[AllMusic]§e使用/music login 重新登录账户"
}
},
"Version": "101"
"Version": "102"
}
+42
View File
@@ -0,0 +1,42 @@
import coloryr.allmusic.AllMusic;
import coloryr.allmusic.objs.CookieObj;
import coloryr.allmusic.objs.music.LyricItemObj;
import coloryr.allmusic.objs.music.LyricSaveObj;
import coloryr.allmusic.side.IMyLogger;
import java.util.Map;
public class RunTest implements IMyLogger {
public static void main(String[] arg) {
AllMusic.cookie = new CookieObj();
AllMusic.log = new RunTest();
// LyricSaveObj obj = AllMusic.getMusicApi().getLyric("2003496380");
// if(obj.isHaveLyric())
// {
//
// }
LyricSaveObj obj = AllMusic.getMusicApi().getLyric("28151022");
if (obj.isHaveLyric()) {
LyricItemObj item = obj.checkTime(15970);
int time = 0;
while (true) {
boolean res = item.ktv(time);
if (res) {
String temp = item.getKly();
System.out.println(temp);
}
time += 10;
}
}
}
@Override
public void warning(String data) {
}
@Override
public void info(String data) {
}
}