This repository provides an automated torrent management system that integrates with qBittorrent's Web API to categorize, process, and organize downloads from multiple sources (Empornium, OneJav). It includes robust error handling, file system monitoring, and automatic cleanup of non-media content.
- Automatic Torrent Categorization: Identifies torrent origin from metadata and assigns appropriate categories
- Smart File Processing: Moves completed downloads to organized destination folders, removes non-video files, and handles cross-filesystem moves
- Reliable Monitoring: Alternative monitor system using polling and a systemd service (bypasses qBittorrent's unreliable external program feature)
- OneJav Torrent Fetcher: Automated script to download torrent files from OneJav.com with pagination support
- Comprehensive Logging: Detailed logging system with error tracking and rotation support
- Configuration Validation: Built-in tools to verify setup and dependencies
- Cross-Platform: Built with Deno for consistent behavior across different operating systems
- qBittorrent Handler: Core system for categorizing and processing torrents based on origin and content
- OneJav Torrent Fetcher: Standalone script for automated torrent file downloading from OneJav.com
--
monitor-torrents.js: Reliable alternative to qBittorrent's external programs using periodic polling (no trigger file support) qbittorrent-monitor.service: Systemd service for automatic monitor startup and management --trigger-monitor.js(removed): The previous trigger script has been deprecated and removed from active useconfig.js: Centralized configuration management with environment variable supportsharedFunctions.js: Common utilities including logging, API calls, and error handlingvalidate-config.js: Configuration validation and health check tool
The system operates in two modes:
- qBittorrent calls
torrentProcessor.jsdirectly when torrents are added/finished - Uses qBittorrent's built-in "Run external program" feature
- Note: This method has reliability issues in recent qBittorrent versions
-### 2. Monitor Mode
- Periodic polling:
monitor-torrents.jsperiodically polls the qBittorrent API to find completed torrents and process them. - Provides reliable, continuous processing without reliance on qBittorrent external programs or trigger files.
- Runs as a systemd service for continuous operation
- Includes fallback polling every 5 minutes for missed events
- Runtime: Deno 1.40+
- qBittorrent: Version 5.1.2+ with Web UI enabled
- System: Linux with systemd (for monitor service) or manual process management
- Permissions: Network access, file system read/write, and process execution
- Storage: Adequate space for temporary downloads and final organized content
curl -fsSL https://deno.land/install.sh | sh
# Add to PATH: export PATH="$HOME/.deno/bin:$PATH"git clone https://github.com/yourusername/qbittorrent_downloadhandler.git
cd qbittorrent_downloadhandler# Copy example config (if available) or create .env file
cp .env.example .env # if .env.example exists
# Edit .env with your settings (see Configuration section below)deno run --allow-net --allow-read --allow-write --allow-env validate-config.js# Install systemd service
sudo cp qbittorrent-monitor.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable qbittorrent-monitor.service
sudo systemctl start qbittorrent-monitor.service
# Check status
sudo systemctl status qbittorrent-monitor.serviceIn qBittorrent settings → Behavior → Run external program:
For Monitor Mode:
The monitor operates as a polling service; no qBittorrent external program configuration is necessary. For users who prefer immediate execution via qBittorrent, use torrentProcessor.js under the traditional mode settings instead.
For Traditional Mode:
- On torrent added:
deno run --allow-all torrentProcessor.js "%N" "%L" "%G" "%F" "%R" "%D" "%C" "%Z" "%T" "%I" "%J" "%K" added - On torrent finished:
deno run --allow-all torrentProcessor.js "%N" "%L" "%G" "%F" "%R" "%D" "%C" "%Z" "%T" "%I" "%J" "%K" finished
All settings can be customized via environment variables in a .env file or directly in the shell. The system provides sensible defaults.
QB_HOST: qBittorrent host (default:localhost)QB_PORT: qBittorrent Web UI port (default:8080, note: your setup uses 12389)QB_PROTOCOL: HTTP protocol (default:http)QB_USERNAME: Web UI username (default: none)QB_PASSWORD: Web UI password (default: none)
EMPORNIUM_FINISHED_PATH: Destination for Empornium torrents (default:/mnt/ST26/Torrents/Fertig/Porn/EmporniumFinished/)ONEJAV_FINISHED_PATH: Destination for OneJav torrents (default:/mnt/ST26/Torrents/Fertig/Porn/OnejavFinished/)TEMP_DOWNLOAD_PATH: Temporary download directory (default:/mnt/Torrent/Torrents/Fertig)
LOG_FILE: Main log file (default:./log.log)ERROR_LOG_FILE: Error log file (default:./error.log)LOG_LEVEL: Logging verbosity (default:info, options:debug,info,warn,error)
MAX_RETRIES: API retry attempts (default:3)API_TIMEOUT: API request timeout in ms (default:30000)MAX_LOG_SIZE: Maximum log file size in bytes (default:1048576/ 1MB)MAX_FILE_SIZE: Maximum file size to process in bytes (default:10737418240/ 10GB)
ONEJAV_ENABLED: Enable/disable OneJav fetcher (default:true)ONEJAV_BASE_URL: OneJav website base URL (default:https://onejav.com)ONEJAV_DOWNLOAD_PATH: Local torrent download directory (default:./torrents/)ONEJAV_RATE_LIMIT: Delay between requests in ms (default:1000)ONEJAV_MAX_PAGES: Maximum pages to fetch per run (default:10)
# qBittorrent Settings
QB_HOST=localhost
QB_PORT=12389
QB_USERNAME=admin
QB_PASSWORD=yourpassword
# File Paths
EMPORNIUM_FINISHED_PATH=/mnt/ST26/Torrents/Fertig/Porn/EmporniumFinished/
ONEJAV_FINISHED_PATH=/mnt/ST26/Torrents/Fertig/Porn/OnejavFinished/
TEMP_DOWNLOAD_PATH=/mnt/Torrent/Torrents/Fertig
# Logging
LOG_LEVEL=info
LOG_FILE=/var/log/qbittorrent-handler.log
# Processing
MAX_RETRIES=3
API_TIMEOUT=30000# Fetch yesterday's torrents
deno run --allow-net --allow-write fetchOnejav.js
# Fetch torrents from specific date
deno run --allow-net --allow-write fetchOnejav.js "2024-10-28"deno run --allow-net --allow-read --allow-write --allow-env validate-config.js# Test with sample arguments
deno run --allow-all torrentProcessor.js "Test Torrent" "" "" "/tmp/test" "/tmp/root" "/tmp/save" "1" "1000000" "http://test.tracker" "testhash1" "testhash2" "testid123" "finished"# Start monitor
sudo systemctl start qbittorrent-monitor.service
# Check logs
sudo journalctl -u qbittorrent-monitor.service -f
# Restart monitor
sudo systemctl restart qbittorrent-monitor.serviceqbittorrent_downloadhandler/
├── config.js # Configuration management
├── sharedFunctions.js # Common utilities and logging
├── torrentProcessor.js # Main entry point for traditional mode
├── handleAddedTorrent.js # Categorization logic
├── handleFinishedTorrent.js # File processing and cleanup
├── monitor-torrents.js # Reliable monitoring system
├── (trigger-monitor.js removed)
├── fetchOnejav.js # OneJav torrent fetcher
├── validate-config.js # Configuration validation
├── qbittorrent-monitor.service # Systemd service file
├── docs/
│ ├── Qbittorrent.md # qBittorrent handler documentation
│ └── Onejav.md # OneJav fetcher documentation
├── log.log # Main application log
├── error.log # Error log
└── torrents/ # Downloaded torrent files
-
Permission Denied Errors
- Ensure Deno has proper permissions:
--allow-net --allow-read --allow-write --allow-run - Check file system permissions for destination paths
- Verify systemd service has correct
ReadWritePaths
- Ensure Deno has proper permissions:
-
qBittorrent API Connection Failed
- Verify Web UI is enabled in qBittorrent settings
- Check
QB_HOSTandQB_PORTmatch your qBittorrent configuration - Test API access:
curl http://localhost:12389/api/v2/app/version
-
Monitor Not Starting
- Check systemd service status:
sudo systemctl status qbittorrent-monitor.service - View logs:
sudo journalctl -u qbittorrent-monitor.service - Verify Deno binary path in service file
- Check systemd service status:
-
Files Not Moving to Destination
- Check if paths exist and are writable:
ls -la /mnt/ST26/Torrents/Fertig/Porn/ - Verify cross-filesystem moves work (monitor logs for cross-device errors)
- Test manual move:
mv /tmp/testfile /mnt/ST26/Torrents/Fertig/Porn/test/
- Check if paths exist and are writable:
Monitor log files for detailed debugging:
# View recent logs
tail -f log.log
# View errors only
grep "ERROR" error.log
# Monitor service logs
sudo journalctl -u qbittorrent-monitor.service -fThe project includes basic validation. For comprehensive testing:
# Run configuration validation
deno run --allow-net --allow-read --allow-write validate-config.js
# Test individual components
deno run --allow-all test_args.txt # Uses test arguments- New Torrent Sources: Extend
getTorrentOrigin()insharedFunctions.js - Custom Processing: Modify
handleFinishedTorrent.jsfor specific file types - Enhanced Monitoring: Add new trigger types in
monitor-torrents.js
- API Access: Restrict qBittorrent Web UI to localhost only
- File Permissions: Set proper ownership on destination directories
- Network Access: Monitor only allows necessary network permissions
- Log Files: Rotate logs regularly to prevent disk space issues
This project is open source. See LICENSE for details.
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Update documentation
- Submit a pull request
For major changes, please open an issue first to discuss your ideas.
Current Status: Production-ready with monitor system. Traditional external program mode available but less reliable.
Todo: See todo.md for planned enhancements and bug fixes.