HFrost0 / danmakuC

Faster conversion for larger Danmaku to Ass format with C++ and Python interface
GNU General Public License v3.0
26 stars 6 forks source link

xml格式的支持 #11

Open Heporis opened 1 year ago

Heporis commented 1 year ago

能不能改进识别方法,多增加一些xml格式的支持啊?DanmakuFactory支持好多 像下面这些danmakuc都会报错 image image

HFrost0 commented 1 year ago

实现起来挺简单的,只是暂时没时间做

HFrost0 commented 1 year ago

如果有人感兴趣想提pr的话,可以参考b站适配中的proto2ass函数,一个新的适配只需要写一点这种python代码即可

    # 1. 初始化ass对象
    ass = Ass(width, height, reserve_blank, font_face, font_size, alpha, duration_marquee,
                  duration_still, comment_filter, reduced)
    #  2.读取源文件,例如proto,xml等
    if isinstance(proto_file, io.IOBase):
        proto_file = proto_file.read()
    target = BiliCommentProto()
    target.ParseFromString(proto_file)
    # elem.mode > 8, example: https://www.bilibili.com/video/BV1Js411f78P/
    mode_map = {1: 0, 4: 2, 5: 1, 6: 3, 7: 4}
    # 3. 把每一条弹幕加到ass对象中
    for elem in target.elems:
        if elem.mode not in mode_map:
            continue
        try:
            ass.add_comment(
                elem.progress / 1000,  # 视频内出现的时间
                elem.ctime,  # 弹幕的发送时间(时间戳)
                elem.content,
                elem.fontsize,
                mode_map[elem.mode],
                elem.color,
            )
        except TypeError:
            # TypeError: incase integer overflow https://github.com/HFrost0/bilix/issues/102
            continue
    # 4.ass对象转字符串写入文件
    if out_filename:
        return ass.write_to_file(out_filename)
    else:
        return ass.to_string()
LifeJustDLC commented 4 months ago

@Heporis https://github.com/yutto-dev/yutto 优点:端到端;缺点:用户验证体验糟糕