Compare commits

...

13 Commits

Author SHA1 Message Date
taizan-hokuto
fb0edef136 Merge branch 'release/v0.0.5.0' 2020-01-13 09:38:10 +09:00
taizan-hokuto
e03d39475e Increment version 2020-01-13 09:37:34 +09:00
taizan-hokuto
2462b8aca0 Merge branch 'hotfix/fix_defaultprocessor_display_amount' 2020-01-13 08:19:42 +09:00
taizan-hokuto
a1024c8734 Merge tag 'fix_defaultprocessor_display_amount' into develop 2020-01-13 08:19:42 +09:00
taizan-hokuto
6b3ca00d35 Fix superchat/sticker display amount 2020-01-13 08:19:03 +09:00
taizan-hokuto
385634b709 Fix MANIFEST.in 2020-01-12 14:55:29 +09:00
taizan-hokuto
c1a78a2743 Fix setup.py 2020-01-12 14:40:26 +09:00
taizan-hokuto
7961801e0c Increment version 2020-01-12 14:38:21 +09:00
taizan-hokuto
5fe4e7af04 Fix description 2020-01-12 14:26:15 +09:00
taizan-hokuto
892dfb8a91 Fix setup.py 2020-01-11 14:23:32 +09:00
taizan-hokuto
fddab22a1f Delete unnecessary file 2020-01-11 13:29:34 +09:00
taizan-hokuto
7194948066 Modify setup.py 2020-01-11 13:23:55 +09:00
taizan-hokuto
a836d92194 Increment version 2020-01-11 05:33:50 +09:00
10 changed files with 29 additions and 68 deletions

View File

