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 1/3] 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( From 99bc9243f89b6b4cdbb401b2c319ba9e2902b2fd Mon Sep 17 00:00:00 2001 From: taizan-hokuto <55448286+taizan-hokuto@users.noreply.github.com> Date: Fri, 4 Sep 2020 20:57:45 +0900 Subject: [PATCH 2/3] Increment version --- yvi/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yvi/__init__.py b/yvi/__init__.py index 7f8c2ab..ae56df0 100644 --- a/yvi/__init__.py +++ b/yvi/__init__.py @@ -2,7 +2,7 @@ Retriever tool for youtube video information. """ __copyright__ = 'Copyright (C) 2020 taizan-hokuto' -__version__ = '0.0.3' +__version__ = '0.0.4' __license__ = 'MIT' __author__ = 'taizan-hokuto' __author_email__ = '55448286+taizan-hokuto@users.noreply.github.com' From c8a5be72556f27329552ecd2cdb5e8fdb05c1fb7 Mon Sep 17 00:00:00 2001 From: taizan-hokuto <55448286+taizan-hokuto@users.noreply.github.com> Date: Fri, 4 Sep 2020 20:58:46 +0900 Subject: [PATCH 3/3] Fix variant name --- yvi/yvi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yvi/yvi.py b/yvi/yvi.py index 0a9291b..667425e 100644 --- a/yvi/yvi.py +++ b/yvi/yvi.py @@ -4,7 +4,7 @@ import json import re import requests from . import util -from . exceptions import InvalidVideoIdException, VideoInfoParseException +from . exceptions import InvalidVideoIdException, VideoInfoParseError pattern = re.compile(r"'PLAYER_CONFIG': ({.*}}})") @@ -99,7 +99,7 @@ class VideoInfo: def _parse(self, text): result = re.search(pattern, text) if result is None: - raise VideoInfoParseException("Failed to parse video info.") + raise VideoInfoParseError("Failed to parse video info.") decoder = json.JSONDecoder() self._res = decoder.raw_decode(result.group(1)[:-1])[0] response = self._get_item(self._res, item_response)