Closed Goshin closed 8 years ago
如 https://github.com/m13253/danmaku2ass/issues/29 里提到,优酷/土豆弹幕的样式以 JSON 字符串放在 propertis 里。
propertis
之前的处理是取出并解析,从而得到样式的 dict。
dict
c = str(comment['content']) prop = json.loads(str(comment['propertis']) or '{}') size = prop.get('size', 1) assert size in (0, 1, 2) size = {0: 0.64, 1: 1, 2: 1.44}[size] * fontsize pos = prop.get('pos', 3) assert pos in (0, 3, 4, 6)
在转换土豆的弹幕时没什么问题,但是我在转换优酷的弹幕时发现,有些弹幕 propertis 的 JSON,value 都用引号包裹。导致上面的 size 和 pos 为 str 类型,然后在作为 dict 下标时出错。
size
pos
str
所以在取值同时做一次类型转换。 如有必要我可以附上有问题的弹幕样例。
谢谢你。
这坨代码当年写的时候很糊涂,维护起来难度很大。 所以你能够帮我修好 bug 真是太感谢了。
如 https://github.com/m13253/danmaku2ass/issues/29 里提到,优酷/土豆弹幕的样式以 JSON 字符串放在
propertis
里。之前的处理是取出并解析,从而得到样式的
dict
。在转换土豆的弹幕时没什么问题,但是我在转换优酷的弹幕时发现,有些弹幕
propertis
的 JSON,value 都用引号包裹。导致上面的size
和pos
为str
类型,然后在作为dict
下标时出错。所以在取值同时做一次类型转换。 如有必要我可以附上有问题的弹幕样例。