@@ -1,7 +1,5 @@
include requirements.txt
include requirements_test.txt
prune testrun*.py
prune log.txt
prune quote.txt
prune .gitignore
prun tests
include README.MD
global-exclude tests/*
global-exclude pytchat/testrun*.py

View File

@@ -27,7 +27,7 @@ pip install pytchat
```python
from pytchat import LiveChat
chat = LiveChat("rsHWP7IjMiw")
chat = LiveChat("DSGyEsJ17cI")
while chat.is_alive():
data = chat.get()
for c in data.items:
@@ -47,7 +47,7 @@ def display(data):
data.tick()
if __name__ == '__main__':
chat = LiveChat("rsHWP7IjMiw", callback = display)
chat = LiveChat("DSGyEsJ17cI", callback = display)
while chat.is_alive():
#other background operation.
time.sleep(3)
@@ -61,7 +61,7 @@ from concurrent.futures import CancelledError
import asyncio
async def main():
chat = LiveChatAsync("rsHWP7IjMiw", callback = func)
chat = LiveChatAsync("DSGyEsJ17cI", callback = func)
while chat.is_alive():
#other background operation.
await asyncio.sleep(3)
@@ -86,7 +86,7 @@ if __name__ == '__main__':
from pytchat import LiveChat, CompatibleProcessor
import time
chat = LiveChat("rsHWP7IjMiw",
chat = LiveChat("DSGyEsJ17cI",
processor = CompatibleProcessor() )
while chat.is_alive():
@@ -108,7 +108,8 @@ from pytchat import LiveChat
def main():
#seektime (seconds): start position of chat.
chat = ReplayChat("ojes5ULOqhc", seektime = 60*30)
chat = LiveChat("ojes5ULOqhc", seektime = 60*30)
print('Replay from 30:00')
while chat.is_alive():
data = chat.get()
for c in data.items:

View File

@@ -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.4.5'
__version__ = '0.0.5.0'
__license__ = 'MIT'
__author__ = 'taizan-hokuto'
__author_email__ = '55448286+taizan-hokuto@users.noreply.github.com'

View File

@@ -226,8 +226,7 @@ class LiveChatAsync:
if contents is None or self._is_replay:
'''Try to fetch archive chat data.'''
self._parser.is_replay = True
self._fetch_url = ("live_chat_replay/"
"get_live_chat_replay?continuation=")
self._fetch_url = "live_chat_replay/get_live_chat_replay?continuation="
continuation = arcparam.getparam(
self.video_id, self.seektime, self._topchat_only)
livechat_json = (await self._get_livechat_json(

View File

@@ -104,7 +104,7 @@ class LiveChat:
self._pauser.put_nowait(None)
self._setup()
self._first_fetch = True
self._fetch_url = "live_chat/get_live_chat?continuation=",
self._fetch_url = "live_chat/get_live_chat?continuation="
self._topchat_only = topchat_only
if not LiveChat._setup_finished:
LiveChat._setup_finished = True
@@ -218,8 +218,7 @@ class LiveChat:
if contents is None or self._is_replay:
'''Try to fetch archive chat data.'''
self._parser.is_replay = True
self._fetch_url = ("live_chat_replay/"
"get_live_chat_replay?continuation=")
self._fetch_url = "live_chat_replay/get_live_chat_replay?continuation="
continuation = arcparam.getparam(self.video_id, self.seektime)
livechat_json = ( self._get_livechat_json(
continuation, session, headers))
@@ -234,8 +233,7 @@ class LiveChat:
continuation = urllib.parse.quote(continuation)
livechat_json = None
status_code = 0
url =(
f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1")
url =f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1"
for _ in range(MAX_RETRY + 1):
with session.get(url ,headers = headers) as resp:
try:

View File

@@ -1,31 +0,0 @@
import logging
import datetime
def get_logger(modname,mode=logging.DEBUG):
logger = logging.getLogger(modname)
if mode == None:
logger.addHandler(logging.NullHandler())
return logger
logger.setLevel(mode)
#create handler1 for showing info
handler1 = logging.StreamHandler()
my_formatter = MyFormatter()
handler1.setFormatter(my_formatter)
handler1.setLevel(mode)
logger.addHandler(handler1)
#create handler2 for recording log file
if mode <= logging.DEBUG:
handler2 = logging.FileHandler(filename="log.txt", encoding='utf-8')
handler2.setLevel(logging.ERROR)
handler2.setFormatter(my_formatter)
logger.addHandler(handler2)
return logger
class MyFormatter(logging.Formatter):
def format(self, record):
s =(datetime.datetime.fromtimestamp(record.created)).strftime("%m-%d %H:%M:%S")+'| '+ (record.module).ljust(15)+(' { '+record.funcName).ljust(20) +":"+str(record.lineno).rjust(4)+'} - '+record.getMessage()
return s

View File

@@ -26,7 +26,8 @@ class Parser:
if jsn is None:
raise ChatParseException('Called with none JSON object.')
if jsn['response']['responseContext'].get('errors'):
raise ResponseContextError('The video_id would be wrong, or video is deleted or private.')
raise ResponseContextError('The video_id would be wrong,'
'or video is deleted or private.')
contents=jsn['response'].get('continuationContents')
return contents
@@ -77,7 +78,8 @@ class Parser:
metadata.setdefault("timeoutMs",interval)
"""Archived chat has different structures than live chat,
so make it the same format."""
chatdata = [action["replayChatItemAction"]["actions"][0] for action in actions]
chatdata = [action["replayChatItemAction"]["actions"][0]
for action in actions]
else:
metadata.setdefault('timeoutMs', 10000)
chatdata = actions

View File

@@ -10,13 +10,9 @@ class LiveChatPaidMessageRenderer(BaseRenderer):
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.get_message(self.renderer)
self.amountValue= amount
self.amountString = amountDisplayString
self.currency= currency.symbols[symbol]["fxtext"] if currency.symbols.get(symbol) else symbol

View File

@@ -10,13 +10,9 @@ class LiveChatPaidStickerRenderer(BaseRenderer):
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

View File

@@ -1,6 +1,6 @@
from setuptools import setup, find_packages, Command
#from codecs import open as open_c
from os import path, system, remove, rename
from os import path, system, remove, rename, removedirs
import re
package_name = "pytchat"
@@ -13,6 +13,15 @@ def _requirements():
def _test_requirements():
return [name.rstrip() for name in open(path.join(root_dir, 'requirements_test.txt')).readlines()]
txt= ''
with open('README.MD', 'r', encoding='utf-8') as f:
txt = f.read()
with open('README1.MD', 'w', encoding='utf-8', newline='\n') as f:
f.write(txt)
remove("README.MD")
rename("README1.MD","README.MD")
with open(path.join(root_dir, package_name, '__init__.py')) as f:
init_text = f.read()
@@ -30,14 +39,7 @@ assert url
with open('README.MD', 'r', encoding='utf-8') as f:
txt = f.read()
with open('README1.MD', 'w', encoding='utf-8', newline='\n') as f:
f.write(txt)
remove("README.MD")
rename("README1.MD","README.MD")
with open('README.md', encoding='utf-8') as f:
long_description = f.read()
@@ -45,7 +47,7 @@ with open('README.md', encoding='utf-8') as f:
setup(
name=package_name,
packages=find_packages(),
packages=find_packages(exclude=['*log.txt','*tests']),
version=version,
url=url,
author=author,