Compare commits

..

7 Commits

Author SHA1 Message Date
taizan-hokuto
a3695a59b8 Merge branch 'hotfix/extract_vid' 2020-09-04 01:55:41 +09:00
taizan-hokuto
bc8655ed62 Increment version 2020-09-04 01:53:14 +09:00
taizan-hokuto
3bdc465740 Devide exception handling 2020-09-04 01:52:53 +09:00
taizan-hokuto
235d6b7212 Fix extract video info 2020-09-04 01:46:10 +09:00
taizan-hokuto
306b0a4564 Merge branch 'hotfix/http2' 2020-09-03 21:27:48 +09:00
taizan-hokuto
1c49387f1a Increment version 2020-09-03 21:24:42 +09:00
taizan-hokuto
300d96e56c Fix requirements.txt 2020-09-03 21:24:21 +09:00
6 changed files with 35 additions and 7 deletions

View File

@@ -2,7 +2,7 @@
pytchat is a lightweight python library to browse youtube livechat without Selenium or BeautifulSoup. pytchat is a lightweight python library to browse youtube livechat without Selenium or BeautifulSoup.
""" """
__copyright__ = 'Copyright (C) 2019 taizan-hokuto' __copyright__ = 'Copyright (C) 2019 taizan-hokuto'
__version__ = '0.1.5' __version__ = '0.1.7'
__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'

View File

@@ -76,9 +76,10 @@ def main():
print("\nThe extraction process has been completed.\n") print("\nThe extraction process has been completed.\n")
except InvalidVideoIdException: except InvalidVideoIdException:
print("Invalid Video ID or URL:", video_id) print("Invalid Video ID or URL:", video_id)
except (TypeError, NoContents) as e: except TypeError as e:
print(e.with_traceback()) print(e.with_traceback())
except NoContents as e:
print(e)
except FileNotFoundError: except FileNotFoundError:
print("The specified directory does not exist.:{}".format(Arguments().output)) print("The specified directory does not exist.:{}".format(Arguments().output))
except JSONDecodeError as e: except JSONDecodeError as e:

View File

@@ -93,7 +93,8 @@ class VideoInfo:
result = re.search(pattern, text) result = re.search(pattern, text)
if result is None: if result is None:
raise PatternUnmatchError(text) raise PatternUnmatchError(text)
res = json.loads(result.group(1)[:-1]) decoder = json.JSONDecoder()
res = decoder.raw_decode(result.group(1)[:-1])[0]
response = self._get_item(res, item_response) response = self._get_item(res, item_response)
if response is None: if response is None:
self._check_video_is_private(res.get("args")) self._check_video_is_private(res.get("args"))

View File

@@ -1,4 +1,4 @@
httpx==0.14.1 httpx[http2]==0.14.1
protobuf==3.13.0 protobuf==3.13.0
pytz pytz
urllib3 urllib3

View File

@@ -1,7 +1,6 @@
from json.decoder import JSONDecodeError from json.decoder import JSONDecodeError
from pytchat.tool.videoinfo import VideoInfo from pytchat.tool.videoinfo import VideoInfo
from pytchat.exceptions import InvalidVideoIdException, PatternUnmatchError from pytchat.exceptions import InvalidVideoIdException, PatternUnmatchError
from pytchat import util
def _open_file(path): def _open_file(path):
@@ -32,7 +31,7 @@ def test_archived_page(mocker):
def test_live_page(mocker): def test_live_page(mocker):
_set_test_data('tests/testdata/videoinfo/live_page.txt', mocker) _set_test_data('tests/testdata/videoinfo/live_page.txt', mocker)
info = VideoInfo('__test_id__') info = VideoInfo('__test_id__')
'''live page :duration = 0''' '''live page: duration==0'''
assert info.get_duration() == 0 assert info.get_duration() == 0
assert info.video_id == '__test_id__' assert info.video_id == '__test_id__'
assert info.get_channel_name() == 'BGM channel' assert info.get_channel_name() == 'BGM channel'
@@ -88,3 +87,15 @@ def test_pattern_unmatch(mocker):
assert False assert False
except PatternUnmatchError: except PatternUnmatchError:
assert True assert True
def test_extradata_handling(mocker):
'''Test case the extracted data are JSON lines.'''
_set_test_data(
'tests/testdata/videoinfo/extradata_page.txt', mocker)
try:
_ = VideoInfo('__test_id__')
assert True
except JSONDecodeError as e:
print(e.doc)
assert False

File diff suppressed because one or more lines are too long