diff --git a/README.md b/README.md index a4a4808..c07d9fe 100644 --- a/README.md +++ b/README.md @@ -7,17 +7,50 @@ drmdtool is a utility for processing .drmd files using N_m3u8DL-RE. Create a `config.toml` file in the same directory as the drmdtool executable: ```toml +[General] BaseDir = "/path/to/save/downloads" Format = "mkv" TempBaseDir = "/tmp/nre" EnableConsole = true -WatchedFolder = "/path/to/watched/folder" -[N_m3u8DL-RE] +[WatchFolder] +Path = "/path/to/watched/folder" +PollingInterval = 10 +UsePolling = true +UseInotify = false + +[N_m3u8DLRE] Path = "/path/to/N_m3u8DL-RE" ``` -Adjust the paths and format as needed. (mkv, mp4) +### Configuration Options + +- **General** + - `BaseDir`: Directory where downloaded files will be saved. + - `Format`: Output format for the downloaded files (e.g., `mkv`, `mp4`). + - `TempBaseDir`: Temporary directory for intermediate files. + - `EnableConsole`: Boolean to enable or disable console output. + +- **WatchFolder** + - `Path`: Directory to watch for new `.drmd` files. + - `PollingInterval`: Interval in seconds for polling the watch folder. + - `UsePolling`: Boolean to enable or disable folder polling. + - `UseInotify`: Boolean to enable or disable inotify for file watching. + +- **N_m3u8DLRE** + - `Path`: Path to the N_m3u8DL-RE executable. + +### Environment Variable Overrides + +You can override the configuration options using environment variables. The following environment variables are supported: + +- `BASE_DIR`: Overrides `General.BaseDir` +- `FORMAT`: Overrides `General.Format` +- `TEMP_BASE_DIR`: Overrides `General.TempBaseDir` +- `WATCHED_FOLDER`: Overrides `WatchFolder.Path` +- `USE_POLLING`: Overrides `WatchFolder.UsePolling` (set to `true` or `false`) +- `USE_INOTIFY`: Overrides `WatchFolder.UseInotify` (set to `true` or `false`) +- `POLLING_INTERVAL`: Overrides `WatchFolder.PollingInterval` ## Web UI Usage @@ -30,7 +63,6 @@ Adjust the paths and format as needed. (mkv, mp4) 3. Use the interface to upload .drmd files and monitor download progress - ## CLI Usage To process a file directly from the command line: @@ -41,7 +73,6 @@ To process a file directly from the command line: This will download the file and save it in the base directory specified in the config. - # Previews ## Index Page diff --git a/src/watcher.go b/src/watcher.go index fd1d982..660a4dc 100644 --- a/src/watcher.go +++ b/src/watcher.go @@ -13,6 +13,16 @@ import ( ) func watchFolder() { + if config.WatchFolder.UsePolling { + go pollFolder() + } + + if config.WatchFolder.UseInotify { + go inotifyWatch() + } +} + +func inotifyWatch() { watcher, err := fsnotify.NewWatcher() if err != nil { log.Fatal(err) @@ -43,13 +53,31 @@ func watchFolder() { } }() - err = watcher.Add(config.WatchedFolder) + err = watcher.Add(config.WatchFolder.Path) if err != nil { log.Fatal(err) } <-done } +func pollFolder() { + ticker := time.NewTicker(time.Duration(config.WatchFolder.PollingInterval) * time.Second) + defer ticker.Stop() + + for range ticker.C { + files, err := filepath.Glob(filepath.Join(config.WatchFolder.Path, "*.drmd")) + if err != nil { + log.Println("Error polling folder:", err) + continue + } + + for _, file := range files { + fmt.Println("New .drmd detected via polling:", file) + go processWatchedFile(file) + } + } +} + func processWatchedFile(filePath string) { for { initialSize, err := getFileSize(filePath)