Skip to content

Commit

Permalink
support radio
Browse files Browse the repository at this point in the history
  • Loading branch information
khjxiaogu committed Oct 25, 2021
1 parent 3a2fe01 commit a240e77
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.khjxiaogu</groupId>
<artifactId>MiraiSongPlugin</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
<name>MiraiSongPlugin</name>
<description>使用“#音乐 关键词”、“#QQ 关键词”、“#网易 关键词”等方式进行点歌的插件。</description>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Map;

import com.khjxiaogu.MiraiSongPlugin.MusicCardProvider;
Expand All @@ -32,13 +33,12 @@ public AmrVoiceProvider() {

@Override
public Message process(MusicInfo mi, Contact ct) {
HttpURLConnection huc2 = null;
URLConnection huc2 = null;
try {
huc2 = (HttpURLConnection) new URL(mi.murl).openConnection();
huc2 = new URL(mi.murl).openConnection();
if (mi.properties != null)
for (Map.Entry<String, String> me : mi.properties.entrySet())
huc2.addRequestProperty(me.getKey(), me.getValue());
huc2.setRequestMethod("GET");
huc2.connect();
} catch (IOException e) {
return new PlainText("获取音频失败");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

import com.google.gson.JsonArray;
Expand Down Expand Up @@ -93,7 +94,17 @@ public MusicInfo get(String keyword) throws Exception {

public MusicInfo get(String keyword, String songname) throws Exception {

URL url = new URL("http://music.163.com/api/search/pc");
JsonObject params = new JsonObject();
params.add("s", new JsonPrimitive(URLDecoder.decode(keyword, "UTF-8")));
params.add("type",new JsonPrimitive(1009));
params.add("offset",new JsonPrimitive(0));
params.add("limit",new JsonPrimitive(3));
String[] encrypt = NetEaseCrypto.weapiEncrypt(params.toString());
StringBuilder sb = new StringBuilder("params=");
sb.append(encrypt[0]);
sb.append("&encSecKey=");
sb.append(encrypt[1]);
URL url = new URL("https://music.163.com/weapi/cloudsearch/get/web?csrf_token=");
HttpURLConnection huc = (HttpURLConnection) url.openConnection();
huc.setDoInput(true);
huc.setDoOutput(true);
Expand All @@ -102,8 +113,7 @@ public MusicInfo get(String keyword, String songname) throws Exception {
huc.setRequestProperty("Cookie", "appver=1.5.0.75771;");
huc.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
huc.connect();

huc.getOutputStream().write(("type=1009&offset=0&limit=1&s=" + keyword).getBytes(StandardCharsets.UTF_8));
huc.getOutputStream().write(sb.toString().getBytes(StandardCharsets.UTF_8));
JsonArray ja;
String murl;
if (huc.getResponseCode() == 200) {
Expand Down

0 comments on commit a240e77

Please sign in to comment.