Compare commits

...

13 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
taizan-hokuto
b02a2badf7 Merge branch 'develop' 2020-04-17 00:23:38 +09:00
taizan-hokuto
3aee1b276f Increment version 2020-04-17 00:23:27 +09:00
taizan-hokuto
73026b52af Add required module 2020-04-17 00:22:59 +09:00
taizan-hokuto
c88abc600d Merge branch 'develop' 2020-04-17 00:07:41 +09:00
taizan-hokuto
679f2e9bb8 Modify README 2020-04-17 00:07:20 +09:00
5 changed files with 50 additions and 30 deletions

View File

@@ -13,11 +13,8 @@ info.get_title()
info.get_channel_id()
```
## Function
### get_info(video_id, session)
Returns
-------
+ VideoInfo object.
### get_info(video_id, session)
Parameters
----------
@@ -25,37 +22,42 @@ Parameters
- session : session object of requests.
Returns
-------
+ VideoInfo object.
## Attributes of VideoInfo object
### get_duration()
- 動画の長さアーカイブのみ。ライブ動画または待機画面の場合0
### get_title()
-   動画タイトル
### get_duration()
- 動画の長さ秒。アーカイブのみ。ライブ動画または待機画面の場合、0が返ります。
### get_title_escaped()
-   動画タイトル(絵文字なし。GUIライブラリ等で絵文字が含まれていてエラーが出る場合はこちらを使用してください)
### get_title()
- 動画タイトル
### get_channel_id()
### get_title_escaped()
- 動画タイトル(絵文字なし。GUIライブラリ等で絵文字が含まれていてエラーが出る場合はこちらを使用してください)
### get_channel_id()
- チャンネルID
### get_thumbnail()
-   動画サムネイルURL
### get_thumbnail()
- 動画サムネイルURL
### get_owner_name()
-   配信者名
### get_owner_name()
- 配信者名
### get_owner_name_escaped()
-   配信者名(絵文字なし)
### get_owner_name_escaped()
- 配信者名(絵文字なし)
### get_owner_image()
### get_owner_image()
-   配信者プロフィール画像URL
### get_user_name()
-   視聴者名
### get_user_name()
- 視聴者名
### get_user_name_escaped()
-   視聴者名(絵文字なし)
### get_user_name_escaped()
- 視聴者名(絵文字なし)
### get_user_image()
-   視聴者プロフィール画像URL
### get_user_image()
- 視聴者プロフィール画像URL

View File

@@ -1 +1,2 @@
requests
emoji

View File

@@ -2,7 +2,7 @@
Retriever tool for youtube video information.
"""
__copyright__ = 'Copyright (C) 2020 taizan-hokuto'
__version__ = '0.0.1'
__version__ = '0.0.4'
__license__ = 'MIT'
__author__ = 'taizan-hokuto'
__author_email__ = '55448286+taizan-hokuto@users.noreply.github.com'

View File

@@ -7,3 +7,18 @@ class InvalidVideoIdException(Exception):
class UnknownConnectionError(Exception):
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 requests
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 = [
"videoDetails",
@@ -98,11 +98,13 @@ class VideoInfo:
def _parse(self, 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)
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(