From 8ec567d0353aa981fcccc60d8d6b81cde4e9f000 Mon Sep 17 00:00:00 2001 From: taizan-hokuto <55448286+taizan-hokuto@users.noreply.github.com> Date: Fri, 4 Sep 2020 20:57:33 +0900 Subject: [PATCH] Fix extraction process --- yvi/exceptions.py | 13 +++++++++++-- yvi/yvi.py | 7 +++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/yvi/exceptions.py b/yvi/exceptions.py index decef13..33db96d 100644 --- a/yvi/exceptions.py +++ b/yvi/exceptions.py @@ -9,7 +9,16 @@ class UnknownConnectionError(Exception): pass -class VideoInfoParseException(Exception): +class VideoInfoParseError(Exception): ''' thrown when failed to parse video info - ''' \ No newline at end of file + ''' + + +class PatternUnmatchError(VideoInfoParseError): + ''' + thrown when failed to parse video info with unmatched pattern + ''' + def __init__(self, doc): + self.msg = "PatternUnmatchError" + self.doc = doc diff --git a/yvi/yvi.py b/yvi/yvi.py index 32e0b05..0a9291b 100644 --- a/yvi/yvi.py +++ b/yvi/yvi.py @@ -98,14 +98,13 @@ class VideoInfo: def _parse(self, text): result = re.search(pattern, text) - gr = result.group(1) - if gr is None: + if result is None: 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) if response is None: self._check_video_is_private(self._res.get("args")) - self._renderer = self._get_item(json.loads(response), item_renderer) if self._renderer is None: raise InvalidVideoIdException(