From 5640c45af6c51bd6bb876082a9707eff6bc46b51 Mon Sep 17 00:00:00 2001 From: taizan-hokuto <55448286+taizan-hokuto@users.noreply.github.com> Date: Fri, 21 Aug 2020 23:16:12 +0900 Subject: [PATCH 1/2] Fix extracting video info --- yvi/exceptions.py | 6 ++++++ yvi/yvi.py | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/yvi/exceptions.py b/yvi/exceptions.py index 3fd888f..decef13 100644 --- a/yvi/exceptions.py +++ b/yvi/exceptions.py @@ -7,3 +7,9 @@ class InvalidVideoIdException(Exception): class UnknownConnectionError(Exception): pass + + +class VideoInfoParseException(Exception): + ''' + thrown when failed to parse video info + ''' \ No newline at end of file diff --git a/yvi/yvi.py b/yvi/yvi.py index dcb3095..32e0b05 100644 --- a/yvi/yvi.py +++ b/yvi/yvi.py @@ -4,9 +4,9 @@ import json import re import requests from . import util -from . exceptions import InvalidVideoIdException +from . exceptions import InvalidVideoIdException, VideoInfoParseException -pattern = re.compile(r"yt\.setConfig\({'PLAYER_CONFIG': ({.*})}\);") +pattern = re.compile(r"'PLAYER_CONFIG': ({.*}}})") item_channel_id = [ "videoDetails", @@ -98,7 +98,10 @@ class VideoInfo: def _parse(self, text): result = re.search(pattern, text) - self._res = json.loads(result.group(1)) + gr = result.group(1) + if gr is None: + raise VideoInfoParseException("Failed to parse video info.") + self._res = json.loads(gr[:-1]) response = self._get_item(self._res, item_response) if response is None: self._check_video_is_private(self._res.get("args")) From 9d08e5cff68e7e3882cd27aef035632a1a3c3cfd Mon Sep 17 00:00:00 2001 From: taizan-hokuto <55448286+taizan-hokuto@users.noreply.github.com> Date: Fri, 21 Aug 2020 23:23:59 +0900 Subject: [PATCH 2/2] Increment version --- yvi/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yvi/__init__.py b/yvi/__init__.py index 90493ed..7f8c2ab 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.2' +__version__ = '0.0.3' __license__ = 'MIT' __author__ = 'taizan-hokuto' __author_email__ = '55448286+taizan-hokuto@users.noreply.github.com'