Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.

Commit 4b63d08

Browse files
committed
up
1 parent 0431b2b commit 4b63d08

4 files changed

Lines changed: 61 additions & 87 deletions

File tree

core/hud/AllMusicHud.java

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
import com.coloryr.allmusic.client.core.AllMusicCore;
44
import com.coloryr.allmusic.client.core.objs.SaveOBJ;
5-
import okhttp3.Call;
6-
import okhttp3.OkHttpClient;
7-
import okhttp3.Request;
8-
import okhttp3.Response;
5+
import org.apache.hc.client5.http.classic.HttpClient;
6+
import org.apache.hc.client5.http.classic.methods.HttpGet;
7+
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
8+
import org.apache.hc.client5.http.impl.classic.HttpClients;
9+
import org.apache.hc.core5.http.HttpEntity;
10+
import org.apache.hc.core5.http.HttpEntityContainer;
11+
import org.apache.hc.core5.http.HttpResponse;
12+
import org.apache.hc.core5.http.io.entity.EntityUtils;
913

1014
import javax.imageio.ImageIO;
1115
import java.awt.*;
@@ -31,7 +35,7 @@ public class AllMusicHud {
3135
/**
3236
* 获取Http客户端
3337
*/
34-
private final OkHttpClient client;
38+
private final HttpClient client;
3539
/**
3640
* 图片buffer
3741
*/
@@ -52,10 +56,6 @@ public class AllMusicHud {
5256
*/
5357
private boolean thisRoute;
5458

55-
//请求
56-
private Response response;
57-
private InputStream inputStream;
58-
5959
/**
6060
* 旋转角度
6161
*/
@@ -86,7 +86,7 @@ public AllMusicHud(int size) {
8686
Thread thread = new Thread(this::run);
8787
thread.setName("allmusic_pic");
8888
thread.start();
89-
client = new OkHttpClient();
89+
client = HttpClients.createDefault();
9090
byteBuffer = ByteBuffer.allocateDirect(size * size * 4);
9191
texture = AllMusicCore.bridge.genTexture(size);
9292
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
@@ -113,25 +113,6 @@ private void picRotateTick() {
113113
public void close() {
114114
haveImg = false;
115115
info = list = lyric = "";
116-
getClose();
117-
}
118-
119-
/**
120-
* 网络请求取消
121-
*/
122-
private void getClose() {
123-
try {
124-
if (response != null) {
125-
response.close();
126-
response = null;
127-
}
128-
if (inputStream != null) {
129-
inputStream.close();
130-
inputStream = null;
131-
}
132-
} catch (Exception e) {
133-
e.printStackTrace();
134-
}
135116
}
136117

137118
/**
@@ -141,21 +122,16 @@ private void getClose() {
141122
private void loadPic(String picUrl) {
142123
haveImg = false;
143124
try {
144-
getClose();
145-
146125
while (save == null || needUpload) {
147126
Thread.sleep(200);
148127
}
149128
if (!save.pic.enable) {
150129
return;
151130
}
152131

153-
Request request = new Request.Builder()
154-
.url(picUrl)
155-
.build();
156-
Call call = client.newCall(request);
157-
response = call.execute();
158-
inputStream = response.body().byteStream();
132+
HttpGet request = new HttpGet(picUrl);
133+
HttpEntity entity = client.execute(request, HttpEntityContainer::getEntity);
134+
InputStream inputStream = entity.getContent();
159135
BufferedImage image = resizeImage(ImageIO.read(inputStream), size, size);
160136
int[] pixels = new int[size * size];
161137

@@ -210,14 +186,16 @@ private void loadPic(String picUrl) {
210186

211187
formatAvatarImage.getRGB(0, 0, size,
212188
size, pixels, 0, size);
213-
getClose();
214189
thisRoute = true;
215190
} else {
216191
image.getRGB(0, 0, size, size, pixels, 0, size);
217-
getClose();
218192
thisRoute = false;
219193
}
220194

195+
inputStream.close();
196+
entity.close();
197+
request.clear();
198+
221199
synchronized (byteBuffer) {
222200
for (int h = 0; h < size; h++) {
223201
for (int w = 0; w < size; w++) {

core/player/AllMusicPlayer.java

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
import com.coloryr.allmusic.client.core.player.decoder.flac.FlacDecoder;
77
import com.coloryr.allmusic.client.core.player.decoder.mp3.Mp3Decoder;
88
import com.coloryr.allmusic.client.core.player.decoder.ogg.OggDecoder;
9-
import okhttp3.*;
9+
import org.apache.hc.client5.http.classic.methods.HttpGet;
10+
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
11+
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
12+
import org.apache.hc.client5.http.impl.classic.HttpClients;
13+
import org.apache.hc.core5.http.Header;
14+
import org.apache.hc.core5.http.HttpEntity;
15+
import org.apache.hc.core5.http.ParseException;
16+
import org.apache.hc.core5.http.io.entity.EntityUtils;
1017

1118
import java.net.SocketTimeoutException;
1219
import org.lwjgl.BufferUtils;
@@ -27,10 +34,10 @@ public class AllMusicPlayer extends InputStream {
2734
private final Semaphore semaphore = new Semaphore(0);
2835
private final Semaphore semaphore1 = new Semaphore(0);
2936
private final Queue<ByteBuffer> queue = new ConcurrentLinkedQueue<>();
30-
private OkHttpClient client;
37+
private CloseableHttpClient client;
3138
private String url;
32-
private Request request;
33-
private Response response;
39+
private HttpGet request;
40+
private CloseableHttpResponse response;
3441
private InputStream content;
3542
private boolean isClose = false;
3643
private boolean reload = false;
@@ -48,8 +55,7 @@ public AllMusicPlayer(IntBuffer source) {
4855
try {
4956
this.source = source;
5057
new Thread(this::run, "allmusic_run").start();
51-
client = new OkHttpClient.Builder()
52-
.build();
58+
client = HttpClients.createDefault();
5359
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
5460
service.scheduleAtFixedRate(this::run1, 0, 10, TimeUnit.MILLISECONDS);
5561
} catch (Exception e) {
@@ -71,21 +77,18 @@ public String Get(String url) {
7177
if (url.contains("https://music.163.com/song/media/outer/url?id=")
7278
|| url.contains("http://music.163.com/song/media/outer/url?id=")) {
7379
try {
74-
Request request = new Request.Builder()
75-
.url(url)
76-
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36 Edg/84.0.522.52")
77-
.header("Host", "music.163.com")
78-
.build();
79-
Call call = client.newCall(request);
80-
Response response = call.execute();
81-
if (response.code() == 302) {
82-
String location = response.header("Location");
83-
if (location != null) {
84-
response.close();
85-
return location;
80+
HttpGet request = new HttpGet(url);
81+
request.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36 Edg/84.0.522.52");
82+
request.setHeader("Host", "music.163.com");
83+
try (CloseableHttpResponse response = client.execute(request)) {
84+
int statusCode = response.getCode();
85+
if (statusCode == 302) {
86+
Header locationHeader = response.getFirstHeader("Location");
87+
if (locationHeader != null) {
88+
return locationHeader.getValue();
89+
}
8690
}
8791
}
88-
response.close();
8992
return url;
9093
} catch (Exception e) {
9194
e.printStackTrace();
@@ -116,20 +119,19 @@ public void set(int time) {
116119
public void connect() throws IOException {
117120
getClose();
118121
streamClose();
119-
request = new Request.Builder()
120-
.url(url)
121-
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36 Edg/84.0.522.52")
122-
.header("Range", "bytes=" + local + "-")
123-
.build();
124-
response = client.newCall(request).execute();
125-
if (!response.isSuccessful()) {
126-
throw new IOException("Unexpected code " + response);
122+
request = new HttpGet(url);
123+
request.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36 Edg/84.0.522.52");
124+
request.setHeader("Range", "bytes=" + local + "-");
125+
response = client.execute(request);
126+
int statusCode = response.getCode();
127+
if (statusCode < 200 || statusCode >= 300) {
128+
throw new IOException("Unexpected code " + statusCode);
127129
}
128-
ResponseBody body = response.body();
129-
if (body == null) {
130-
throw new IOException("Response body is null");
130+
HttpEntity entity = response.getEntity();
131+
if (entity == null) {
132+
throw new IOException("Response entity is null");
131133
}
132-
content = body.byteStream();
134+
content = entity.getContent();
133135
}
134136

135137
private void run() {
@@ -302,10 +304,13 @@ public void setMusic(String url) {
302304
}
303305

304306
private void getClose() {
305-
// OkHttp doesn't have an abort method for requests, but we can cancel the call
306-
// Since we store the response, we can close it
307+
// Close the HTTP response if it exists
307308
if (response != null) {
308-
response.close();
309+
try {
310+
response.close();
311+
} catch (IOException e) {
312+
e.printStackTrace();
313+
}
309314
response = null;
310315
}
311316
request = null;

fabric_26_1/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ dependencies {
3737
// Fabric API. This is technically optional, but you probably want it anyway.
3838
implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
3939

40-
// OkHttp3 for HTTP requests
41-
include implementation("com.squareup.okio:okio-jvm:3.16.4")
42-
include implementation("com.squareup.okhttp3:okhttp:5.3.2")
40+
include implementation("org.apache.httpcomponents.client5:httpclient5:5.6")
4341
}
4442

4543
processResources {

forge_1_20_1/build.gradle

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ base {
2424
archivesName = file_name
2525
}
2626

27+
jarJar.enable()
28+
2729
// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17.
2830
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
2931

@@ -164,11 +166,6 @@ repositories {
164166
// flatDir {
165167
// dir 'libs'
166168
// }
167-
168-
maven {
169-
name = 'Kotlin for Forge'
170-
url = 'https://thedarkcolour.github.io/KotlinForForge/'
171-
}
172169
}
173170

174171
dependencies {
@@ -179,13 +176,9 @@ dependencies {
179176
// then special handling is done to allow a setup of a vanilla dependency without the use of an external repository.
180177
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
181178

182-
implementation "thedarkcolour:kotlinforforge:$kff_version"
183-
184-
jarJar(group: 'com.squareup.okhttp3', name: 'okhttp', version: '[5.3.2,6.0)')
185-
jarJar(group: 'com.squareup.okio', name: 'okio-jvm', version: '[3.16.4,4.0)')
179+
jarJar(group: 'org.apache.httpcomponents.client5', name: 'httpclient5', version: '[5.6,6.0)')
186180

187-
implementation('com.squareup.okhttp3:okhttp:5.3.2')
188-
implementation('com.squareup.okio:okio-jvm:3.16.4')
181+
implementation('org.apache.httpcomponents.client5:httpclient5:5.6')
189182

190183
// Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings
191184
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime

0 commit comments

Comments
 (0)