parent
cab81e36ea
commit
26fe6fdfa0
@ -92,9 +92,11 @@ def ProbeCommentFormat(f):
|
|||||||
f.seek(0)
|
f.seek(0)
|
||||||
return 'Acfun'
|
return 'Acfun'
|
||||||
elif tmp == '{':
|
elif tmp == '{':
|
||||||
tmp = f.read(17)
|
tmp = f.read(14)
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
if tmp == '"root":{"total":"':
|
if tmp == '"status_code":':
|
||||||
|
return 'Tudou'
|
||||||
|
elif tmp == '"root":{"total':
|
||||||
return 'sH5V'
|
return 'sH5V'
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
@ -179,6 +181,25 @@ def ReadCommentsBilibili(f, fontsize):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
def ReadCommentsTudou(f, fontsize):
|
||||||
|
'Output format: [(timeline, timestamp, no, comment, pos, color, size, height, width)]'
|
||||||
|
comment_element = json.load(f)
|
||||||
|
i = 0
|
||||||
|
for comment in comment_element['comment_list']:
|
||||||
|
try:
|
||||||
|
assert comment['pos'] in (3, 4, 6)
|
||||||
|
c = str(comment['data'])
|
||||||
|
assert comment['size'] in (0, 1, 2)
|
||||||
|
size = {0: 0.64, 1: 1, 2: 1.44}[comment['size']]*fontsize
|
||||||
|
yield (int(comment['replay_time']*0.001), int(comment['commit_time']), i, c, {3: 0, 4: 2, 6: 1}[comment['pos']], int(comment['color']), size, (c.count('\n')+1)*size, CalculateLength(c)*size)
|
||||||
|
i += 1
|
||||||
|
except Exception:
|
||||||
|
raise
|
||||||
|
except (AssertionError, AttributeError, IndexError, TypeError, ValueError):
|
||||||
|
logging.warning(_('Invalid comment: %r') % comment)
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
def ReadCommentsSH5V(f, fontsize):
|
def ReadCommentsSH5V(f, fontsize):
|
||||||
'Output format: [(timeline, timestamp, no, comment, pos, color, size, height, width)]'
|
'Output format: [(timeline, timestamp, no, comment, pos, color, size, height, width)]'
|
||||||
comment_element = json.load(f)
|
comment_element = json.load(f)
|
||||||
@ -258,7 +279,7 @@ if __name__ == '__main__':
|
|||||||
comments = []
|
comments = []
|
||||||
for i in args.file:
|
for i in args.file:
|
||||||
with open(i, 'r', encoding='utf-8') as f:
|
with open(i, 'r', encoding='utf-8') as f:
|
||||||
CommentProcesser = {None: None, 'Niconico': ReadCommentsNiconico, 'Acfun': ReadCommentsAcfun, 'Bilibili': ReadCommentsBilibili, 'sH5V': ReadCommentsSH5V}[ProbeCommentFormat(f)]
|
CommentProcesser = {None: None, 'Niconico': ReadCommentsNiconico, 'Acfun': ReadCommentsAcfun, 'Bilibili': ReadCommentsBilibili, 'Tudou': ReadCommentsTudou, 'sH5V': ReadCommentsSH5V}[ProbeCommentFormat(f)]
|
||||||
if not CommentProcesser:
|
if not CommentProcesser:
|
||||||
raise ValueError(_('Unknown comment file format: %s') % i)
|
raise ValueError(_('Unknown comment file format: %s') % i)
|
||||||
for comment in CommentProcesser(f, args.fontsize):
|
for comment in CommentProcesser(f, args.fontsize):
|
||||||
|
Loading…
Reference in New Issue
Block a user