Compare commits

...

3 Commits

Author SHA1 Message Date
taizan-hokuto
480c9e15b8 Merge branch 'hotfix/continue_error' 2020-09-11 00:21:07 +09:00
taizan-hokuto
35aa7636f6 Increment version 2020-09-11 00:20:24 +09:00
taizan-hokuto
8fee67c2d4 Fix handling video info error 2020-09-11 00:18:09 +09:00
3 changed files with 25 additions and 14 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.2.1' __version__ = '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'

View File

@@ -2,6 +2,7 @@ import argparse
import os import os
import signal import signal
import time
from json.decoder import JSONDecodeError from json.decoder import JSONDecodeError
from pathlib import Path from pathlib import Path
from .arguments import Arguments from .arguments import Arguments
@@ -55,7 +56,21 @@ def main():
path = Path(Arguments().output + video_id + '.html') path = Path(Arguments().output + video_id + '.html')
else: else:
raise FileNotFoundError raise FileNotFoundError
err = None
for _ in range(3): # retry 3 times
try:
info = VideoInfo(video_id) info = VideoInfo(video_id)
break
except (PatternUnmatchError, JSONDecodeError, InvalidVideoIdException) as e:
err = e
time.sleep(2)
continue
else:
print("Cannot parse video information.:{}".format(video_id))
if Arguments().save_error_data:
util.save(err.doc, "ERR", ".dat")
continue
if len(Arguments().video_ids) > 1: if len(Arguments().video_ids) > 1:
print(f"\n{'-' * 10} video:{counter + 1} of {len(Arguments().video_ids)} {'-' * 10}") print(f"\n{'-' * 10} video:{counter + 1} of {len(Arguments().video_ids)} {'-' * 10}")
print(f"\n" print(f"\n"
@@ -86,8 +101,6 @@ def main():
print() print()
if pbar.is_cancelled(): if pbar.is_cancelled():
print("\nThe extraction process has been discontinued.\n") print("\nThe extraction process has been discontinued.\n")
except InvalidVideoIdException: except InvalidVideoIdException:
print("Invalid Video ID or URL:", video_id) print("Invalid Video ID or URL:", video_id)
except NoContents as e: except NoContents as e:
@@ -96,14 +109,9 @@ def main():
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:
print(e.msg) print(e.msg)
print("Cannot parse video information.:{}".format(video_id)) print("JSONDecodeError.:{}".format(video_id))
if Arguments().save_error_data: if Arguments().save_error_data:
util.save(e.doc, "ERR_JSON_DECODE", ".dat") util.save(e.doc, "ERR_JSON_DECODE", ".dat")
except PatternUnmatchError as e:
print(e.msg)
print("Cannot parse video information.:{}".format(video_id))
if Arguments().save_error_data:
util.save(e.doc, "ERR_PATTERN_UNMATCH", ".dat")
return return

View File

@@ -38,7 +38,10 @@ class InvalidVideoIdException(Exception):
''' '''
Thrown when the video_id is not exist (VideoInfo). Thrown when the video_id is not exist (VideoInfo).
''' '''
pass def __init__(self, doc):
self.msg = "InvalidVideoIdException"
self.doc = doc
class UnknownConnectionError(Exception): class UnknownConnectionError(Exception):
@@ -47,7 +50,7 @@ class UnknownConnectionError(Exception):
class RetryExceedMaxCount(Exception): class RetryExceedMaxCount(Exception):
''' '''
thrown when the number of retries exceeds the maximum value. Thrown when the number of retries exceeds the maximum value.
''' '''
pass pass
@@ -66,13 +69,13 @@ class FailedExtractContinuation(ChatDataFinished):
class VideoInfoParseError(Exception): class VideoInfoParseError(Exception):
''' '''
thrown when failed to parse video info Base exception when parsing video info.
''' '''
class PatternUnmatchError(VideoInfoParseError): class PatternUnmatchError(VideoInfoParseError):
''' '''
thrown when failed to parse video info with unmatched pattern Thrown when failed to parse video info with unmatched pattern.
''' '''
def __init__(self, doc): def __init__(self, doc):
self.msg = "PatternUnmatchError" self.msg = "PatternUnmatchError"