Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
385634b709 | ||
|
|
c1a78a2743 | ||
|
|
7961801e0c | ||
|
|
5fe4e7af04 | ||
|
|
892dfb8a91 | ||
|
|
fddab22a1f | ||
|
|
7194948066 | ||
|
|
a836d92194 |
@@ -1,7 +1,5 @@
|
|||||||
include requirements.txt
|
include requirements.txt
|
||||||
include requirements_test.txt
|
include requirements_test.txt
|
||||||
prune testrun*.py
|
include README.MD
|
||||||
prune log.txt
|
global-exclude tests/*
|
||||||
prune quote.txt
|
global-exclude pytchat/testrun*.py
|
||||||
prune .gitignore
|
|
||||||
prun tests
|
|
||||||
@@ -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.4.5'
|
__version__ = '0.0.4.9'
|
||||||
__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'
|
||||||
|
|||||||
@@ -226,8 +226,7 @@ class LiveChatAsync:
|
|||||||
if contents is None or self._is_replay:
|
if contents is None or self._is_replay:
|
||||||
'''Try to fetch archive chat data.'''
|
'''Try to fetch archive chat data.'''
|
||||||
self._parser.is_replay = True
|
self._parser.is_replay = True
|
||||||
self._fetch_url = ("live_chat_replay/"
|
self._fetch_url = "live_chat_replay/get_live_chat_replay?continuation="
|
||||||
"get_live_chat_replay?continuation=")
|
|
||||||
continuation = arcparam.getparam(
|
continuation = arcparam.getparam(
|
||||||
self.video_id, self.seektime, self._topchat_only)
|
self.video_id, self.seektime, self._topchat_only)
|
||||||
livechat_json = (await self._get_livechat_json(
|
livechat_json = (await self._get_livechat_json(
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class LiveChat:
|
|||||||
self._pauser.put_nowait(None)
|
self._pauser.put_nowait(None)
|
||||||
self._setup()
|
self._setup()
|
||||||
self._first_fetch = True
|
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
|
self._topchat_only = topchat_only
|
||||||
if not LiveChat._setup_finished:
|
if not LiveChat._setup_finished:
|
||||||
LiveChat._setup_finished = True
|
LiveChat._setup_finished = True
|
||||||
@@ -218,8 +218,7 @@ class LiveChat:
|
|||||||
if contents is None or self._is_replay:
|
if contents is None or self._is_replay:
|
||||||
'''Try to fetch archive chat data.'''
|
'''Try to fetch archive chat data.'''
|
||||||
self._parser.is_replay = True
|
self._parser.is_replay = True
|
||||||
self._fetch_url = ("live_chat_replay/"
|
self._fetch_url = "live_chat_replay/get_live_chat_replay?continuation="
|
||||||
"get_live_chat_replay?continuation=")
|
|
||||||
continuation = arcparam.getparam(self.video_id, self.seektime)
|
continuation = arcparam.getparam(self.video_id, self.seektime)
|
||||||
livechat_json = ( self._get_livechat_json(
|
livechat_json = ( self._get_livechat_json(
|
||||||
continuation, session, headers))
|
continuation, session, headers))
|
||||||
@@ -234,8 +233,7 @@ class LiveChat:
|
|||||||
continuation = urllib.parse.quote(continuation)
|
continuation = urllib.parse.quote(continuation)
|
||||||
livechat_json = None
|
livechat_json = None
|
||||||
status_code = 0
|
status_code = 0
|
||||||
url =(
|
url =f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1"
|
||||||
f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1")
|
|
||||||
for _ in range(MAX_RETRY + 1):
|
for _ in range(MAX_RETRY + 1):
|
||||||
with session.get(url ,headers = headers) as resp:
|
with session.get(url ,headers = headers) as resp:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -26,7 +26,8 @@ class Parser:
|
|||||||
if jsn is None:
|
if jsn is None:
|
||||||
raise ChatParseException('Called with none JSON object.')
|
raise ChatParseException('Called with none JSON object.')
|
||||||
if jsn['response']['responseContext'].get('errors'):
|
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')
|
contents=jsn['response'].get('continuationContents')
|
||||||
return contents
|
return contents
|
||||||
|
|
||||||
@@ -77,7 +78,8 @@ class Parser:
|
|||||||
metadata.setdefault("timeoutMs",interval)
|
metadata.setdefault("timeoutMs",interval)
|
||||||
"""Archived chat has different structures than live chat,
|
"""Archived chat has different structures than live chat,
|
||||||
so make it the same format."""
|
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:
|
else:
|
||||||
metadata.setdefault('timeoutMs', 10000)
|
metadata.setdefault('timeoutMs', 10000)
|
||||||
chatdata = actions
|
chatdata = actions
|
||||||
|
|||||||
20
setup.py
20
setup.py
@@ -1,6 +1,6 @@
|
|||||||
from setuptools import setup, find_packages, Command
|
from setuptools import setup, find_packages, Command
|
||||||
#from codecs import open as open_c
|
#from codecs import open as open_c
|
||||||
from os import path, system, remove, rename
|
from os import path, system, remove, rename, removedirs
|
||||||
import re
|
import re
|
||||||
|
|
||||||
package_name = "pytchat"
|
package_name = "pytchat"
|
||||||
@@ -13,6 +13,15 @@ def _requirements():
|
|||||||
def _test_requirements():
|
def _test_requirements():
|
||||||
return [name.rstrip() for name in open(path.join(root_dir, 'requirements_test.txt')).readlines()]
|
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:
|
with open(path.join(root_dir, package_name, '__init__.py')) as f:
|
||||||
init_text = f.read()
|
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:
|
with open('README.md', encoding='utf-8') as f:
|
||||||
long_description = f.read()
|
long_description = f.read()
|
||||||
|
|
||||||
@@ -45,7 +47,7 @@ with open('README.md', encoding='utf-8') as f:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name=package_name,
|
name=package_name,
|
||||||
packages=find_packages(),
|
packages=find_packages(exclude=['*log.txt','*tests']),
|
||||||
version=version,
|
version=version,
|
||||||
url=url,
|
url=url,
|
||||||
author=author,
|
author=author,
|
||||||
|
|||||||
Reference in New Issue
Block a user