Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13bdf0376b | ||
|
|
b2ffdaec0c | ||
|
|
c85786679f | ||
|
|
c7a7886672 | ||
|
|
12996fb44d | ||
|
|
c884ef7288 | ||
|
|
2cd9e98fc2 |
26
README.md
26
README.md
@@ -40,11 +40,11 @@ while chat.is_alive():
|
|||||||
from pytchat import LiveChat
|
from pytchat import LiveChat
|
||||||
import time
|
import time
|
||||||
|
|
||||||
chat = LiveChat("G1w62uEMZ74", callback = func)
|
def main()
|
||||||
while chat.is_alive():
|
chat = LiveChat("G1w62uEMZ74", callback = func)
|
||||||
#other background operation here.
|
#other background operation.
|
||||||
time.sleep(3)
|
|
||||||
|
#callback function is automatically called periodically.
|
||||||
def func(data):
|
def func(data):
|
||||||
for c in data.items:
|
for c in data.items:
|
||||||
print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}")
|
print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}")
|
||||||
@@ -58,10 +58,9 @@ import asyncio
|
|||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
chat = LiveChatAsync("G1w62uEMZ74", callback = func)
|
chat = LiveChatAsync("G1w62uEMZ74", callback = func)
|
||||||
while chat.is_alive():
|
#other background operation.
|
||||||
#other background operation here.
|
|
||||||
await asyncio.sleep(3)
|
|
||||||
|
|
||||||
|
#callback function is automatically called periodically.
|
||||||
async def func(data):
|
async def func(data):
|
||||||
for c in data.items:
|
for c in data.items:
|
||||||
print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}")
|
print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}")
|
||||||
@@ -96,10 +95,9 @@ import asyncio
|
|||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
chat = ReplayChatAsync("G1w62uEMZ74", seektime = 1000, callback = func)
|
chat = ReplayChatAsync("G1w62uEMZ74", seektime = 1000, callback = func)
|
||||||
while chat.is_alive():
|
|
||||||
#other background operation here.
|
#other background operation here.
|
||||||
await asyncio.sleep(3)
|
|
||||||
|
|
||||||
|
#callback function is automatically called periodically.
|
||||||
async def func(data):
|
async def func(data):
|
||||||
for count in range(0,len(data.items)):
|
for count in range(0,len(data.items)):
|
||||||
c= data.items[count]
|
c= data.items[count]
|
||||||
@@ -107,15 +105,15 @@ async def func(data):
|
|||||||
tick=data.items[count+1].timestamp -data.items[count].timestamp
|
tick=data.items[count+1].timestamp -data.items[count].timestamp
|
||||||
else:
|
else:
|
||||||
tick=0
|
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)
|
await asyncio.sleep(tick/1000)
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
loop.run_until_complete(main())
|
loop.run_until_complete(main())
|
||||||
```
|
```
|
||||||
|
|
||||||
## Chatdata Structure of Default Processor
|
## Structure of Default Processor
|
||||||
Structure of each item which got from items() function.
|
Each item can be got with items() function.
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>name</th>
|
<th>name</th>
|
||||||
@@ -152,7 +150,7 @@ Structure of each item which got from items() function.
|
|||||||
<td>str</td>
|
<td>str</td>
|
||||||
<td>ex. "2019-10-10 12:34:56"</td>
|
<td>ex. "2019-10-10 12:34:56"</td>
|
||||||
</tr>
|
</tr>
|
||||||
<td>timestampText</td>
|
<td>elapsedTime</td>
|
||||||
<td>str</td>
|
<td>str</td>
|
||||||
<td>elapsed time. (ex. "1:02:27") *Replay Only.</td>
|
<td>elapsed time. (ex. "1:02:27") *Replay Only.</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
pytchat is a python library for fetching youtube live chat without using yt api, Selenium, or BeautifulSoup.
|
pytchat is a python library for fetching youtube live chat without using yt api, Selenium, or BeautifulSoup.
|
||||||
"""
|
"""
|
||||||
__copyright__ = 'Copyright (C) 2019 taizan-hokuto'
|
__copyright__ = 'Copyright (C) 2019 taizan-hokuto'
|
||||||
__version__ = '0.0.3.2'
|
__version__ = '0.0.3.4'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__author__ = 'taizan-hokuto'
|
__author__ = 'taizan-hokuto'
|
||||||
__author_email__ = '55448286+taizan-hokuto@users.noreply.github.com'
|
__author_email__ = '55448286+taizan-hokuto@users.noreply.github.com'
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ class BaseRenderer:
|
|||||||
self.timestamp = int(timestampUsec/1000)
|
self.timestamp = int(timestampUsec/1000)
|
||||||
tst = self.renderer.get("timestampText")
|
tst = self.renderer.get("timestampText")
|
||||||
if tst:
|
if tst:
|
||||||
self.timestampText = tst.get("simpleText")
|
self.elapsedTime = tst.get("simpleText")
|
||||||
else:
|
else:
|
||||||
self.timestampText = ""
|
self.elapsedTime = ""
|
||||||
self.datetime = self.get_datetime(timestampUsec)
|
self.datetime = self.get_datetime(timestampUsec)
|
||||||
self.message = self.get_message(self.renderer)
|
self.message = self.get_message(self.renderer)
|
||||||
self.messageEx = self.get_message_ex(self.renderer)
|
self.messageEx = self.get_message_ex(self.renderer)
|
||||||
|
|||||||
@@ -1,12 +1,42 @@
|
|||||||
import re
|
import re
|
||||||
from . import currency
|
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):
|
def __init__(self, item):
|
||||||
super().__init__(item, "superSticker")
|
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