Compare commits

...

4 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
3 changed files with 17 additions and 9 deletions

View File

@@ -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'

View File

@@ -9,7 +9,16 @@ class UnknownConnectionError(Exception):
pass
class VideoInfoParseException(Exception):
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,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': ({.*}}})")
@@ -98,14 +98,13 @@ class VideoInfo:
def _parse(self, text):
result = re.search(pattern, text)
gr = result.group(1)
if gr is None:
raise VideoInfoParseException("Failed to parse video info.")
self._res = json.loads(gr[:-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)
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(