New Tudou danmaku

This commit is contained in:
John Chong 2015-12-26 12:13:12 +08:00
parent 93285afb05
commit f530b3789e

View File

@ -66,6 +66,8 @@ def ProbeCommentFormat(f):
return 'Tudou' return 'Tudou'
elif tmp == '"root":{"total': elif tmp == '"root":{"total':
return 'sH5V' return 'sH5V'
elif tmp.strip().startswith('"result'):
return 'Tudou2'
elif tmp == '<': elif tmp == '<':
tmp = f.read(1) tmp = f.read(1)
if tmp == '?': if tmp == '?':
@ -205,6 +207,26 @@ def ReadCommentsTudou(f, fontsize):
continue continue
def ReadCommentsTudou2(f, fontsize):
comment_element = json.load(f)
for i, comment in enumerate(comment_element['result']):
try:
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)
yield (
int(comment['playat'] * 0.001), int(comment['createtime'] * 0.001), i, c,
{0: 0, 3: 0, 4: 2, 6: 1}[pos],
int(prop.get('color', 0xffffff)), size, (c.count('\n') + 1) * size, CalculateLength(c) * size)
except (AssertionError, AttributeError, IndexError, TypeError, ValueError):
logging.warning(_('Invalid comment: %r') % comment)
continue
def ReadCommentsMioMio(f, fontsize): def ReadCommentsMioMio(f, fontsize):
NiconicoColorMap = {'red': 0xff0000, 'pink': 0xff8080, 'orange': 0xffc000, 'yellow': 0xffff00, 'green': 0x00ff00, 'cyan': 0x00ffff, 'blue': 0x0000ff, 'purple': 0xc000ff, 'black': 0x000000} NiconicoColorMap = {'red': 0xff0000, 'pink': 0xff8080, 'orange': 0xffc000, 'yellow': 0xffff00, 'green': 0x00ff00, 'cyan': 0x00ffff, 'blue': 0x0000ff, 'purple': 0xc000ff, 'black': 0x000000}
dom = xml.dom.minidom.parse(f) dom = xml.dom.minidom.parse(f)
@ -248,7 +270,7 @@ def ReadCommentsSH5V(f, fontsize):
continue continue
CommentFormatMap = {None: None, 'Niconico': ReadCommentsNiconico, 'Acfun': ReadCommentsAcfun, 'Bilibili': ReadCommentsBilibili, 'Tudou': ReadCommentsTudou, 'MioMio': ReadCommentsMioMio, 'sH5V': ReadCommentsSH5V} CommentFormatMap = {None: None, 'Niconico': ReadCommentsNiconico, 'Acfun': ReadCommentsAcfun, 'Bilibili': ReadCommentsBilibili, 'Tudou': ReadCommentsTudou, 'Tudou2': ReadCommentsTudou2, 'MioMio': ReadCommentsMioMio, 'sH5V': ReadCommentsSH5V}
def WriteCommentBilibiliPositioned(f, c, width, height, styleid): def WriteCommentBilibiliPositioned(f, c, width, height, styleid):