Refactor downloader and file manager for improved rclone integration and add healthcheck and smoke test options

- Renamed download flags in ContentDownloader for clarity.
- Enhanced FileManager with methods to build upload paths and verify existing files for rclone uploads.
- Updated StreamProcessor to return success status for stream processing.
- Added rclone smoke test and healthcheck functions to validate configuration and tool availability.
- Improved environment variable handling with a utility function.
- Updated TwitchArchive to incorporate new rclone verification and processing logic.
- Added unit tests for new functionality and refactored existing tests for clarity and coverage.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
MaddoScientisto 2026-04-25 11:54:03 +02:00
commit f97e0200d6
23 changed files with 1013 additions and 289 deletions

View file

@ -4,6 +4,7 @@ Utility functions and helpers for Twitch Archive.
import os
import sys
import shutil
import pathlib
import subprocess
from typing import Optional
@ -35,6 +36,15 @@ def get_bin_path() -> str:
return str(pathlib.Path(__file__).parent.parent.resolve() / "bin")
def get_env_value(*names: str, default: Optional[str] = None) -> Optional[str]:
"""Return the first non-empty environment variable from the provided names."""
for name in names:
value = os.getenv(name)
if value not in (None, ""):
return value
return default
def get_ffmpeg_executable(os_type: str) -> str:
"""
Get the platform-specific ffmpeg executable path.
@ -48,6 +58,11 @@ def get_ffmpeg_executable(os_type: str) -> str:
bin_path = get_bin_path()
if os_type == 'windows':
return os.path.join(bin_path, 'ffmpeg.exe')
system_ffmpeg = shutil.which('ffmpeg')
if system_ffmpeg:
return system_ffmpeg
return os.path.join(bin_path, 'ffmpeg')
@ -64,6 +79,11 @@ def get_twitch_downloader_executable(os_type: str) -> str:
bin_path = get_bin_path()
if os_type == 'windows':
return os.path.join(bin_path, 'TwitchDownloaderCLI.exe')
system_twitch_downloader = shutil.which('TwitchDownloaderCLI')
if system_twitch_downloader:
return system_twitch_downloader
return os.path.join(bin_path, 'TwitchDownloaderCLI')
@ -164,6 +184,24 @@ def verify_streamlink() -> bool:
return False
def verify_rclone() -> bool:
"""Verify that rclone is available on PATH."""
try:
result = subprocess.run(['rclone', 'version'],
capture_output=True,
text=True,
timeout=5)
if result.returncode == 0:
version_line = result.stdout.strip().splitlines()[0] if result.stdout.strip() else 'unknown'
print(f'{Fore.GREEN}✓ Rclone found ({version_line}){Style.RESET_ALL}')
return True
raise FileNotFoundError()
except (FileNotFoundError, subprocess.TimeoutExpired, IndexError):
print(f'{Fore.RED}✗ ERROR: rclone not found{Style.RESET_ALL}')
print(f'{Fore.CYAN} → Install rclone and ensure it is on PATH{Style.RESET_ALL}')
return False
def verify_ffmpeg(os_type: str) -> bool:
"""
Verify that ffmpeg is available.