Fix extraction process

This commit is contained in:
taizan-hokuto
2020-09-04 20:57:33 +09:00
parent 69c60d085f
commit 8ec567d035
2 changed files with 14 additions and 6 deletions

View File

@@ -9,7 +9,16 @@ class UnknownConnectionError(Exception):
pass pass
class VideoInfoParseException(Exception): class VideoInfoParseError(Exception):
''' '''
thrown when failed to parse video info thrown when failed to parse video info
''' '''
class PatternUnmatchError(VideoInfoParseError):
'''
thrown when failed to parse video info with unmatched pattern
'''
def __init__(self, doc):
self.msg = "PatternUnmatchError"
self.doc = doc

View File

@@ -98,14 +98,13 @@ class VideoInfo:
def _parse(self, text): def _parse(self, text):
result = re.search(pattern, text) result = re.search(pattern, text)
gr = result.group(1) if result is None:
if gr is None:
raise VideoInfoParseException("Failed to parse video info.") raise VideoInfoParseException("Failed to parse video info.")
self._res = json.loads(gr[:-1]) decoder = json.JSONDecoder()
self._res = decoder.raw_decode(result.group(1)[:-1])[0]
response = self._get_item(self._res, item_response) response = self._get_item(self._res, item_response)
if response is None: if response is None:
self._check_video_is_private(self._res.get("args")) self._check_video_is_private(self._res.get("args"))
self._renderer = self._get_item(json.loads(response), item_renderer) self._renderer = self._get_item(json.loads(response), item_renderer)
if self._renderer is None: if self._renderer is None:
raise InvalidVideoIdException( raise InvalidVideoIdException(