mirror of
https://github.com/Coloryr/AllMusic.git
synced 2026-11-27 05:02:57 +00:00
1.14.0
This commit is contained in:
1 parent
3d88d0ba3d
commit
8040601bed
13 files changed
+520
-10
No files matched your search
+1
-1
@@ -6,7 +6,7 @@ plugins {
|
||||
// Note the spaces before and after the equals sign
|
||||
ext.majorVersion = 0
|
||||
ext.minorVersion = 1
|
||||
version = "1.13.3"
|
||||
version = "1.14.0"
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
|
||||
@@ -4,6 +4,7 @@ import Color_yr.ALLMusic.Message.MessageOBJ;
|
||||
import Color_yr.ALLMusic.MusicAPI.IMusic;
|
||||
import Color_yr.ALLMusic.MusicAPI.MusicAPI1.API1;
|
||||
import Color_yr.ALLMusic.MusicAPI.MusicAPI2.API2;
|
||||
import Color_yr.ALLMusic.MusicAPI.MusicAPILocal.APILocal;
|
||||
import Color_yr.ALLMusic.MusicAPI.SongSearch.SearchPage;
|
||||
import Color_yr.ALLMusic.Side.ISide;
|
||||
import Color_yr.ALLMusic.Side.SideBukkit.VVGet;
|
||||
@@ -19,7 +20,7 @@ import java.util.logging.Logger;
|
||||
|
||||
public class ALLMusic {
|
||||
public static final String channel = "allmusic:channel";
|
||||
public static final String Version = "1.13.3";
|
||||
public static final String Version = "1.14.0";
|
||||
|
||||
private static final Map<String, SearchPage> SearchSave = new HashMap<>();
|
||||
private static final List<String> VotePlayer = new ArrayList<>();
|
||||
@@ -151,13 +152,17 @@ public class ALLMusic {
|
||||
|
||||
private static void initAPI() {
|
||||
switch (ALLMusic.Config.getMusic_Api()) {
|
||||
case 2: {
|
||||
case 3: {
|
||||
ALLMusic.Music = new API2();
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
ALLMusic.Music = new API1();
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
default: {
|
||||
ALLMusic.Music = new API1();
|
||||
ALLMusic.Music = new APILocal();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class API1 implements IMusic {
|
||||
public boolean isUpdata;
|
||||
|
||||
public API1() {
|
||||
ALLMusic.log.info("§d[ALLMusic]§e使用API1");
|
||||
ALLMusic.log.info("§d[ALLMusic]§e使用外置爬虫1");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,7 +98,7 @@ public class API1 implements IMusic {
|
||||
if (temp.Check(obj)) {
|
||||
ALLMusic.log.warning("§d[ALLMusic]§c歌词解析错误,正在进行第" + times + "重试");
|
||||
} else {
|
||||
if(temp.isHave) {
|
||||
if (temp.isHave) {
|
||||
Lyric.setHaveLyric(ALLMusic.getConfig().isSendLyric());
|
||||
Lyric.setLyric(temp.getTemp());
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class API2 implements IMusic {
|
||||
public boolean isUpdata;
|
||||
|
||||
public API2() {
|
||||
ALLMusic.log.info("§d[ALLMusic]§e使用API2");
|
||||
ALLMusic.log.info("§d[ALLMusic]§e使用外置爬虫2");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,7 +98,7 @@ public class API2 implements IMusic {
|
||||
if (temp.Check(obj)) {
|
||||
ALLMusic.log.warning("§d[ALLMusic]§c歌词解析错误,正在进行第" + times + "重试");
|
||||
} else {
|
||||
if(temp.isHave) {
|
||||
if (temp.isHave) {
|
||||
Lyric.setHaveLyric(ALLMusic.getConfig().isSendLyric());
|
||||
Lyric.setLyric(temp.getTemp());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
package Color_yr.ALLMusic.MusicAPI.MusicAPILocal;
|
||||
|
||||
import Color_yr.ALLMusic.ALLMusic;
|
||||
import Color_yr.ALLMusic.Http.HttpGet;
|
||||
import Color_yr.ALLMusic.Http.Res;
|
||||
import Color_yr.ALLMusic.MusicAPI.IMusic;
|
||||
import Color_yr.ALLMusic.MusicAPI.MusicAPILocal.GetMusicInfo.InfoOBJ;
|
||||
import Color_yr.ALLMusic.MusicAPI.MusicAPILocal.GetMusicList.DataOBJ;
|
||||
import Color_yr.ALLMusic.MusicAPI.MusicAPILocal.GetMusicLyric.LyricOBJ;
|
||||
import Color_yr.ALLMusic.MusicAPI.MusicAPILocal.GetMusicSearch.PostSearch;
|
||||
import Color_yr.ALLMusic.MusicAPI.MusicAPILocal.GetMusicSearch.SearchDataOBJ;
|
||||
import Color_yr.ALLMusic.MusicAPI.MusicAPILocal.GetMusicSearch.songs;
|
||||
import Color_yr.ALLMusic.MusicAPI.SongInfo.SongInfo;
|
||||
import Color_yr.ALLMusic.MusicAPI.SongLyric.LyricDo;
|
||||
import Color_yr.ALLMusic.MusicAPI.SongLyric.LyricSave;
|
||||
import Color_yr.ALLMusic.MusicAPI.SongSearch.SearchOBJ;
|
||||
import Color_yr.ALLMusic.MusicAPI.SongSearch.SearchPage;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class APILocal implements IMusic {
|
||||
|
||||
public int PlayNow = 0;
|
||||
public boolean isUpdata;
|
||||
|
||||
public APILocal() {
|
||||
ALLMusic.log.info("§d[ALLMusic]§e使用内置API爬虫");
|
||||
}
|
||||
|
||||
@Override
|
||||
public SongInfo GetMusic(String ID, String player, boolean isList) {
|
||||
Res res = HttpGet.realData("http://music.163.com/api/song/detail/?ids=%5B", ID + "]");
|
||||
SongInfo info = null;
|
||||
if (res != null && res.isOk()) {
|
||||
InfoOBJ temp = new Gson().fromJson(res.getData(), InfoOBJ.class);
|
||||
if (temp.isok()) {
|
||||
info = new SongInfo(temp.getAuthor(), temp.getName(),
|
||||
ID, temp.getAlia(), player, temp.getAl(), isList, temp.getLength());
|
||||
} else {
|
||||
ALLMusic.log.warning("§d[ALLMusic]§c歌曲信息获取为空");
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String GetPlayUrl(String ID) {
|
||||
return "http://music.163.com/song/media/outer/url?id=" + ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetList(String ID, Object sender) {
|
||||
Thread thread = new Thread(() ->
|
||||
{
|
||||
Res res = HttpGet.realData(ALLMusic.getConfig().getMusic_Api2() + "/playlist/detail?id=", ID);
|
||||
if (res != null && res.isOk())
|
||||
try {
|
||||
isUpdata = true;
|
||||
DataOBJ obj = new Gson().fromJson(res.getData(), DataOBJ.class);
|
||||
ALLMusic.getConfig().getPlayList().addAll(obj.getPlaylist());
|
||||
ALLMusic.save();
|
||||
ALLMusic.Side.SendMessaget(sender, ALLMusic.getMessage().getMusicPlay().getListMusic().getGet().replace("%ListName%", obj.getName()));
|
||||
} catch (Exception e) {
|
||||
ALLMusic.log.warning("§d[ALLMusic]§c歌曲列表获取错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
isUpdata = false;
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LyricSave getLyric(String ID) {
|
||||
LyricSave Lyric = new LyricSave();
|
||||
Res res = HttpGet.realData("http://music.163.com/api/song/lyric?os=pc&lv=-1&kv=-1&tv=-1&id=", ID);
|
||||
if (res != null && res.isOk()) {
|
||||
try {
|
||||
LyricOBJ obj = new Gson().fromJson(res.getData(), LyricOBJ.class);
|
||||
LyricDo temp = new LyricDo();
|
||||
for (int times = 0; times < 3; times++) {
|
||||
if (temp.Check(obj)) {
|
||||
ALLMusic.log.warning("§d[ALLMusic]§c歌词解析错误,正在进行第" + times + "重试");
|
||||
} else {
|
||||
if (temp.isHave) {
|
||||
Lyric.setHaveLyric(ALLMusic.getConfig().isSendLyric());
|
||||
Lyric.setLyric(temp.getTemp());
|
||||
}
|
||||
return Lyric;
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
ALLMusic.log.warning("§d[ALLMusic]§c歌词解析失败");
|
||||
} catch (Exception e) {
|
||||
ALLMusic.log.warning("§d[ALLMusic]§c歌词解析错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return Lyric;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchPage Search(String[] name) {
|
||||
List<SearchOBJ> resData = new ArrayList<>();
|
||||
int maxpage;
|
||||
|
||||
StringBuilder name1 = new StringBuilder();
|
||||
for (int a = 1; a < name.length; a++) {
|
||||
name1.append(name[a]).append(" ");
|
||||
}
|
||||
String MusicName = name1.toString();
|
||||
MusicName = MusicName.substring(0, MusicName.length() - 1);
|
||||
Res res = PostSearch.realData(MusicName);
|
||||
if (res != null && res.isOk()) {
|
||||
SearchDataOBJ obj = new Gson().fromJson(res.getData(), SearchDataOBJ.class);
|
||||
if (obj != null && obj.isok()) {
|
||||
List<songs> res1 = obj.getResult();
|
||||
SearchOBJ item;
|
||||
for (songs temp : res1) {
|
||||
item = new SearchOBJ(String.valueOf(temp.getId()), temp.getName(), temp.getArtists(), temp.getAlbum());
|
||||
resData.add(item);
|
||||
}
|
||||
maxpage = res1.size() / 10;
|
||||
return new SearchPage(resData, maxpage);
|
||||
} else {
|
||||
ALLMusic.log.warning("§d[ALLMusic]§c歌曲搜索出现错误");
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String GetListMusic() {
|
||||
if (!isUpdata && ALLMusic.getConfig().getPlayList().size() != 0) {
|
||||
String ID;
|
||||
if (ALLMusic.getConfig().isPlayListRandom()) {
|
||||
ID = ALLMusic.getConfig().getPlayList().get(new Random().nextInt(ALLMusic.getConfig().getPlayList().size() - 1));
|
||||
} else {
|
||||
ID = ALLMusic.getConfig().getPlayList().get(PlayNow);
|
||||
if (PlayNow == ALLMusic.getConfig().getPlayList().size())
|
||||
PlayNow = 0;
|
||||
else
|
||||
PlayNow++;
|
||||
}
|
||||
return ID;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package Color_yr.ALLMusic.MusicAPI.MusicAPILocal.GetMusicInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class InfoOBJ {
|
||||
private List<Songs> songs;
|
||||
|
||||
public boolean isok() {
|
||||
return (songs != null && songs.size() != 0);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if (songs == null || songs.size() == 0)
|
||||
return null;
|
||||
return songs.get(0).getName();
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
StringBuilder Author = new StringBuilder();
|
||||
if (songs.size() == 0)
|
||||
return null;
|
||||
for (Color_yr.ALLMusic.MusicAPI.MusicAPILocal.GetMusicInfo.ar ar : songs.get(0).getAr()) {
|
||||
Author.append(ar.getName()).append(",");
|
||||
}
|
||||
if (Author.length() != 0) {
|
||||
Author = new StringBuilder(Author.substring(0, Author.length() - 1));
|
||||
}
|
||||
return Author.toString();
|
||||
}
|
||||
|
||||
public String getAlia() {
|
||||
StringBuilder Alia = new StringBuilder();
|
||||
for (String alia : songs.get(0).getAlia()) {
|
||||
Alia.append(alia).append(",");
|
||||
}
|
||||
if (Alia.length() != 0) {
|
||||
Alia = new StringBuilder(Alia.substring(0, Alia.length() - 1));
|
||||
}
|
||||
return Alia.toString();
|
||||
}
|
||||
|
||||
public String getAl() {
|
||||
return songs.get(0).getAl();
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
if (songs == null)
|
||||
return 0;
|
||||
return songs.get(0).getLength();
|
||||
}
|
||||
}
|
||||
|
||||
class Songs {
|
||||
private String name;
|
||||
private List<ar> artists;
|
||||
private List<String> alias;
|
||||
private al album;
|
||||
private h hMusic;
|
||||
private h mMusic;
|
||||
private h lMusic;
|
||||
|
||||
public int getLength() {
|
||||
if (hMusic != null)
|
||||
return hMusic.getLength();
|
||||
if (mMusic != null)
|
||||
return mMusic.getLength();
|
||||
if (lMusic != null)
|
||||
return lMusic.getLength();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<ar> getAr() {
|
||||
return artists;
|
||||
}
|
||||
|
||||
public List<String> getAlia() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
public String getAl() {
|
||||
return album.getName();
|
||||
}
|
||||
}
|
||||
|
||||
class ar {
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
class al {
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
class h {
|
||||
private int playTime;
|
||||
|
||||
public int getLength() {
|
||||
return playTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package Color_yr.ALLMusic.MusicAPI.MusicAPILocal.GetMusicInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PlayOBJ {
|
||||
private List<obj> data;
|
||||
private int code;
|
||||
|
||||
public String getData() {
|
||||
if (data == null)
|
||||
return null;
|
||||
if (data.size() == 0)
|
||||
return null;
|
||||
obj obj = data.get(0);
|
||||
return obj.getUrl();
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
class obj {
|
||||
private String url;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package Color_yr.ALLMusic.MusicAPI.MusicAPILocal.GetMusicList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DataOBJ {
|
||||
private result result;
|
||||
|
||||
public List<String> getPlaylist() {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (track item : result.getTracks()) {
|
||||
list.add(item.getId());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return result.getName();
|
||||
}
|
||||
}
|
||||
|
||||
class track {
|
||||
private int id;
|
||||
|
||||
public String getId() {
|
||||
return String.valueOf(id);
|
||||
}
|
||||
}
|
||||
|
||||
class result {
|
||||
private List<track> tracks;
|
||||
private String name;
|
||||
|
||||
public List<track> getTracks() {
|
||||
return tracks;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package Color_yr.ALLMusic.MusicAPI.MusicAPILocal.GetMusicLyric;
|
||||
|
||||
import Color_yr.ALLMusic.MusicAPI.SongLyric.Lyric;
|
||||
|
||||
public class LyricOBJ implements Lyric {
|
||||
private lrc lrc;
|
||||
private tlyric tlyric;
|
||||
private boolean nolyric;
|
||||
private boolean uncollected;
|
||||
|
||||
public boolean isok() {
|
||||
return lrc != null || isNone();
|
||||
}
|
||||
|
||||
public String getLyric() {
|
||||
return lrc.getLyric();
|
||||
}
|
||||
|
||||
public String getTlyric() {
|
||||
return tlyric.getLyric();
|
||||
}
|
||||
|
||||
public boolean isNone() {
|
||||
return nolyric || uncollected;
|
||||
}
|
||||
}
|
||||
|
||||
class lrc {
|
||||
private String lyric;
|
||||
|
||||
public String getLyric() {
|
||||
return lyric == null ? "" : lyric;
|
||||
}
|
||||
}
|
||||
|
||||
class tlyric {
|
||||
private String lyric;
|
||||
|
||||
public String getLyric() {
|
||||
return lyric;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package Color_yr.ALLMusic.MusicAPI.MusicAPILocal.GetMusicSearch;
|
||||
|
||||
import Color_yr.ALLMusic.ALLMusic;
|
||||
import Color_yr.ALLMusic.Http.Res;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class PostSearch {
|
||||
public static Res realData(String ID) {
|
||||
try {
|
||||
ID = URLEncoder.encode(ID, "UTF-8");
|
||||
URL realUrl = new URL("http://music.163.com/api/search/get/web?csrf_token=");
|
||||
HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setConnectTimeout(4 * 1000);
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestProperty("Host", "music.163.com");
|
||||
connection.setRequestProperty("Origin", "http://music.163.com");
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36");
|
||||
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
connection.setRequestProperty("Referer", "http://music.163.com/search/");
|
||||
|
||||
OutputStream out = connection.getOutputStream();
|
||||
String PostData = "type=1&offset=0&limit=50&s=" + ID;
|
||||
connection.connect();
|
||||
out.write(PostData.getBytes());
|
||||
out.flush();
|
||||
out.close();
|
||||
InputStream inputStream;
|
||||
boolean ok;
|
||||
if (connection.getResponseCode() >= 400) {
|
||||
inputStream = connection.getErrorStream();
|
||||
ok = false;
|
||||
} else {
|
||||
inputStream = connection.getInputStream();
|
||||
ok = true;
|
||||
}
|
||||
ByteArrayOutputStream result = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = inputStream.read(buffer)) != -1) {
|
||||
result.write(buffer, 0, length);
|
||||
}
|
||||
String data1 = result.toString(StandardCharsets.UTF_8.name());
|
||||
if (!ok) {
|
||||
ALLMusic.log.warning("§c服务器返回错误:" + data1);
|
||||
}
|
||||
return new Res(data1, ok);
|
||||
} catch (Exception e) {
|
||||
ALLMusic.log.warning("§c获取网页错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package Color_yr.ALLMusic.MusicAPI.MusicAPILocal.GetMusicSearch;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SearchDataOBJ {
|
||||
private result result;
|
||||
|
||||
public boolean isok() {
|
||||
return result != null && result.getSongs() != null;
|
||||
}
|
||||
|
||||
public List<songs> getResult() {
|
||||
return result.getSongs();
|
||||
}
|
||||
}
|
||||
|
||||
class result {
|
||||
private List<songs> songs;
|
||||
|
||||
public List<songs> getSongs() {
|
||||
return songs;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class artists {
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
class album {
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package Color_yr.ALLMusic.MusicAPI.MusicAPILocal.GetMusicSearch;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class songs {
|
||||
private int id;
|
||||
private String name;
|
||||
private List<artists> artists;
|
||||
private album album;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getAlbum() {
|
||||
return album.getName();
|
||||
}
|
||||
|
||||
public String getArtists() {
|
||||
StringBuilder a = new StringBuilder();
|
||||
for (artists temp : artists) {
|
||||
a.append(temp.getName()).append(",");
|
||||
}
|
||||
return a.substring(0, a.length() - 1);
|
||||
}
|
||||
}
|
||||
@@ -7,14 +7,13 @@ import java.util.*;
|
||||
|
||||
public class LyricDo {
|
||||
|
||||
public boolean isHave = false;
|
||||
private Map<Integer, ShowOBJ> temp = new HashMap<>();
|
||||
|
||||
public Map<Integer, ShowOBJ> getTemp() {
|
||||
return temp;
|
||||
}
|
||||
|
||||
public boolean isHave = false;
|
||||
|
||||
public boolean Check(Lyric obj) {
|
||||
String[] lyric;
|
||||
|
||||
|
||||
Reference in new issue
Block a user