Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f63e172dc | ||
|
|
c0a790a7c4 | ||
|
|
1625bf51e9 | ||
|
|
0d80c249f3 | ||
|
|
57d72cb78d | ||
|
|
af6b75669b | ||
|
|
48f07bdf34 | ||
|
|
01dc1709c4 |
30
README.md
30
README.md
@@ -1,11 +1,10 @@
|
||||
|
||||
pytchat
|
||||
=======
|
||||
|
||||
pytchat is a python library for fetching youtube live chat.
|
||||
|
||||
## Description
|
||||
pytchat is a python library for fetching youtube live chat.
|
||||
pytchat is a python library for fetching youtube live chat
|
||||
without using youtube api, Selenium or BeautifulSoup.
|
||||
|
||||
Other features:
|
||||
@@ -15,12 +14,13 @@ Other features:
|
||||
instead of web scraping.
|
||||
|
||||
## Install
|
||||
```
|
||||
```python
|
||||
pip install pytchat
|
||||
```
|
||||
|
||||
## Examples
|
||||
```
|
||||
### on-demand mode
|
||||
```python
|
||||
from pytchat import LiveChat
|
||||
|
||||
chat = LiveChat("G1w62uEMZ74")
|
||||
@@ -31,12 +31,14 @@ while chat.is_alive():
|
||||
data.tick()
|
||||
```
|
||||
|
||||
callback mode
|
||||
```
|
||||
### callback mode
|
||||
```python
|
||||
from pytchat import LiveChat
|
||||
import time
|
||||
|
||||
chat = LiveChat("G1w62uEMZ74", callback = func)
|
||||
while chat.is_alive():
|
||||
#other background operation here.
|
||||
time.sleep(3)
|
||||
|
||||
def func(chatdata):
|
||||
@@ -45,8 +47,8 @@ def func(chatdata):
|
||||
chat.tick()
|
||||
```
|
||||
|
||||
asyncio context:
|
||||
```
|
||||
### asyncio context:
|
||||
```python
|
||||
from pytchat import LiveChatAsync
|
||||
import asyncio
|
||||
|
||||
@@ -66,8 +68,8 @@ loop.run_until_complete(main())
|
||||
```
|
||||
|
||||
|
||||
yt api compatible processor:
|
||||
```
|
||||
### yt api compatible processor:
|
||||
```python
|
||||
from pytchat import LiveChat, CompatibleProcessor
|
||||
|
||||
chat = LiveChat("G1w62uEMZ74",
|
||||
@@ -113,6 +115,11 @@ Structure of each item which got from items() function.
|
||||
<td>int</td>
|
||||
<td>unixtime milliseconds</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>datetime</td>
|
||||
<td>str</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>amountValue</td>
|
||||
<td>float</td>
|
||||
@@ -188,6 +195,7 @@ Structure of author object.
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## Licence
|
||||
|
||||
[](LICENSE)
|
||||
@@ -195,3 +203,5 @@ Structure of author object.
|
||||
## Author
|
||||
|
||||
[taizan-hokuto](https://github.com/taizan-hokuto)
|
||||
|
||||
[twitter:@taizan205](https://twitter.com/taizan205)
|
||||
@@ -2,7 +2,7 @@
|
||||
pytchat is a python library for fetching youtube live chat.
|
||||
"""
|
||||
__copyright__ = 'Copyright (C) 2019 taizan-hokuto'
|
||||
__version__ = '0.0.1.5'
|
||||
__version__ = '0.0.1.7'
|
||||
__license__ = 'MIT'
|
||||
__author__ = 'taizan-hokuto'
|
||||
__author_email__ = '55448286+taizan-hokuto@users.noreply.github.com'
|
||||
|
||||
@@ -122,7 +122,7 @@ def _build(video_id, _ts1, _ts2, _ts3, _ts4, _ts5, topchatonly = False):
|
||||
)
|
||||
|
||||
|
||||
def _times():
|
||||
def _times(past_sec):
|
||||
|
||||
def unixts_now():
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
@@ -132,12 +132,18 @@ def _times():
|
||||
|
||||
_ts1= n - random.uniform(0,1*3)
|
||||
_ts2= n - random.uniform(0.01,0.99)
|
||||
_ts3= n - 60*60 + random.uniform(0,1)
|
||||
_ts3= n - past_sec + random.uniform(0,1)
|
||||
_ts4= n - random.uniform(10*60,60*60)
|
||||
_ts5= n - random.uniform(0.01,0.99)
|
||||
return list(map(lambda x:int(x*1000000),[_ts1,_ts2,_ts3,_ts4,_ts5]))
|
||||
|
||||
|
||||
def getparam(video_id):
|
||||
return _build(video_id,*_times())
|
||||
def getparam(video_id,past_sec = 60):
|
||||
'''
|
||||
Parameter
|
||||
---------
|
||||
past_sec : int
|
||||
seconds to load past chat data
|
||||
'''
|
||||
return _build(video_id,*_times(past_sec))
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class Chatdata:
|
||||
|
||||
async def tick_async(self):
|
||||
if self.interval == 0:
|
||||
await asyncio.sleep(3)
|
||||
await asyncio.sleep(0.5)
|
||||
return
|
||||
await asyncio.sleep(self.interval/len(self.items))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user