# Livestream Archiver A Rust application that monitors a directory for livestream recordings, processes them, and syncs them to a remote server. Designed for automated livestream archiving with hardware-accelerated transcoding. ## Features - **File Detection**: Monitors a configured directory for new MP4 files - **Readiness Check**: Waits for files to be completely written before processing - **Remote Sync**: Uses rsync to send files to a remote server immediately after detection - **Caching & Retry**: Caches failed syncs and retries them on subsequent runs - **Processing**: Converts files to AV1 using QSV hardware acceleration - **Organization**: Creates date-based directory structure in Jellyfin format - **Cleanup**: Deletes original files after successful processing and sync - **Systemd Integration**: Runs as a system service with automatic restart ## Installation ### Prerequisites - Rust toolchain (1.70 or later) - `rsync` for file synchronization - `ffmpeg` compiled with Intel QSV support - SSH key authentication configured for passwordless rsync ### Building from Source ```bash # Clone the repository git clone cd livestream-archiver # Build release binary cargo build --release # Binary will be at target/release/livestream-archiver ``` ### Quick Deploy ```bash # Use the included deploy script ./deploy.sh ``` ## Configuration Set the `PC_SYNC_TARGET` environment variable to configure where files are synced: ```bash export PC_SYNC_TARGET="user@192.168.1.100:/path/to/destination/" ``` If not set, defaults to: `user@192.168.1.100:/path/to/destination/` ## Usage ### Running Manually ```bash # Run directly cargo run # Or run the compiled binary ./target/release/livestream-archiver ``` ### Running as a Service ```bash # Copy the service file sudo cp livestream-archiver.service /etc/systemd/system/ # Reload systemd and enable the service sudo systemctl daemon-reload sudo systemctl enable livestream-archiver sudo systemctl start livestream-archiver # Check service status sudo systemctl status livestream-archiver ``` The application will: 1. Check for existing unprocessed files 2. Start monitoring for new files 3. For each detected file: - Wait for it to be ready (stable size/modification time) - Sync to PC using rsync - Convert to AV1 format - Create NFO metadata file - Delete original file ## Directory Structure Output files are organized as: ``` / ├── 2024/ │ ├── 01-January/ │ │ ├── Livestream - January 01 2024.mp4 │ │ ├── Livestream - January 01 2024.nfo │ │ └── ... │ └── ... └── ... ``` ## Environment Variables - `PC_SYNC_TARGET`: Remote sync destination (e.g., `user@server:/path/to/destination/`) - `INPUT_DIR`: Directory to monitor for new files (default: `/home/user/Sync/Livestreams`) - `OUTPUT_DIR`: Local output directory for processed files (default: `/media/archive/jellyfin/livestreams`) ## Troubleshooting ### Service not starting - Check logs: `journalctl -u livestream-archiver -f` - Verify paths exist and have proper permissions - Ensure ffmpeg has QSV support: `ffmpeg -hwaccels | grep qsv` ### Sync failures - Verify SSH key authentication to remote server - Check network connectivity - Review cached sync files in `~/.cache/livestream-archiver/` ## License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. ## Contributing Contributions are welcome! Please feel free to submit a Pull Request.