diff --git a/config.toml b/config.toml index 2539382..4b89b64 100644 --- a/config.toml +++ b/config.toml @@ -1,5 +1,5 @@ [General] -BaseDir = "/mnt/media" +BaseDir = "/home/joren/dev/DRMDTool/media" Format = "mkv" TempBaseDir = "/tmp/nre" EnableConsole = true @@ -8,7 +8,7 @@ EnableConsole = true Path = "/mnt/watched" PollingInterval = 10 UsePolling = false -UseInotify = true +UseInotify = false [N_m3u8DLRE] -Path = "nre" \ No newline at end of file +Path = "nre" diff --git a/src/downloaders.go b/src/downloaders.go index 21f7f84..5ceef66 100644 --- a/src/downloaders.go +++ b/src/downloaders.go @@ -195,6 +195,10 @@ func getDownloadCommand(item Item, mpdPath string, tempDir string) string { command += fmt.Sprintf(" --tmp-dir \"%s\"", tempDir) + if globalSpeedLimit != "" { + command += fmt.Sprintf(" -R %s", globalSpeedLimit) + } + fmt.Println(command) return command diff --git a/src/handlers.go b/src/handlers.go index de5889e..da28c77 100644 --- a/src/handlers.go +++ b/src/handlers.go @@ -48,7 +48,11 @@ func handleRoot(w http.ResponseWriter, r *http.Request) { CurrentFile string Paused bool } - }{jobsInfo}) + GlobalSpeedLimit string + }{ + Jobs: jobsInfo, + GlobalSpeedLimit: globalSpeedLimit, + }) if err != nil { logger.LogError("Handle Root", fmt.Sprintf("Error executing template: %v", err)) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -443,3 +447,32 @@ func broadcast(filename string, message []byte) { } } } + +func handleSetSpeedLimit(w http.ResponseWriter, r *http.Request) { + logger.LogInfo("Set Speed Limit", "Received request to set speed limit") + + if r.Method != http.MethodPost { + logger.LogError("Set Speed Limit", "Invalid method") + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) + return + } + + var requestData struct { + SpeedLimit string `json:"speedLimit"` + } + + if err := json.NewDecoder(r.Body).Decode(&requestData); err != nil { + logger.LogError("Set Speed Limit", "Invalid request body") + http.Error(w, "Invalid request", http.StatusBadRequest) + return + } + + if requestData.SpeedLimit == "unlimited" { + globalSpeedLimit = "" + } else { + globalSpeedLimit = requestData.SpeedLimit + } + + logger.LogInfo("Set Speed Limit", fmt.Sprintf("Global speed limit set to: %s", globalSpeedLimit)) + w.WriteHeader(http.StatusOK) +} diff --git a/src/main.go b/src/main.go index c24ed9d..0de1759 100644 --- a/src/main.go +++ b/src/main.go @@ -44,6 +44,8 @@ var templates *template.Template //go:embed templates var templateFS embed.FS +var globalSpeedLimit string + func init() { if err := os.MkdirAll(uploadDir, 0755); err != nil { fmt.Printf("Error creating upload directory: %v\n", err) @@ -70,6 +72,8 @@ func main() { } processItems(*inputFile, items) } + + http.HandleFunc("/set-speed-limit", handleSetSpeedLimit) } func startWebServer() { @@ -83,6 +87,7 @@ func startWebServer() { http.HandleFunc("/resume", handleResume) http.HandleFunc("/clear-completed", handleClearCompleted) http.HandleFunc("/ws", handleWebSocket) + http.HandleFunc("/set-speed-limit", handleSetSpeedLimit) logger.LogInfo("Main", "Starting web server on http://0.0.0.0:8080") http.ListenAndServe(":8080", nil) diff --git a/src/templates/index b/src/templates/index index fff9d5e..1d8ba87 100644 --- a/src/templates/index +++ b/src/templates/index @@ -77,6 +77,11 @@ .paused { color: #ffa500; } + .speed-limit { + font-size: 1em; + color: #a0a0a0; + margin-top: 10px; + } @media (max-width: 600px) { body { padding: 10px; @@ -107,6 +112,39 @@ #clear-completed:hover { background-color: #d32f2f; } + /* New CSS for speed limit form */ + .settings-section { + margin-top: 30px; + } + .speed-limit-form { + display: flex; + align-items: center; + justify-content: space-between; + gap: 10px; + margin-bottom: 20px; + } + .speed-limit-form .form-group { + display: flex; + align-items: center; + gap: 10px; + } + .speed-limit-form input[type="number"], + .speed-limit-form select, + .speed-limit-form button { + background-color: #2d2d2d; + color: #d4d4d4; + border: 1px solid #444; + padding: 8px 12px; + border-radius: 4px; + } + .speed-limit-form button { + cursor: pointer; + background-color: #4CAF50; + color: white; + } + .speed-limit-form button:hover { + background-color: #45a049; + } @@ -135,6 +173,24 @@ {{end}} + +
+

Settings

+
+
+ + + + +
+

Current Speed Limit: {{if .GlobalSpeedLimit}}{{.GlobalSpeedLimit}}{{else}}unlimited{{end}}

+
+
+