Skip to content

Commit

Permalink
New Tudou danmaku
Browse files Browse the repository at this point in the history
  • Loading branch information
Goshin committed Dec 26, 2015
1 parent 93285af commit f530b37
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion danmaku2ass.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def ProbeCommentFormat(f):
return 'Tudou'
elif tmp == '"root":{"total':
return 'sH5V'
elif tmp.strip().startswith('"result'):
return 'Tudou2'
elif tmp == '<':
tmp = f.read(1)
if tmp == '?':
Expand Down Expand Up @@ -205,6 +207,26 @@ def ReadCommentsTudou(f, fontsize):
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):
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)
Expand Down Expand Up @@ -248,7 +270,7 @@ def ReadCommentsSH5V(f, fontsize):
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):
Expand Down

0 comments on commit f530b37

Please sign in to comment.