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.
91 lines
2.4 KiB
91 lines
2.4 KiB
import org.dom4j.DocumentException;
|
|
import org.dom4j.Element;
|
|
import org.dom4j.io.SAXReader;
|
|
import org.jsoup.Jsoup;
|
|
import org.jsoup.nodes.Document;
|
|
import org.jsoup.select.Elements;
|
|
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
|
|
public class SohuParser implements Parser<Element> {
|
|
@Override
|
|
public String color(Element content) {
|
|
return content.attributeValue("c");
|
|
}
|
|
|
|
@Override
|
|
public String size(Element content) {
|
|
switch (content.attributeValue("s")) {
|
|
case "l":
|
|
return "30";
|
|
case "m":
|
|
return "25";
|
|
default:
|
|
return "18";
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String text(Element content) {
|
|
return content.getText();
|
|
}
|
|
|
|
@Override
|
|
public String style(Element content) {
|
|
if (content.attributeValue("m").contains("f")) {
|
|
switch (content.attributeValue("p")) {
|
|
case "t":
|
|
case "m":
|
|
return "5";
|
|
default:
|
|
return "4";
|
|
}
|
|
} else if (content.attributeValue("m").contains("l")) {
|
|
switch (content.attributeValue("p")) {
|
|
case "t":
|
|
case "m":
|
|
return "1";
|
|
default:
|
|
return "2";
|
|
}
|
|
} else {
|
|
return "1";
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public String time(Element content) {
|
|
return content.attributeValue("v");
|
|
}
|
|
|
|
@Override
|
|
public List<Element> parse(String playUrl) {
|
|
Document doc;
|
|
try {
|
|
doc = Jsoup.connect(playUrl).get();
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
Elements videosrc=doc.select("meta[property=og:videosrc]");
|
|
if(videosrc.size()!=1){
|
|
throw new RuntimeException("该视频:"+playUrl+"找不到弹幕");
|
|
}
|
|
String vid = videosrc.get(0).attr("content").replaceAll("\\D","");
|
|
|
|
SAXReader reader = new SAXReader();
|
|
|
|
org.dom4j.Document document;
|
|
try {
|
|
document = reader.read("http://cdn.danmu.56.com/xml/2/v_" + vid + ".xml");
|
|
} catch (DocumentException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
|
|
Element d = document.getRootElement().elements("d").get(0);
|
|
|
|
return d.elements("c");
|
|
}
|
|
|
|
}
|
|
|