This project aims to watch a directory for changes, specifically for extracting files after torrent downloads. It looks for media files and moves them to a specific directory to be served by a media server. It then deletes the subdirectory created by the torrent client if it becomes empty.
- Watches a specified directory for new media files.
- Moves media files (
.mp4,.mkv,.avi) to a designated media directory. - Ensures files are fully written before moving them.
- Deletes empty subdirectories after moving files.
- Node.js installed on your system.
- Proper permissions to read from and write to the directories being watched and moved.
-
Clone this repository:
git clone https://github.com/yourusername/torrent-file-organizer.git cd torrent-file-organizer -
Install dependencies:
npm install
-
Update the paths in the script to match your setup:
const mediaDir = '/media/ssd/torrent/files/movies'; const watchDir = '/media/ssd/torrent/files';
-
Run the script:
node index.js
-
If needed, run the script with elevated permissions to ensure it can access and modify the files:
sudo node index.js
- Watcher Setup: Uses
chokidarto watch the specified directory for new files and directories. - File Check: Ensures files are fully written before moving by checking file size stability over 1 second intervals.
- File Move: Moves detected media files to the specified media directory.
- Directory Cleanup: Deletes subdirectories if they become empty after file moves.
The script includes error handling for common issues such as permission errors and read/write errors, with appropriate logging to the console.
This project is licensed under the MIT License. See the LICENSE file for details.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/your-feature). - Commit your changes (
git commit -am 'Add some feature'). - Push to the branch (
git push origin feature/your-feature). - Create a new Pull Request.
- chokidar - A neat wrapper around Node.js fs.watch / fs.watchFile / fsevents.
This project simplifies the process of organizing downloaded media files, ensuring they are quickly and efficiently moved to the appropriate directory for serving via a media server.