diff --git a/.gitignore b/.gitignore index ea8c4bf..55fcc26 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,53 @@ +# Rust build artifacts /target +**/*.rs.bk +*.pdb + +# Environment files +.env +.env.* +*.env + +# IDE and editor files +.idea/ +.vscode/ +*.swp +*.swo +*~ +.DS_Store + +# Log files +*.log +logs/ + +# Temporary files +*.tmp +*.temp +.syncthing.* + +# System files +Thumbs.db + +# Backup files +*.bak +*.backup + +# Configuration files with sensitive data +config.toml +config.yaml +config.json +settings.toml +settings.yaml +settings.json + +# Private keys and certificates +*.key +*.pem +*.crt +*.pfx + +# Video files (if you don't want to commit them) +*.mp4 +*.avi +*.mov +*.mkv diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fe1c2fa --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Rockville Tolland SDA Church + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3da792 --- /dev/null +++ b/README.md @@ -0,0 +1,119 @@ +# Sermon Converter + +A Rust-based service that automatically monitors a directory for new sermon video files and converts them to an optimized format for streaming. + +## Features + +- Automatic detection of new MP4 files in the watch directory +- Efficient video conversion using FFmpeg +- Preserves audio quality while optimizing video for streaming +- Automatic file organization with date-based naming +- Syncthing-aware (ignores temporary sync files) + +## Prerequisites + +- Rust (latest stable version) +- FFmpeg installed and available in PATH +- Sufficient disk space for video processing + +## Installation + +1. Clone the repository: +```bash +git clone +cd sermon-converter +``` + +2. Build the project: +```bash +cargo build --release +``` + +## Configuration + +The service uses environment variables for configuration: + +- `SERMON_WATCH_PATH`: Directory to monitor for new sermon videos +- `SERMON_OUTPUT_PATH`: Directory where converted videos will be saved + +Example: +```bash +export SERMON_WATCH_PATH="/path/to/watch/directory" +export SERMON_OUTPUT_PATH="/path/to/output/directory" +``` + +## Usage + +Run the service: +```bash +cargo run --release +``` + +Or run the built binary: +```bash +./target/release/sermon_converter +``` + +The service will: +1. Process any existing MP4 files in the watch directory +2. Continue monitoring for new files +3. Automatically convert new MP4 files as they appear + +## Running as a System Service + +To run as a systemd service, create a service file at `/etc/systemd/system/sermon-converter.service`: + +```ini +[Unit] +Description=Sermon Video Converter Service +After=network.target + +[Service] +Type=simple +User= +Environment="SERMON_WATCH_PATH=/path/to/watch/directory" +Environment="SERMON_OUTPUT_PATH=/path/to/output/directory" +ExecStart=/path/to/sermon_converter +Restart=always +RestartSec=10 + +[Install] +WantedBy=multi-user.target +``` + +Enable and start the service: +```bash +sudo systemctl enable sermon-converter +sudo systemctl start sermon-converter +``` + +## Video Conversion Details + +The service converts videos using the following FFmpeg settings: +- Video codec: H.264 (libx264) +- Audio codec: AAC +- Video preset: medium +- Constant Rate Factor (CRF): 23 +- Pixel format: yuv420p +- Audio bitrate: 128k +- Audio sample rate: 44100 Hz + +## File Naming Convention + +Converted files are named based on the original filename's date pattern: +- Input: `YYYY-MM-DD_sermon.mp4` +- Output: `YYYY-MM-DD_sermon_converted.mp4` + +## Troubleshooting + +- **FFmpeg not found**: Ensure FFmpeg is installed and in your system PATH +- **Permission denied**: Check that the service has read/write permissions for both watch and output directories +- **Files not detected**: Verify the watch directory path and that files are complete before processing + +## License + +See LICENSE file for details. + +## Contributing + +Contributions are welcome! Please submit pull requests or issues through the repository. \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 58cfad8..22f6451 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use std::path::PathBuf; +use std::env; use anyhow::Result; use notify::{Watcher, RecursiveMode, Event, EventKind}; use tokio::sync::mpsc; @@ -8,8 +9,12 @@ use services::sermon_converter::VideoConverter; #[tokio::main] async fn main() -> Result<()> { - let watch_path = PathBuf::from("/home/rockvilleav/Sync/Sermons"); - let output_path = PathBuf::from("/media/archive/jellyfin/sermons"); + let watch_path = PathBuf::from( + env::var("SERMON_WATCH_PATH").expect("SERMON_WATCH_PATH environment variable must be set") + ); + let output_path = PathBuf::from( + env::var("SERMON_OUTPUT_PATH").expect("SERMON_OUTPUT_PATH environment variable must be set") + ); // Ensure directories exist if !watch_path.exists() {