Merge tag 'extract_vid' into develop
v0.1.7
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
pytchat is a lightweight python library to browse youtube livechat without Selenium or BeautifulSoup.
|
||||
"""
|
||||
__copyright__ = 'Copyright (C) 2019 taizan-hokuto'
|
||||
__version__ = '0.1.6'
|
||||
__version__ = '0.1.7'
|
||||
__license__ = 'MIT'
|
||||
__author__ = 'taizan-hokuto'
|
||||
__author_email__ = '55448286+taizan-hokuto@users.noreply.github.com'
|
||||
|
||||
@@ -76,9 +76,10 @@ def main():
|
||||
print("\nThe extraction process has been completed.\n")
|
||||
except InvalidVideoIdException:
|
||||
print("Invalid Video ID or URL:", video_id)
|
||||
except (TypeError, NoContents) as e:
|
||||
|
||||
except TypeError as e:
|
||||
print(e.with_traceback())
|
||||
except NoContents as e:
|
||||
print(e)
|
||||
except FileNotFoundError:
|
||||
print("The specified directory does not exist.:{}".format(Arguments().output))
|
||||
except JSONDecodeError as e:
|
||||
|
||||
@@ -93,7 +93,8 @@ class VideoInfo:
|
||||
result = re.search(pattern, text)
|
||||
if result is None:
|
||||
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)
|
||||
if response is None:
|
||||
self._check_video_is_private(res.get("args"))
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from json.decoder import JSONDecodeError
|
||||
from pytchat.tool.videoinfo import VideoInfo
|
||||
from pytchat.exceptions import InvalidVideoIdException, PatternUnmatchError
|
||||
from pytchat import util
|
||||
|
||||
|
||||
def _open_file(path):
|
||||
@@ -32,7 +31,7 @@ def test_archived_page(mocker):
|
||||
def test_live_page(mocker):
|
||||
_set_test_data('tests/testdata/videoinfo/live_page.txt', mocker)
|
||||
info = VideoInfo('__test_id__')
|
||||
'''live page :duration = 0'''
|
||||
'''live page: duration==0'''
|
||||
assert info.get_duration() == 0
|
||||
assert info.video_id == '__test_id__'
|
||||
assert info.get_channel_name() == 'BGM channel'
|
||||
@@ -88,3 +87,15 @@ def test_pattern_unmatch(mocker):
|
||||
assert False
|
||||
except PatternUnmatchError:
|
||||
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
|
||||
|
||||
15
tests/testdata/videoinfo/extradata_page.txt
vendored
Normal file
15
tests/testdata/videoinfo/extradata_page.txt
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user