add channel ID, expand readme

This commit is contained in:
Glyphscribe Ety
2025-04-27 12:11:34 -05:00
parent bfa12f842e
commit 949f576fec
4 changed files with 72 additions and 9 deletions

View File

@ -65,6 +65,27 @@ def merge_segments_to_mp4(segments: list[str], output_path: Path, output_filenam
return output_file
def delete_clip(filename: str):
"""
Deletes a named file from the temporary directory
Args:
filename (str): The name of the file to be deleted, e.g. file.mp4
Returns:
None
"""
file = config.TEMP_DIRECTORY / filename
try:
file.unlink()
except FileNotFoundError:
print(f'Error deleting temporary file: {file}; file not found.')
except Exception as e:
print(f'Error deleting temporary file: {file}; {e}.')
return
def generate_and_post_clip(user: str, title: str, timestamp: datetime):
"""
Invokes clip collection, remux, upload, and notification (chat) routines.
@ -78,16 +99,16 @@ def generate_and_post_clip(user: str, title: str, timestamp: datetime):
None
"""
recent_clips = get_recent_segments(
config.CLIP_DIRECTORY, config.CLIP_QUANTITY)
if not (recent_clips := get_recent_segments(config.CLIP_DIRECTORY, config.CLIP_QUANTITY)):
return
new_filename = f'{timestamp.strftime("%Y%m%d_%H%M%S_%f")}.mp4'
new_filepath = merge_segments_to_mp4(
recent_clips, config.TEMP_DIRECTORY, new_filename)
if (token := authenticate_to_peertube(config.PT_API_BASE, config.PEERTUBE_USER, config.PEERTUBE_PASS)) is None:
print(f'Failed to authenticate to PeerTube', file=sys.stderr)
delete_clip(new_filename)
return
# TODO: handle this gracefully
stream_title = ''
if (stream_title := get_owncast_title()):
@ -97,14 +118,15 @@ def generate_and_post_clip(user: str, title: str, timestamp: datetime):
upload_options[
'description'] = f'🎞️ Clipped by **{user}** {stream_title} on {timestamp.strftime("%Y-%m-%d %H:%M:%S")}'
upload_options['description'] += f'\n🌐 {config.OWNCAST_HOST}'
if (video_url := upload_to_peertube(config.PT_API_BASE, token, new_filepath, 3800, title, **upload_options)) is None:
if (video_url := upload_to_peertube(config.PT_API_BASE, token, new_filepath, config.PEERTUBE_CHANNEL_ID, title, **upload_options)) is None:
print(f'Failed to upload file to PeerTube', file=sys.stderr)
delete_clip(new_filename)
return
# TODO: handle this gracefully
delete_clip(new_filename)
clip_url = f'{config.PEERTUBE_HOST}{video_url}'
message = f'**{title}**: {clip_url}'
send_owncast_message(message)
print(f'Clip created by {user} at {timestamp}: {clip_url}')
return