Compare commits

..

8 Commits

Author SHA1 Message Date
taizan-hokuto
f5fb7053ee Merge branch 'hotfix/match' 2020-09-04 21:12:01 +09:00
taizan-hokuto
c8a5be7255 Fix variant name 2020-09-04 20:58:46 +09:00
taizan-hokuto
99bc9243f8 Increment version 2020-09-04 20:57:45 +09:00
taizan-hokuto
8ec567d035 Fix extraction process 2020-09-04 20:57:33 +09:00
taizan-hokuto
69c60d085f Merge branch 'develop' 2020-08-21 23:26:12 +09:00
taizan-hokuto
9e3f18c20b Merge branch 'hotfix/extract_info' into develop 2020-08-21 23:25:44 +09:00
taizan-hokuto
9d08e5cff6 Increment version 2020-08-21 23:23:59 +09:00
taizan-hokuto
5640c45af6 Fix extracting video info 2020-08-21 23:16:12 +09:00
3 changed files with 22 additions and 5 deletions

View File

@@ -2,7 +2,7 @@
Retriever tool for youtube video information. Retriever tool for youtube video information.
""" """
__copyright__ = 'Copyright (C) 2020 taizan-hokuto' __copyright__ = 'Copyright (C) 2020 taizan-hokuto'
__version__ = '0.0.2' __version__ = '0.0.4'
__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

@@ -7,3 +7,18 @@ class InvalidVideoIdException(Exception):
class UnknownConnectionError(Exception): class UnknownConnectionError(Exception):
pass pass
class VideoInfoParseError(Exception):
'''
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

@@ -4,9 +4,9 @@ import json
import re import re
import requests import requests
from . import util from . import util
from . exceptions import InvalidVideoIdException from . exceptions import InvalidVideoIdException, VideoInfoParseError
pattern = re.compile(r"yt\.setConfig\({'PLAYER_CONFIG': ({.*})}\);") pattern = re.compile(r"'PLAYER_CONFIG': ({.*}}})")
item_channel_id = [ item_channel_id = [
"videoDetails", "videoDetails",
@@ -98,11 +98,13 @@ class VideoInfo:
def _parse(self, text): def _parse(self, text):
result = re.search(pattern, text) result = re.search(pattern, text)
self._res = json.loads(result.group(1)) if result is None:
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) 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(