I wanted to see "Dried Sister! Umaru-chan" seen on Amazon Prime Video along with the comments on Nico Nico Douga.
The comment itself of Nico Nico Douga is
How to get comments on Nico Nico Douga with Python
Get it with and save it in a file called result.xml
.
The essence of the program below is that comments can be displayed in conjunction with the video. Of course, the sense of presence does not match that of Nico Nico Douga, but I have come to enjoy it as it is.
# -*- coding: utf-8 -*-
# For Python 2
import xml.etree.ElementTree as ET
from operator import itemgetter
import time
def vpos_str(vpos):
sec = int(vpos / 100)
return "%02d:%02d:%02d" % (int(sec / 60), sec % 60, vpos % 100)
tree = ET.parse('result.xml')
root = tree.getroot()
chats = [(int(c.attrib["vpos"]), c.text) for c in root.findall("chat") if c.text]
chats = sorted(chats, key=itemgetter(0))
st = int(time.time() * 100)
i = 0
while i < len(chats):
time.sleep(0.01)
t = int(time.time() * 100) - st
while i < len(chats) and chats[i][0] <= t:
print(u"%s %s" % (vpos_str(chats[i][0]), chats[i][1]))
i += 1
00:01:18 Look at
00:01:I bought 55.
00:06:31 !
00:10:91 I charged!
00:11:83 Umaru
00:14:39 Who
00:15:79 Who are you! ??
Recommended Posts