Merge branch 'master' into feature/httpx
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
pytchat is a lightweight python library to browse youtube livechat without Selenium or BeautifulSoup.
|
pytchat is a lightweight python library to browse youtube livechat without Selenium or BeautifulSoup.
|
||||||
"""
|
"""
|
||||||
__copyright__ = 'Copyright (C) 2019 taizan-hokuto'
|
__copyright__ = 'Copyright (C) 2019 taizan-hokuto'
|
||||||
__version__ = '0.1.3'
|
__version__ = '0.1.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'
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import os
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pytchat.util.extract_video_id import extract_video_id
|
from pytchat.util.extract_video_id import extract_video_id
|
||||||
from .arguments import Arguments
|
from .arguments import Arguments
|
||||||
from .. exceptions import InvalidVideoIdException, NoContents
|
from .. exceptions import InvalidVideoIdException, NoContents, VideoInfoParseException
|
||||||
from .. processors.html_archiver import HTMLArchiver
|
from .. processors.html_archiver import HTMLArchiver
|
||||||
from .. tool.extract.extractor import Extractor
|
from .. tool.extract.extractor import Extractor
|
||||||
from .. tool.videoinfo import VideoInfo
|
from .. tool.videoinfo import VideoInfo
|
||||||
@@ -40,11 +40,11 @@ def main():
|
|||||||
if '[' in video_id:
|
if '[' in video_id:
|
||||||
video_id = video_id.replace('[', '').replace(']', '')
|
video_id = video_id.replace('[', '').replace(']', '')
|
||||||
try:
|
try:
|
||||||
|
video_id = extract_video_id(video_id)
|
||||||
if os.path.exists(Arguments().output):
|
if os.path.exists(Arguments().output):
|
||||||
path = Path(Arguments().output + video_id + '.html')
|
path = Path(Arguments().output + video_id + '.html')
|
||||||
else:
|
else:
|
||||||
raise FileNotFoundError
|
raise FileNotFoundError
|
||||||
video_id = extract_video_id(video_id)
|
|
||||||
info = VideoInfo(video_id)
|
info = VideoInfo(video_id)
|
||||||
print(f"Extracting...\n"
|
print(f"Extracting...\n"
|
||||||
f" video_id: {video_id}\n"
|
f" video_id: {video_id}\n"
|
||||||
@@ -63,7 +63,9 @@ def main():
|
|||||||
except (TypeError, NoContents) as e:
|
except (TypeError, NoContents) as e:
|
||||||
print(e)
|
print(e)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print("The specified directory does not exist.:{}".format(Arguments().output ))
|
print("The specified directory does not exist.:{}".format(Arguments().output))
|
||||||
|
except VideoInfoParseException:
|
||||||
|
print("Cannot parse video information.:{}".format(video_id))
|
||||||
return
|
return
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
||||||
|
|||||||
@@ -62,3 +62,9 @@ class ReceivedUnknownContinuation(ChatParseException):
|
|||||||
|
|
||||||
class FailedExtractContinuation(ChatDataFinished):
|
class FailedExtractContinuation(ChatDataFinished):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class VideoInfoParseException(Exception):
|
||||||
|
'''
|
||||||
|
thrown when failed to parse video info
|
||||||
|
'''
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class Extractor:
|
|||||||
|
|
||||||
def extract(self):
|
def extract(self):
|
||||||
if self.duration == 0:
|
if self.duration == 0:
|
||||||
print("video is not archived.")
|
print("\nCannot extract chat data:\n The specified video has not yet been archived.")
|
||||||
return []
|
return []
|
||||||
data = self._execute_extract_operations()
|
data = self._execute_extract_operations()
|
||||||
if self.processor is None:
|
if self.processor is None:
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from ..util.extract_video_id import extract_video_id
|
|||||||
|
|
||||||
headers = config.headers
|
headers = config.headers
|
||||||
|
|
||||||
pattern = re.compile(r"yt\.setConfig\({'PLAYER_CONFIG': ({.*})}\);")
|
pattern = re.compile(r"'PLAYER_CONFIG': ({.*}}})")
|
||||||
|
|
||||||
item_channel_id = [
|
item_channel_id = [
|
||||||
"videoDetails",
|
"videoDetails",
|
||||||
@@ -91,7 +91,7 @@ class VideoInfo:
|
|||||||
|
|
||||||
def _parse(self, text):
|
def _parse(self, text):
|
||||||
result = re.search(pattern, text)
|
result = re.search(pattern, text)
|
||||||
res = json.loads(result.group(1))
|
res = json.loads(result.group(1)[:-1])
|
||||||
response = self._get_item(res, item_response)
|
response = self._get_item(res, item_response)
|
||||||
if response is None:
|
if response is None:
|
||||||
self._check_video_is_private(res.get("args"))
|
self._check_video_is_private(res.get("args"))
|
||||||
|
|||||||
Reference in New Issue
Block a user