m13253 / danmaku2ass

Convert comments from Niconico/AcFun/bilibili to ASS format
http://m13253.blogspot.com/2013/11/play-danmaku-offline-danmaku2ass.html
GNU General Public License v3.0
556 stars 92 forks source link

Fix potential type error when processing Tudou danmaku. #32

Closed Goshin closed 8 years ago

Goshin commented 8 years ago

https://github.com/m13253/danmaku2ass/issues/29 里提到,优酷/土豆弹幕的样式以 JSON 字符串放在 propertis 里。

之前的处理是取出并解析,从而得到样式的 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 都用引号包裹。导致上面的 sizeposstr 类型,然后在作为 dict 下标时出错。

所以在取值同时做一次类型转换。 如有必要我可以附上有问题的弹幕样例。

m13253 commented 8 years ago

谢谢你。

这坨代码当年写的时候很糊涂,维护起来难度很大。 所以你能够帮我修好 bug 真是太感谢了。