Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5fb7053ee | ||
|
|
c8a5be7255 | ||
|
|
99bc9243f8 | ||
|
|
8ec567d035 | ||
|
|
69c60d085f | ||
|
|
9e3f18c20b | ||
|
|
9d08e5cff6 | ||
|
|
5640c45af6 |
@@ -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'
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
10
yvi/yvi.py
10
yvi/yvi.py
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user