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.
38 lines
1.1 KiB
38 lines
1.1 KiB
import org.apache.commons.io.FileUtils;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
|
|
public class BuildDanmu<T> {
|
|
private Parser<T> parser;
|
|
|
|
private static final String DANMU_HEADER="<?xml version=\"1.0\" encoding=\"UTF-8\"?><i>\n";
|
|
|
|
public BuildDanmu(Parser<T> parser) {
|
|
this.parser = parser;
|
|
}
|
|
|
|
/**
|
|
* 生成弹幕
|
|
* @param playUrl 播放地址
|
|
* @param filepath 生成路径
|
|
*/
|
|
public void build(String playUrl,String filepath){
|
|
List<T> list=parser.parse(playUrl);
|
|
|
|
File danmuFile=new File(filepath);
|
|
|
|
StringBuffer sb=new StringBuffer(DANMU_HEADER);
|
|
for(T t:list){
|
|
sb.append("<d p=\"").append(parser.time(t)).append(",").append(parser.style(t)).append(",").append(parser.size(t)).append(",").append(parser.color(t))
|
|
.append(",0,0,0,0\">").append(parser.text(t)).append("</d>").append("\n");
|
|
}
|
|
sb.append("</i>");
|
|
try {
|
|
FileUtils.writeStringToFile(danmuFile,sb.toString(),"UTF-8");
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
|