Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13bdf0376b | ||
|
|
b2ffdaec0c | ||
|
|
c85786679f | ||
|
|
c7a7886672 | ||
|
|
12996fb44d | ||
|
|
c884ef7288 | ||
|
|
2cd9e98fc2 |
24
README.md
24
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,15 +105,15 @@ 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()
|
||||
loop.run_until_complete(main())
|
||||
```
|
||||
|
||||
## Chatdata Structure of Default Processor
|
||||
Structure of each item which got from items() function.
|
||||
## Structure of Default Processor
|
||||
Each item can be got with items() function.
|
||||
<table>
|
||||
<tr>
|
||||
<th>name</th>
|
||||
@@ -152,7 +150,7 @@ Structure of each item which got from items() function.
|
||||
<td>str</td>
|
||||
<td>ex. "2019-10-10 12:34:56"</td>
|
||||
</tr>
|
||||
<td>timestampText</td>
|
||||
<td>elapsedTime</td>
|
||||
<td>str</td>
|
||||
<td>elapsed time. (ex. "1:02:27") *Replay Only.</td>
|
||||
</tr>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
pytchat is a python library for fetching youtube live chat without using yt api, Selenium, or BeautifulSoup.
|
||||
"""
|
||||
__copyright__ = 'Copyright (C) 2019 taizan-hokuto'
|
||||
__version__ = '0.0.3.2'
|
||||
__version__ = '0.0.3.4'
|
||||
__license__ = 'MIT'
|
||||
__author__ = 'taizan-hokuto'
|
||||
__author_email__ = '55448286+taizan-hokuto@users.noreply.github.com'
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user