Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests #222

Merged
merged 3 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions chat_downloader/sites/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,12 @@ def _parse_currency(item):
# gifts
'primaryText': r('message', _parse_text),

'bannerType': 'banner_type',
'bannerProperties': 'banner_properties',
'headerOverlayImage': r('header_overlay_image', _parse_thumbnails),

# hearted message
'creatorHeartButton': 'creator_heart_button',
}

_COLOUR_KEYS = [
Expand Down
26 changes: 2 additions & 24 deletions chat_downloader/sites/zoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class ZoomChatDownloader(BaseChatDownloader):
_ZOOM_PATH_TEMPLATE = 'rec/play/{id}'
_ZOOM_API_TEMPLATE = 'nws/recording/1.0/play/info/{file_id}'

_INITIAL_INFO_REGEX = r'(?s)window\.__data__\s*=\s*({.+?});'
_CHAT_MESSAGES_REGEX = r'window\.__data__\.chatList\.push\((\{[\s\S]+?\})\)'

_SITE_DEFAULT_PARAMS = {
Expand Down Expand Up @@ -96,35 +95,14 @@ class ZoomChatDownloader(BaseChatDownloader):
_VALID_URLS = {
'_get_chat_by_video_id': r'(?P<base_url>https?://(?:[^.]+\.)?zoom.us/)rec(?:ording)?/(?:play|share)/(?P<id>[A-Za-z0-9_.-]+)',
}
_ERROR_MESSAGE_REGEX = r'<span class="error-message">\s*([^<]+?)\s*<\/span>'

def _get_chat_by_video_id(self, match, params):
match_id = match.group('id')
base_url = match.group('base_url')
return self.get_chat_by_video_id(match_id, params, base_url=base_url)

def get_chat_by_video_id(self, video_id, params, base_url=_ZOOM_HOMEPAGE):

url = base_url + self._ZOOM_PATH_TEMPLATE.format(id=video_id)
page_data = self._session_get(url).text

json_string = regex_search(page_data, self._INITIAL_INFO_REGEX)

if json_string is None:
error_message = regex_search(page_data, self._ERROR_MESSAGE_REGEX)
if error_message:
raise ZoomError(error_message.split('\n')[0])
else:
raise ParsingError('Error parsing video')

initial_info = self._parse_js_dict(json_string)
video_type = 'video' if initial_info.get('isVideo') else 'not_video'

file_id = initial_info.get('fileId')
if not file_id:
raise ParsingError('Error parsing video. Unable to find file ID.')

api_url = base_url + self._ZOOM_API_TEMPLATE.format(file_id=file_id)
api_url = base_url + self._ZOOM_API_TEMPLATE.format(file_id=video_id)

api_data = self._session_get_json(api_url)

Expand All @@ -142,7 +120,7 @@ def get_chat_by_video_id(self, video_id, params, base_url=_ZOOM_HOMEPAGE):
return Chat(
self._get_chat_messages(chat_messages, params),
title=title,
video_type=video_type,
video_type='video',
start_time=result.get('fileStartTime'),
id=video_id,
duration=result.get('duration'),
Expand Down
Loading