You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
danmuparser/src/main/java/AniGamerParser.java

57 lines
1.5 KiB

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.luhuiguo.chinese.ChineseUtils;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import java.io.IOException;
import java.util.List;
public class AniGamerParser implements Parser<JSONObject> {
private static final String INTERFACE_URL ="https://ani.gamer.com.tw/ajax/danmuGet.php";
@Override
public String color(JSONObject content) {
return Integer.parseInt(content.getString("color").replace("#", ""), 16)+"";
}
@Override
public String size(JSONObject content) {
if(content.getIntValue("size")==2){
return "30";
}else{
return "25";
}
}
@Override
public String text(JSONObject content) {
return ChineseUtils.toSimplified(content.getString("text"));
}
@Override
public String style(JSONObject content) {
if(content.getIntValue("position")==2){
return "2";
}else{
return "1";
}
}
@Override
public String time(JSONObject content) {
return (content.getDoubleValue("time")/10)+"";
}
@Override
public List<JSONObject> parse(String playUrl) {
String tstr;
try {
tstr = Jsoup.connect(INTERFACE_URL).ignoreContentType(true).method(Connection.Method.POST).data("sn", playUrl.replaceAll("\\D+","")).execute().body();
} catch (IOException e) {
throw new RuntimeException(e);
}
return JSON.parseArray(tstr).toJavaList(JSONObject.class);
}
}