Skip to content

Commit

Permalink
新增功能 #39:延长直播信息查询超时时间;当哔哩哔哩查询超时时,视为主播下播情况处理。
Browse files Browse the repository at this point in the history
  • Loading branch information
nICEnnnnnnnLee committed Apr 22, 2020
1 parent ac635b7 commit 9b18433
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
19 changes: 12 additions & 7 deletions src/main/java/nicelee/bilibili/live/impl/RoomDealerBilibili.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ public RoomInfo getRoomInfo(String shortId) {
String basicInfoUrl = String.format("https://api.live.bilibili.com/room/v1/Room/get_info?id=%s&from=room", shortId);
String jsonStr = util.getContent(basicInfoUrl, headers.getBiliLiveJsonAPIHeaders(Long.parseLong(shortId)), null);
Logger.println(jsonStr);

JSONObject jObj = new JSONObject(jsonStr).getJSONObject("data");
roomInfo.setRoomId("" + jObj.getLong("room_id"));
roomInfo.setUserId(jObj.getLong("uid"));
roomInfo.setTitle(jObj.getString("title"));
roomInfo.setDescription(jObj.getString("description"));// .replaceAll("</?(h4|a|p|span)[^>]*>", " "));
roomInfo.setLiveStatus(jObj.getInt("live_status"));

if(jsonStr.isEmpty()) {
roomInfo.setTitle("网络超时,尚未获得信息");
roomInfo.setLiveStatus(0);
}else {
JSONObject jObj = new JSONObject(jsonStr).getJSONObject("data");
roomInfo.setRoomId("" + jObj.getLong("room_id"));
roomInfo.setUserId(jObj.getLong("uid"));
roomInfo.setTitle(jObj.getString("title"));
roomInfo.setDescription(jObj.getString("description"));// .replaceAll("</?(h4|a|p|span)[^>]*>", " "));
roomInfo.setLiveStatus(jObj.getInt("live_status"));
}

if (roomInfo.getLiveStatus() == 1) {
// 获取该房间的主播信息 - 名称等
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/nicelee/bilibili/util/HttpRequestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public boolean download(String url, String fileName, HashMap<String, String> hea
String urlNameString = url;
URL realUrl = new URL(urlNameString);
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
conn.setConnectTimeout(10000);
conn.setConnectTimeout(20000);
conn.setReadTimeout(120000);
for (Map.Entry<String, String> entry : headers.entrySet()) {
conn.setRequestProperty(entry.getKey(), entry.getValue());
Expand Down Expand Up @@ -258,10 +258,11 @@ public String getContent(String url, HashMap<String, String> headers) {
}

/**
* do a Http Get Not Worked with http stream with Deflate
* do a Http Get.
*
* @param url
* @param headers
* @param listCookie
* @return content, mostly a html page
* @throws IOException
*/
Expand All @@ -272,8 +273,8 @@ public String getContent(String url, HashMap<String, String> headers, List<HttpC
String urlNameString = url;
URL realUrl = new URL(urlNameString);
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
conn.setConnectTimeout(2000);
conn.setReadTimeout(2000);
conn.setConnectTimeout(20000);
conn.setReadTimeout(20000);
for (Map.Entry<String, String> entry : headers.entrySet()) {
conn.setRequestProperty(entry.getKey(), entry.getValue());
// System.out.println(entry.getKey()+ " : " +entry.getValue());
Expand Down

0 comments on commit 9b18433

Please sign in to comment.