Skip to content

Commit

Permalink
added while to ensure success
Browse files Browse the repository at this point in the history
  • Loading branch information
khjxiaogu committed Aug 24, 2020
1 parent cb0a05d commit c2ff546
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,36 @@ public BaiduMusicSource() {

@Override
public MusicInfo get(String keyword) throws Exception {

HttpURLConnection huc=(HttpURLConnection) new URL("http://tingapi.ting.baidu.com/v1/restserver/ting?format=json&calback=&from=webapp_music&method=baidu.ting.search.catalogSug&query="+keyword).openConnection();
JsonObject jo;
HttpURLConnection huc;
do {
huc=(HttpURLConnection) new URL("http://tingapi.ting.baidu.com/v1/restserver/ting?format=json&calback=&from=webapp_music&method=baidu.ting.search.catalogSug&query="+keyword).openConnection();
huc.setRequestProperty("Host","tingapi.ting.baidu.com");
huc.setRequestProperty("Referrer","http://http://music.taihe.com/");
huc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36");
huc.setRequestMethod("GET");
huc.connect();
JsonObject jo=JsonParser.parseString(new String(Utils.readAll(huc.getInputStream()), "UTF-8")).getAsJsonObject();
jo=JsonParser.parseString(new String(Utils.readAll(huc.getInputStream()), "UTF-8")).getAsJsonObject();
}while(jo.get("error_code").getAsInt()!=22000);
String sid=jo.getAsJsonObject()
.getAsJsonObject().get("song").getAsJsonArray().get(0).getAsJsonObject().get("songid")
.getAsString();
huc=(HttpURLConnection) new URL("http://tingapi.ting.baidu.com/v1/restserver/ting?format=json&calback=&from=webapp_music&method=baidu.ting.song.playAAC&songid="+sid).openConnection();
huc.disconnect();
huc=(HttpURLConnection) new URL("http://tingapi.ting.baidu.com/v1/restserver/ting?format=json&calback=&from=webapp_music&method=baidu.ting.song.play&songid="+sid).openConnection();
huc.setRequestProperty("Host","tingapi.ting.baidu.com");
huc.setRequestProperty("Referrer","http://http://music.taihe.com/");
huc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36");
huc.setRequestMethod("GET");
huc.connect();
JsonObject allinfo=JsonParser.parseString(new String(Utils.readAll(huc.getInputStream()), "UTF-8")).getAsJsonObject();
JsonObject sif=allinfo.getAsJsonObject().get("songinfo").getAsJsonObject();
huc.disconnect();
return new MusicInfo(sif.get("title").getAsString(),
sif.get("author").getAsString(),
sif.get("pic_big").getAsString(),
allinfo.get("bitrate").getAsJsonObject().get("file_link").getAsString(),
sif.get("share_url").getAsString(),

"千千静听");
}

Expand Down

0 comments on commit c2ff546

Please sign in to comment.