chore(BiliApi): 删除冗余代码

This commit is contained in:
ClovertaTheTrilobita 2025-04-11 14:23:04 +08:00
parent 3e67ba4b0c
commit 9ebff09c04

View file

@ -6,7 +6,6 @@ import com.cloverta.webapi.restservice.BiliApi;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
@ -16,12 +15,12 @@ import java.util.*;
@Service @Service
public class BiliApiService { public class BiliApiService {
public static BiliApi getPagesInfo(String bvid) { public BiliApi getPagesInfo(String bvid) {
List<BiliVid> biliVids = new ArrayList<>(); List<BiliVid> biliVids = new ArrayList<>();
HttpURLConnection connection = null; HttpURLConnection connection = null;
InputStream is = null; InputStream is = null;
BufferedReader br = null; BufferedReader br = null;
StringBuffer result = new StringBuffer(); StringBuilder result = new StringBuilder();
try { try {
//创建连接 //创建连接
URL url = new URL(String.format("https://api.bilibili.com/x/web-interface/view?bvid=%s", bvid)); URL url = new URL(String.format("https://api.bilibili.com/x/web-interface/view?bvid=%s", bvid));
@ -55,7 +54,7 @@ public class BiliApiService {
String description = data.optString("desc"); String description = data.optString("desc");
JSONArray pages = data.getJSONArray("pages"); JSONArray pages = data.getJSONArray("pages");
System.out.println(pages.toString()); // System.out.println(pages.toString());
for (int i = 0; i < pages.length(); i++) { for (int i = 0; i < pages.length(); i++) {
JSONObject page = pages.getJSONObject(i); JSONObject page = pages.getJSONObject(i);
@ -101,12 +100,12 @@ public class BiliApiService {
return null; return null;
} }
public static List<BiliVid> appendVidUrl(List<BiliVid> biliVids) { public List<BiliVid> appendVidUrl(List<BiliVid> biliVids) {
for (BiliVid biliVid : biliVids) { for (BiliVid biliVid : biliVids) {
HttpURLConnection connection = null; HttpURLConnection connection = null;
InputStream is = null; InputStream is = null;
BufferedReader br = null; BufferedReader br = null;
StringBuffer result = new StringBuffer(); StringBuilder result = new StringBuilder();
try { try {
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put("bvid", biliVid.getBvId() ); params.put("bvid", biliVid.getBvId() );
@ -138,7 +137,7 @@ public class BiliApiService {
} }
String jsonResponse = result.toString(); String jsonResponse = result.toString();
System.out.println(result); // System.out.println(result);
JSONObject root = new JSONObject(jsonResponse); JSONObject root = new JSONObject(jsonResponse);
JSONObject data = root.getJSONObject("data"); JSONObject data = root.getJSONObject("data");
@ -173,7 +172,7 @@ public class BiliApiService {
return biliVids; return biliVids;
} }
public static BiliApi generateBiliApi(String status, public BiliApi generateBiliApi(String status,
String bvId, String bvId,
String name, String name,
String author, String author,
@ -183,7 +182,7 @@ public class BiliApiService {
return new BiliApi(status, bvId, name, author, imageUrl, description, data); return new BiliApi(status, bvId, name, author, imageUrl, description, data);
} }
public static void main(String[] args) { // public static void main(String[] args) {
System.out.println(getPagesInfo("BV117411r7R1").data().get(0).getUrl()); // System.out.println(getPagesInfo("BV117411r7R1").data().get(0).getUrl());
} // }
} }