feat: enhance chat downloading with stream monitoring and improved file paths

This commit is contained in:
MaddoScientisto 2026-02-18 18:11:53 +01:00
commit b47641feaa
3 changed files with 87 additions and 30 deletions

View file

@ -505,6 +505,16 @@ class ContentDownloader:
if not self.download_live_chat:
print(f'{Fore.YELLOW}⚠ downloadLiveCHAT is disabled in config{Style.RESET_ALL}')
return False
# If a stream monitor was provided, check that the user is currently live
if stream_monitor is not None:
try:
if not stream_monitor.is_user_live():
print(f'{Fore.YELLOW}⚠ Stream is not live; skipping chat download{Style.RESET_ALL}')
return False
except Exception as e:
# If we couldn't determine live status, continue and let chat_downloader handle it
print(f'{Fore.YELLOW}⚠ Could not determine live status: {e} - proceeding with chat download{Style.RESET_ALL}')
print(f'\n{Fore.CYAN}Starting live chat download (chat_downloader)...{Style.RESET_ALL}')
print(f'{Fore.MAGENTA}[VERBOSE] chat_downloader library version: {ChatDownloader.__module__}{Style.RESET_ALL}')

View file

@ -129,51 +129,60 @@ class FileManager:
os.makedirs(os.path.dirname(upload_list_path), exist_ok=True)
files_to_upload = []
# Always include metadata and chat JSON
files_to_upload.append(f"{PREFIX_METADATA}{filename_base}.json")
files_to_upload.append(f"{PREFIX_CHAT}{filename_base}.json")
# Add pre-merge videos (original LIVE and VOD files)
# Build files list relative to root_path so rclone can read them with --files-from
# Metadata and chat JSON
files_to_upload.append(os.path.join(self.username, 'metadata', f"{PREFIX_METADATA}{filename_base}.json"))
files_to_upload.append(os.path.join(self.username, 'chat', 'json', f"{PREFIX_CHAT}{filename_base}.json"))
# Pre-merge videos (raw .ts in video/raw, mp4/mp3 in video)
if self.upload_pre_merge_video:
files_to_upload.extend([
f"{PREFIX_LIVE}{filename_base}.ts",
f"{PREFIX_LIVE}{filename_base}.mp4",
f"{PREFIX_LIVE}{filename_base}.mp3",
f"{PREFIX_VOD}{filename_base}.ts",
f"{PREFIX_VOD}{filename_base}.mp4",
f"{PREFIX_VOD}{filename_base}.mp3"
os.path.join(self.username, 'video', 'raw', f"{PREFIX_LIVE}{filename_base}.ts"),
os.path.join(self.username, 'video', f"{PREFIX_LIVE}{filename_base}.mp4"),
os.path.join(self.username, 'video', f"{PREFIX_LIVE}{filename_base}.mp3"),
os.path.join(self.username, 'video', 'raw', f"{PREFIX_VOD}{filename_base}.ts"),
os.path.join(self.username, 'video', f"{PREFIX_VOD}{filename_base}.mp4"),
os.path.join(self.username, 'video', f"{PREFIX_VOD}{filename_base}.mp3")
])
# Add merged videos
# Merged videos (in video folder)
if self.upload_merged_video:
files_to_upload.extend([
f"{PREFIX_MERGED}{filename_base}.mp4",
f"{PREFIX_MERGED}{filename_base}.mp3",
f"{PREFIX_MERGED}{PREFIX_VOD}{filename_base}.mp4",
f"{PREFIX_MERGED}{PREFIX_VOD}{filename_base}.mp3"
os.path.join(self.username, 'video', f"{PREFIX_MERGED}{filename_base}.mp4"),
os.path.join(self.username, 'video', f"{PREFIX_MERGED}{filename_base}.mp3"),
os.path.join(self.username, 'video', f"{PREFIX_MERGED}{PREFIX_VOD}{filename_base}.mp4"),
os.path.join(self.username, 'video', f"{PREFIX_MERGED}{PREFIX_VOD}{filename_base}.mp3")
])
# Add standalone chat video
# Standalone chat video (in chat folder)
if self.upload_chat_video:
files_to_upload.append(f"{PREFIX_CHAT}{filename_base}.mp4")
files_to_upload.append(os.path.join(self.username, 'chat', f"{PREFIX_CHAT}{filename_base}.mp4"))
with open(upload_list_path, 'w') as f:
f.write('\n'.join(files_to_upload))
# Run rclone
# Run rclone using --files-from so the listed paths (relative to root_path) are uploaded.
try:
result = subprocess.call([
cmd = [
'rclone', 'copy',
str(self.root_path.resolve()),
self.rclone_path,
'--include-from', upload_list_path
])
'--files-from', upload_list_path
]
# Stream rclone output to console so user can see progress/errors
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
if proc.stdout:
for line in proc.stdout:
print(line, end='')
proc.wait()
result = proc.returncode
# Clean up upload list
if os.path.exists(upload_list_path):
os.remove(upload_list_path)
if result == 0:
print(f'{Fore.GREEN}✓ Upload complete{Style.RESET_ALL}')
if notification_callback:
@ -186,7 +195,7 @@ class FileManager:
notification_callback(f'✗ Upload Failed - {filename_base}',
f'Upload failed with code {result}. Files preserved locally.')
return False
except Exception as e:
print(f'{Fore.RED}✗ Upload error: {str(e)}{Style.RESET_ALL}')
return False