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

Added option to output video date as part of the file output #237

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion chat_downloader/sites/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class Chat():
next value is yielded from the object's `chat` generator method.
"""

def __init__(self, chat=None, title=None, duration=None, status=None, video_type=None, start_time=None, id=None, **kwargs):
def __init__(self, chat=None, title=None, duration=None, status=None, video_type=None, start_time=None, id=None, date_time=None, **kwargs):
"""Create a Chat object

:param chat: Generator method for retrieving chat messages, defaults to None
Expand All @@ -219,10 +219,13 @@ def __init__(self, chat=None, title=None, duration=None, status=None, video_type
:param start_time: Start time of the stream (or upload date of video)
in UNIX microseconds, defaults to None
:type start_time: float, optional
:param date_time: Date of Stream or clip created, defaults to None
:type date_time: str, optional
"""

self.chat = chat

self.date_time = date_time
self.title = title
self.duration = duration

Expand Down Expand Up @@ -253,7 +256,9 @@ def _init_writer(self):
# Special formatting of output name:
# Allowed keys are specified here
# Remove invalid characters from output file name
log('info', f'Retrieving chat for "{self.date_time}".')
self._output_writer.file_name = self._output_writer.file_name.format(
date_time=safe_path(self.date_time),
title=safe_path(self.title),
id=safe_path(self.id)
)
Expand Down
9 changes: 6 additions & 3 deletions chat_downloader/sites/twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,7 @@ def get_chat_by_vod_id(self, vod_id, params):
"Sorry. Unless you've got a time machine, that content is unavailable.")
title = video.get('title')
duration = video.get('lengthSeconds')
date_time = video.get('createdAt')

channel_name = multi_get(video, 'owner', 'login')
self._update_badge_info(channel_name)
Expand All @@ -1263,7 +1264,8 @@ def get_chat_by_vod_id(self, vod_id, params):
duration=duration,
status='past',
video_type='video',
id=vod_id
id=vod_id,
date_time=date_time
)

def _get_chat_by_clip_id(self, match, params):
Expand Down Expand Up @@ -1294,7 +1296,7 @@ def get_chat_by_clip_id(self, clip_id, params):

duration = clip.get('durationSeconds')
title = f"{clip.get('title')} ({clip_id})"

date_time = clip.get('createdAt')
channel_name = multi_get(clip, 'broadcaster', 'login')
self._update_badge_info(channel_name)

Expand All @@ -1305,7 +1307,8 @@ def get_chat_by_clip_id(self, clip_id, params):
duration=duration,
status='past',
video_type='clip',
id=clip_id
id=clip_id,
date_time=date_time
)

_MESSAGE_REGEX = re.compile(
Expand Down
4 changes: 3 additions & 1 deletion chat_downloader/sites/youtube.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

from datetime import datetime
from .common import (
BaseChatDownloader,
Chat,
Expand Down Expand Up @@ -2176,10 +2176,12 @@ def get_chat_by_video_id(self, video_id, params):
:rtype: Chat
"""
initial_info, ytcfg = self._get_initial_video_info(video_id, params)
date_time = initial_info.get('start_time')/1000000

return Chat(
self._get_chat_messages(initial_info, ytcfg, params),
id=video_id,
date_time=str(datetime.fromtimestamp(date_time)),
**initial_info
)

Expand Down
4 changes: 3 additions & 1 deletion chat_downloader/sites/zoom.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@


from datetime import datetime
import json
import re
from .common import (
Expand Down Expand Up @@ -117,13 +117,15 @@ def get_chat_by_video_id(self, video_id, params, base_url=_ZOOM_HOMEPAGE):

chat_messages = result.get('meetingChatList') or []
title = multi_get(result, 'meet', 'topic')
date_time = datetime.fromtimestamp(float(result.get('fileStartTime'))/1000)
return Chat(
self._get_chat_messages(chat_messages, params),
title=title,
video_type='video',
start_time=result.get('fileStartTime'),
id=video_id,
duration=result.get('duration'),
date_time=str(date_time)
)

def _parse_js_dict(self, json_string):
Expand Down