Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44dc5ff1c3 | ||
|
|
0676ee5c8c | ||
|
|
89ddc0551f | ||
|
|
0a8cd83d41 | ||
|
|
cb505074f7 | ||
|
|
e9e16b2bcc | ||
|
|
c596911901 | ||
|
|
275e1a7aa8 | ||
|
|
737095e7fb | ||
|
|
10d9f76f67 | ||
|
|
34a74f28aa | ||
|
|
c3c4827798 | ||
|
|
e930c75e2d | ||
|
|
d5efede758 | ||
|
|
dc9b067d1d | ||
|
|
940e2a7431 | ||
|
|
8fcb3ab50f | ||
|
|
8ef6474c90 | ||
|
|
5da28e4d89 | ||
|
|
8902955fed | ||
|
|
30429b05a5 | ||
|
|
ca266ef04b | ||
|
|
8891b35dc7 | ||
|
|
0f63e172dc | ||
|
|
c0a790a7c4 | ||
|
|
1625bf51e9 | ||
|
|
0d80c249f3 | ||
|
|
57d72cb78d | ||
|
|
af6b75669b | ||
|
|
48f07bdf34 | ||
|
|
01dc1709c4 |
@@ -1 +1,3 @@
|
|||||||
include requirements.txt
|
include requirements.txt
|
||||||
|
include requirements_test.txt
|
||||||
|
|
||||||
|
|||||||
43
README.md
43
README.md
@@ -1,11 +1,10 @@
|
|||||||
|
|
||||||
pytchat
|
pytchat
|
||||||
=======
|
=======
|
||||||
|
|
||||||
pytchat is a python library for fetching youtube live chat.
|
pytchat is a python library for fetching youtube live chat.
|
||||||
|
|
||||||
## Description
|
## 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.
|
without using youtube api, Selenium or BeautifulSoup.
|
||||||
|
|
||||||
Other features:
|
Other features:
|
||||||
@@ -14,13 +13,18 @@ Other features:
|
|||||||
+ Quick fetching of initial chat data by generating continuation params
|
+ Quick fetching of initial chat data by generating continuation params
|
||||||
instead of web scraping.
|
instead of web scraping.
|
||||||
|
|
||||||
|
For more detailed information, see [wiki](https://github.com/taizan-hokuto/pytchat/wiki)
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
```
|
```python
|
||||||
pip install pytchat
|
pip install pytchat
|
||||||
```
|
```
|
||||||
|
## Demo
|
||||||
|

|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
```
|
### on-demand mode
|
||||||
|
```python
|
||||||
from pytchat import LiveChat
|
from pytchat import LiveChat
|
||||||
|
|
||||||
chat = LiveChat("G1w62uEMZ74")
|
chat = LiveChat("G1w62uEMZ74")
|
||||||
@@ -31,12 +35,14 @@ while chat.is_alive():
|
|||||||
data.tick()
|
data.tick()
|
||||||
```
|
```
|
||||||
|
|
||||||
callback mode
|
### callback mode
|
||||||
```
|
```python
|
||||||
from pytchat import LiveChat
|
from pytchat import LiveChat
|
||||||
|
import time
|
||||||
|
|
||||||
chat = LiveChat("G1w62uEMZ74", callback = func)
|
chat = LiveChat("G1w62uEMZ74", callback = func)
|
||||||
while chat.is_alive():
|
while chat.is_alive():
|
||||||
|
#other background operation here.
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
def func(chatdata):
|
def func(chatdata):
|
||||||
@@ -45,8 +51,8 @@ def func(chatdata):
|
|||||||
chat.tick()
|
chat.tick()
|
||||||
```
|
```
|
||||||
|
|
||||||
asyncio context:
|
### asyncio context:
|
||||||
```
|
```python
|
||||||
from pytchat import LiveChatAsync
|
from pytchat import LiveChatAsync
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
@@ -66,8 +72,8 @@ loop.run_until_complete(main())
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
yt api compatible processor:
|
### yt api compatible processor:
|
||||||
```
|
```python
|
||||||
from pytchat import LiveChat, CompatibleProcessor
|
from pytchat import LiveChat, CompatibleProcessor
|
||||||
|
|
||||||
chat = LiveChat("G1w62uEMZ74",
|
chat = LiveChat("G1w62uEMZ74",
|
||||||
@@ -113,6 +119,11 @@ Structure of each item which got from items() function.
|
|||||||
<td>int</td>
|
<td>int</td>
|
||||||
<td>unixtime milliseconds</td>
|
<td>unixtime milliseconds</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>datetime</td>
|
||||||
|
<td>str</td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>amountValue</td>
|
<td>amountValue</td>
|
||||||
<td>float</td>
|
<td>float</td>
|
||||||
@@ -126,7 +137,12 @@ Structure of each item which got from items() function.
|
|||||||
<tr>
|
<tr>
|
||||||
<td>currency</td>
|
<td>currency</td>
|
||||||
<td>str</td>
|
<td>str</td>
|
||||||
<td>ex. "USD"</td>
|
<td>ISO 4217 currency codes (ex. "USD")</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>bgColor</td>
|
||||||
|
<td>int</td>
|
||||||
|
<td>RGB Int</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>author</td>
|
<td>author</td>
|
||||||
@@ -188,10 +204,13 @@ Structure of author object.
|
|||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
## Licence
|
## Licence
|
||||||
|
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|
||||||
[taizan-hokuto](https://github.com/taizan-hokuto)
|
[taizan-hokuto](https://github.com/taizan-hokuto)
|
||||||
|
|
||||||
|
[twitter:@taizan205](https://twitter.com/taizan205)
|
||||||
@@ -2,17 +2,18 @@
|
|||||||
pytchat is a python library for fetching youtube live chat.
|
pytchat is a python library for fetching youtube live chat.
|
||||||
"""
|
"""
|
||||||
__copyright__ = 'Copyright (C) 2019 taizan-hokuto'
|
__copyright__ = 'Copyright (C) 2019 taizan-hokuto'
|
||||||
__version__ = '0.0.1.5'
|
__version__ = '0.0.2.2'
|
||||||
__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'
|
||||||
__url__ = 'https://github.com/taizan-hokuto'
|
__url__ = 'https://github.com/taizan-hokuto/pytchat'
|
||||||
|
|
||||||
__all__ = ["core_async","core_multithread","processors"]
|
__all__ = ["core_async","core_multithread","processors"]
|
||||||
|
|
||||||
from .api import (
|
from .api import (
|
||||||
LiveChat,
|
LiveChat,
|
||||||
LiveChatAsync,
|
LiveChatAsync,
|
||||||
|
ChatProcessor,
|
||||||
CompatibleProcessor,
|
CompatibleProcessor,
|
||||||
SimpleDisplayProcessor,
|
SimpleDisplayProcessor,
|
||||||
JsonfileArchiveProcessor
|
JsonfileArchiveProcessor
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from .core_async.livechat import LiveChatAsync
|
from .core_async.livechat import LiveChatAsync
|
||||||
from .core_multithread.livechat import LiveChat
|
from .core_multithread.livechat import LiveChat
|
||||||
|
from .processors.chat_processor import ChatProcessor
|
||||||
from .processors.default.processor import DefaultProcessor
|
from .processors.default.processor import DefaultProcessor
|
||||||
from .processors.compatible.processor import CompatibleProcessor
|
from .processors.compatible.processor import CompatibleProcessor
|
||||||
from .processors.simple_display_processor import SimpleDisplayProcessor
|
from .processors.simple_display_processor import SimpleDisplayProcessor
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
class Buffer(asyncio.Queue):
|
class Buffer(asyncio.Queue):
|
||||||
'''
|
'''
|
||||||
チャットデータを格納するバッファの役割を持つLIFOキュー
|
チャットデータを格納するバッファの役割を持つFIFOキュー
|
||||||
|
|
||||||
Parameter
|
Parameter
|
||||||
---------
|
---------
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import aiohttp, asyncio, async_timeout
|
import aiohttp, asyncio
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import queue
|
|||||||
|
|
||||||
class Buffer(queue.Queue):
|
class Buffer(queue.Queue):
|
||||||
'''
|
'''
|
||||||
チャットデータを格納するバッファの役割を持つLIFOキュー
|
チャットデータを格納するバッファの役割を持つFIFOキュー
|
||||||
|
|
||||||
Parameter
|
Parameter
|
||||||
---------
|
---------
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ def _build(video_id, _ts1, _ts2, _ts3, _ts4, _ts5, topchatonly = False):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _times():
|
def _times(past_sec):
|
||||||
|
|
||||||
def unixts_now():
|
def unixts_now():
|
||||||
now = datetime.datetime.now(pytz.utc)
|
now = datetime.datetime.now(pytz.utc)
|
||||||
@@ -132,12 +132,18 @@ def _times():
|
|||||||
|
|
||||||
_ts1= n - random.uniform(0,1*3)
|
_ts1= n - random.uniform(0,1*3)
|
||||||
_ts2= n - random.uniform(0.01,0.99)
|
_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)
|
_ts4= n - random.uniform(10*60,60*60)
|
||||||
_ts5= n - random.uniform(0.01,0.99)
|
_ts5= n - random.uniform(0.01,0.99)
|
||||||
return list(map(lambda x:int(x*1000000),[_ts1,_ts2,_ts3,_ts4,_ts5]))
|
return list(map(lambda x:int(x*1000000),[_ts1,_ts2,_ts3,_ts4,_ts5]))
|
||||||
|
|
||||||
|
|
||||||
def getparam(video_id):
|
def getparam(video_id,past_sec = 60):
|
||||||
return _build(video_id,*_times())
|
'''
|
||||||
|
Parameter
|
||||||
|
---------
|
||||||
|
past_sec : int
|
||||||
|
seconds to load past chat data
|
||||||
|
'''
|
||||||
|
return _build(video_id,*_times(past_sec))
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ class ChatProcessor:
|
|||||||
'''
|
'''
|
||||||
def process(self, chat_components: list):
|
def process(self, chat_components: list):
|
||||||
'''
|
'''
|
||||||
チャットデータの加工を表すインターフェース
|
チャットデータの加工を表すインターフェース。
|
||||||
Listenerから呼び出される。
|
LiveChatオブジェクトから呼び出される。
|
||||||
|
|
||||||
Parameter
|
Parameter
|
||||||
----------
|
----------
|
||||||
chat_components: list<component>
|
chat_components: [LIST:component]
|
||||||
component : dict {
|
component : dict {
|
||||||
"video_id" : str
|
"video_id" : str
|
||||||
動画ID
|
動画ID
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class Chatdata:
|
|||||||
|
|
||||||
async def tick_async(self):
|
async def tick_async(self):
|
||||||
if self.interval == 0:
|
if self.interval == 0:
|
||||||
await asyncio.sleep(3)
|
await asyncio.sleep(0.5)
|
||||||
return
|
return
|
||||||
await asyncio.sleep(self.interval/len(self.items))
|
await asyncio.sleep(self.interval/len(self.items))
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ symbols = {
|
|||||||
"PLN\xa0": {"fxtext": "PLN", "jptext": "ポーランド・ズロチ"},
|
"PLN\xa0": {"fxtext": "PLN", "jptext": "ポーランド・ズロチ"},
|
||||||
"R$": {"fxtext": "BRL", "jptext": "ブラジル・レアル"},
|
"R$": {"fxtext": "BRL", "jptext": "ブラジル・レアル"},
|
||||||
"RUB\xa0": {"fxtext": "RUB", "jptext": "ロシア・ルーブル"},
|
"RUB\xa0": {"fxtext": "RUB", "jptext": "ロシア・ルーブル"},
|
||||||
"SEK\xa0": {"fxtext": "SEK", "jptext": "スウェーデン・クローネ"},
|
"SEK\xa0": {"fxtext": "SEK", "jptext": "スウェーデン・クローナ"},
|
||||||
"£": {"fxtext": "GBP", "jptext": "英・ポンド"},
|
"£": {"fxtext": "GBP", "jptext": "英・ポンド"},
|
||||||
"₩": {"fxtext": "KRW", "jptext": "韓国・ウォン"},
|
"₩": {"fxtext": "KRW", "jptext": "韓国・ウォン"},
|
||||||
"€": {"fxtext": "EUR", "jptext": "欧・ユーロ"},
|
"€": {"fxtext": "EUR", "jptext": "欧・ユーロ"},
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
aiohttp==3.6.0
|
aiohttp
|
||||||
aioresponses==0.6.0
|
pytz
|
||||||
mock==3.0.5
|
requests
|
||||||
mocker==1.1.1
|
urllib3
|
||||||
pytest==5.1.2
|
|
||||||
pytest-mock==1.10.4
|
|
||||||
pytz==2019.2
|
|
||||||
requests==2.22.0
|
|
||||||
urllib3==1.25.3
|
|
||||||
5
requirements_test.txt
Normal file
5
requirements_test.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
aioresponses
|
||||||
|
mock
|
||||||
|
mocker
|
||||||
|
pytest
|
||||||
|
pytest-mock
|
||||||
22
setup.py
22
setup.py
@@ -1,14 +1,18 @@
|
|||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages, Command
|
||||||
from codecs import open
|
from codecs import open
|
||||||
from os import path
|
from os import path, system
|
||||||
import re
|
import re
|
||||||
|
|
||||||
package_name = "pytchat"
|
package_name = "pytchat"
|
||||||
|
|
||||||
root_dir = path.abspath(path.dirname(__file__))
|
root_dir = path.abspath(path.dirname(__file__))
|
||||||
|
|
||||||
def _requires_from_file(filename):
|
def _requirements():
|
||||||
return open(filename).read().splitlines()
|
return [name.rstrip() for name in open(path.join(root_dir, 'requirements.txt')).readlines()]
|
||||||
|
|
||||||
|
def _test_requirements():
|
||||||
|
return [name.rstrip() for name in open(path.join(root_dir, 'requirements_test.txt')).readlines()]
|
||||||
|
|
||||||
|
|
||||||
with open(path.join(root_dir, package_name, '__init__.py')) as f:
|
with open(path.join(root_dir, package_name, '__init__.py')) as f:
|
||||||
init_text = f.read()
|
init_text = f.read()
|
||||||
@@ -27,18 +31,20 @@ assert url
|
|||||||
with open('README.md', encoding='utf-8') as f:
|
with open('README.md', encoding='utf-8') as f:
|
||||||
long_description = f.read()
|
long_description = f.read()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name=package_name,
|
name=package_name,
|
||||||
packages=[package_name],
|
packages=find_packages(),
|
||||||
|
|
||||||
version=version,
|
version=version,
|
||||||
|
|
||||||
url=url,
|
url=url,
|
||||||
author=author,
|
author=author,
|
||||||
author_email=author_email,
|
author_email=author_email,
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type='text/markdown',
|
long_description_content_type='text/markdown',
|
||||||
license=license,
|
license=license,
|
||||||
|
install_requires=_requirements(),
|
||||||
|
tests_require=_test_requirements(),
|
||||||
description="a python library for fetching youtube live chat.",
|
description="a python library for fetching youtube live chat.",
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Natural Language :: Japanese',
|
'Natural Language :: Japanese',
|
||||||
@@ -52,5 +58,5 @@ setup(
|
|||||||
'License :: OSI Approved :: MIT License',
|
'License :: OSI Approved :: MIT License',
|
||||||
],
|
],
|
||||||
keywords='youtube livechat asyncio',
|
keywords='youtube livechat asyncio',
|
||||||
install_requires=_requires_from_file('requirements.txt')
|
|
||||||
)
|
)
|
||||||
Reference in New Issue
Block a user