diff --git a/README.md b/README.md
index 2ae6c59..3c60adb 100644
--- a/README.md
+++ b/README.md
@@ -40,11 +40,11 @@ while chat.is_alive():
from pytchat import LiveChat
import time
-chat = LiveChat("G1w62uEMZ74", callback = func)
-while chat.is_alive():
- #other background operation here.
- time.sleep(3)
-
+def main()
+ chat = LiveChat("G1w62uEMZ74", callback = func)
+ #other background operation.
+
+#callback function is automatically called periodically.
def func(data):
for c in data.items:
print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}")
@@ -58,10 +58,9 @@ import asyncio
async def main():
chat = LiveChatAsync("G1w62uEMZ74", callback = func)
- while chat.is_alive():
- #other background operation here.
- await asyncio.sleep(3)
+ #other background operation.
+#callback function is automatically called periodically.
async def func(data):
for c in data.items:
print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}")
@@ -96,10 +95,9 @@ import asyncio
async def main():
chat = ReplayChatAsync("G1w62uEMZ74", seektime = 1000, callback = func)
- while chat.is_alive():
#other background operation here.
- await asyncio.sleep(3)
+#callback function is automatically called periodically.
async def func(data):
for count in range(0,len(data.items)):
c= data.items[count]
@@ -107,7 +105,7 @@ async def func(data):
tick=data.items[count+1].timestamp -data.items[count].timestamp
else:
tick=0
- print(f"<{c.timestampText}> [{c.author.name}]-{c.message} {c.amountString}")
+ print(f"<{c.elapsedTime}> [{c.author.name}]-{c.message} {c.amountString}")
await asyncio.sleep(tick/1000)
loop = asyncio.get_event_loop()
@@ -152,7 +150,7 @@ Structure of each item which got from items() function.
str |
ex. "2019-10-10 12:34:56" |
- timestampText |
+ elapsedTime |
str |
elapsed time. (ex. "1:02:27") *Replay Only. |
diff --git a/pytchat/processors/default/renderer/base.py b/pytchat/processors/default/renderer/base.py
index 61e7d4c..e11e42f 100644
--- a/pytchat/processors/default/renderer/base.py
+++ b/pytchat/processors/default/renderer/base.py
@@ -15,9 +15,9 @@ class BaseRenderer:
self.timestamp = int(timestampUsec/1000)
tst = self.renderer.get("timestampText")
if tst:
- self.timestampText = tst.get("simpleText")
+ self.elapsedTime = tst.get("simpleText")
else:
- self.timestampText = ""
+ self.elapsedTime = ""
self.datetime = self.get_datetime(timestampUsec)
self.message = self.get_message(self.renderer)
self.messageEx = self.get_message_ex(self.renderer)
diff --git a/pytchat/processors/default/renderer/paidsticker.py b/pytchat/processors/default/renderer/paidsticker.py
index 5d00bf2..6d89df3 100644
--- a/pytchat/processors/default/renderer/paidsticker.py
+++ b/pytchat/processors/default/renderer/paidsticker.py
@@ -1,12 +1,42 @@
import re
from . import currency
-from .paidmessage import LiveChatPaidMessageRenderer
+from .base import BaseRenderer
+superchat_regex = re.compile(r"^(\D*)(\d{1,3}(,\d{3})*(\.\d*)*\b)$")
-class LiveChatPaidStickerRenderer(LiveChatPaidMessageRenderer):
+class LiveChatPaidStickerRenderer(BaseRenderer):
def __init__(self, item):
super().__init__(item, "superSticker")
+ def get_snippet(self):
+ super().get_snippet()
+
+ self.author.name = self.renderer["authorName"]["simpleText"]
+
+ amountDisplayString, symbol, amount =(
+ self.get_amountdata(self.renderer)
+ )
+ self.message = ""
+ self.amountValue = amount
+ self.amountString = amountDisplayString
+ self.currency = currency.symbols[symbol]["fxtext"] if currency.symbols.get(symbol) else symbol
+ self.bgColor = self.renderer.get("moneyChipBackgroundColor", 0)
+ self.sticker = "https:"+self.renderer["sticker"]["thumbnails"][0]["url"]
+
+
+
+ def get_amountdata(self,renderer):
+ amountDisplayString = renderer["purchaseAmountText"]["simpleText"]
+ m = superchat_regex.search(amountDisplayString)
+ if m:
+ symbol = m.group(1)
+ amount = float(m.group(2).replace(',',''))
+ else:
+ symbol = ""
+ amount = 0.0
+ return amountDisplayString, symbol, amount
+
+