From 83cd0b722b390d14925463afd57548b9868a0ec3 Mon Sep 17 00:00:00 2001 From: Joren Date: Mon, 30 Dec 2024 16:04:37 +0100 Subject: [PATCH 1/8] style --- config.toml | 6 ++-- src/downloaders.go | 4 +++ src/handlers.go | 35 +++++++++++++++++++- src/main.go | 5 +++ src/templates/index | 78 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 124 insertions(+), 4 deletions(-) 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}}

+
+
+ -- 2.45.2 From 68da5f9658c7deec0d6c83db2f65bb5632eaed3c Mon Sep 17 00:00:00 2001 From: Joren Date: Mon, 30 Dec 2024 16:16:21 +0100 Subject: [PATCH 2/8] Speed --- src/templates/index | 68 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/src/templates/index b/src/templates/index index 1d8ba87..ed10ece 100644 --- a/src/templates/index +++ b/src/templates/index @@ -45,7 +45,10 @@ ul { list-style-type: none; padding: 0; - margin-bottom: 10px; + margin-bottom: 10px; + background-color: #2d2d2d; + border: 1px solid #444; + border-radius: 4px; } li { background-color: #2d2d2d; @@ -145,6 +148,53 @@ .speed-limit-form button:hover { background-color: #45a049; } + .speed-limit-container { + display: flex; + align-items: center; + margin-bottom: 20px; + background-color: #2d2d2d; + padding: 8px 12px; + border-radius: 4px; + border: 1px solid #444; + } + .speed-limit-container .form-group { + display: flex; + align-items: center; + gap: 10px; + width: 100%; + } + .speed-limit-container input[type="number"], + .speed-limit-container select, + .speed-limit-container button { + background-color: #2d2d2d; + color: #d4d4d4; + border: 1px solid #444; + padding: 8px 12px; + border-radius: 4px; + height: 40px; + box-sizing: border-box; + } + .speed-limit-container button { + cursor: pointer; + background-color: #4CAF50; + color: white; + } + .speed-limit-container button:hover { + background-color: #45a049; + } + .speed-limit-container .speed-limit { + color: #d4d4d4; + margin-left: auto; + display: flex; + align-items: center; + } + .speed-limit-container .speed-limit span { + margin-left: 5px; + } + .current-speed-limit { + color: #d4d4d4; + margin-top: 10px; + } @@ -176,7 +226,7 @@

Settings

-
+
@@ -187,8 +237,7 @@
-

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

- +
-- 2.45.2 From 189bbb0874fba9cb27ec7f1c83717cc7fc6186e7 Mon Sep 17 00:00:00 2001 From: Joren Date: Mon, 30 Dec 2024 16:16:37 +0100 Subject: [PATCH 3/8] Speed --- src/templates/index | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/templates/index b/src/templates/index index ed10ece..613fb0c 100644 --- a/src/templates/index +++ b/src/templates/index @@ -16,6 +16,7 @@ box-sizing: border-box; } h1, h2 { + text-align: center; border-bottom: 1px solid #333; padding-bottom: 10px; word-wrap: break-word; @@ -49,6 +50,7 @@ background-color: #2d2d2d; border: 1px solid #444; border-radius: 4px; + text-align: center; } li { background-color: #2d2d2d; @@ -56,6 +58,7 @@ padding: 10px; border-radius: 4px; word-wrap: break-word; + text-align: center; } .job-title { font-size: 1.1em; @@ -151,6 +154,7 @@ .speed-limit-container { display: flex; align-items: center; + justify-content: center; margin-bottom: 20px; background-color: #2d2d2d; padding: 8px 12px; @@ -162,6 +166,7 @@ align-items: center; gap: 10px; width: 100%; + justify-content: center; } .speed-limit-container input[type="number"], .speed-limit-container select, -- 2.45.2 From 7eb724d01fece1abadb7deea59bce5ac4a98cc24 Mon Sep 17 00:00:00 2001 From: Joren Date: Mon, 30 Dec 2024 16:16:51 +0100 Subject: [PATCH 4/8] Speed --- src/templates/index | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/templates/index b/src/templates/index index 613fb0c..ed10ece 100644 --- a/src/templates/index +++ b/src/templates/index @@ -16,7 +16,6 @@ box-sizing: border-box; } h1, h2 { - text-align: center; border-bottom: 1px solid #333; padding-bottom: 10px; word-wrap: break-word; @@ -50,7 +49,6 @@ background-color: #2d2d2d; border: 1px solid #444; border-radius: 4px; - text-align: center; } li { background-color: #2d2d2d; @@ -58,7 +56,6 @@ padding: 10px; border-radius: 4px; word-wrap: break-word; - text-align: center; } .job-title { font-size: 1.1em; @@ -154,7 +151,6 @@ .speed-limit-container { display: flex; align-items: center; - justify-content: center; margin-bottom: 20px; background-color: #2d2d2d; padding: 8px 12px; @@ -166,7 +162,6 @@ align-items: center; gap: 10px; width: 100%; - justify-content: center; } .speed-limit-container input[type="number"], .speed-limit-container select, -- 2.45.2 From 457ede5b62f67b8acf02c847ed726504e31237a0 Mon Sep 17 00:00:00 2001 From: Joren Date: Mon, 30 Dec 2024 16:20:48 +0100 Subject: [PATCH 5/8] Speed --- src/templates/index | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/templates/index b/src/templates/index index ed10ece..7470463 100644 --- a/src/templates/index +++ b/src/templates/index @@ -45,10 +45,7 @@ ul { list-style-type: none; padding: 0; - margin-bottom: 10px; - background-color: #2d2d2d; - border: 1px solid #444; - border-radius: 4px; + margin-bottom: 10px; } li { background-color: #2d2d2d; -- 2.45.2 From f1efb1d67c89e278be22c15d8ebc76abcbe29466 Mon Sep 17 00:00:00 2001 From: Joren Date: Mon, 30 Dec 2024 16:32:12 +0100 Subject: [PATCH 6/8] impl speed limit --- config.toml | 4 ++-- src/templates/index | 29 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/config.toml b/config.toml index 4b89b64..04a2c04 100644 --- a/config.toml +++ b/config.toml @@ -5,9 +5,9 @@ TempBaseDir = "/tmp/nre" EnableConsole = true [WatchFolder] -Path = "/mnt/watched" +Path = "/home/joren/dev/DRMDTool/folder" PollingInterval = 10 -UsePolling = false +UsePolling = true UseInotify = false [N_m3u8DLRE] diff --git a/src/templates/index b/src/templates/index index 7470463..1e6d92a 100644 --- a/src/templates/index +++ b/src/templates/index @@ -28,7 +28,6 @@ input[type="file"], input[type="submit"] { background-color: #2d2d2d; color: #d4d4d4; - border: 1px solid #444; padding: 8px 12px; border-radius: 4px; margin-bottom: 10px; @@ -152,7 +151,6 @@ background-color: #2d2d2d; padding: 8px 12px; border-radius: 4px; - border: 1px solid #444; } .speed-limit-container .form-group { display: flex; @@ -160,7 +158,16 @@ gap: 10px; width: 100%; } - .speed-limit-container input[type="number"], + .speed-limit-container input[type="number"] { + background-color: #2d2d2d; + color: #d4d4d4; + border: 1px solid #444; + padding: 8px 12px; + border-radius: 4px; + height: 40px; + box-sizing: border-box; + flex-grow: 1; + } .speed-limit-container select, .speed-limit-container button { background-color: #2d2d2d; @@ -225,14 +232,14 @@

Settings

- + - +
@@ -249,6 +256,7 @@ } }); } + function updateSpeedLimit(event) { event.preventDefault(); @@ -256,6 +264,11 @@ const speedLimitUnit = document.getElementById('speedLimitUnit').value; const speedLimit = speedLimitValue === "0" ? "unlimited" : speedLimitValue + speedLimitUnit; + if (!validateSpeedLimit(speedLimitValue)) { + alert('Please enter a valid speed limit.'); + return; + } + fetch('/set-speed-limit', { method: 'POST', headers: { @@ -271,6 +284,12 @@ } }); } + + function validateSpeedLimit(value) { + const number = parseFloat(value); + return !isNaN(number) && number >= 0; + } + document.addEventListener('DOMContentLoaded', function() { const currentSpeedLimit = "{{if .GlobalSpeedLimit}}{{.GlobalSpeedLimit}}{{else}}0{{end}}"; const speedLimitValueInput = document.getElementById('speedLimitValue'); -- 2.45.2 From 2e18921a2713d17005e6a79e4c227e806a97cccc Mon Sep 17 00:00:00 2001 From: Joren Date: Mon, 30 Dec 2024 16:45:56 +0100 Subject: [PATCH 7/8] Show limit --- config.toml | 2 +- src/templates/index | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/config.toml b/config.toml index 04a2c04..808531f 100644 --- a/config.toml +++ b/config.toml @@ -7,7 +7,7 @@ EnableConsole = true [WatchFolder] Path = "/home/joren/dev/DRMDTool/folder" PollingInterval = 10 -UsePolling = true +UsePolling = false UseInotify = false [N_m3u8DLRE] diff --git a/src/templates/index b/src/templates/index index 1e6d92a..8e2135d 100644 --- a/src/templates/index +++ b/src/templates/index @@ -293,12 +293,15 @@ document.addEventListener('DOMContentLoaded', function() { const currentSpeedLimit = "{{if .GlobalSpeedLimit}}{{.GlobalSpeedLimit}}{{else}}0{{end}}"; const speedLimitValueInput = document.getElementById('speedLimitValue'); - - // Extract numeric value and unit + const speedLimitUnitSelect = document.getElementById('speedLimitUnit'); + const match = currentSpeedLimit.match(/(\d+(\.\d+)?)([A-Za-z]+)/); if (match) { - speedLimitValueInput.value = match[1]; // Set the numeric value - document.getElementById('speedLimitUnit').value = match[3]; // Set the unit + speedLimitValueInput.value = match[1]; + speedLimitUnitSelect.value = match[3]; + } else { + speedLimitValueInput.value = "0"; + speedLimitUnitSelect.value = "MBps"; } }); -- 2.45.2 From 8cf3d4dda8415b64ff9695fe47d1c1cd6f548726 Mon Sep 17 00:00:00 2001 From: Joren Date: Mon, 30 Dec 2024 16:46:30 +0100 Subject: [PATCH 8/8] Show limit --- config.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.toml b/config.toml index 808531f..ae3d0fd 100644 --- a/config.toml +++ b/config.toml @@ -1,11 +1,11 @@ [General] -BaseDir = "/home/joren/dev/DRMDTool/media" +BaseDir = "/mnt/Media" Format = "mkv" TempBaseDir = "/tmp/nre" EnableConsole = true [WatchFolder] -Path = "/home/joren/dev/DRMDTool/folder" +Path = "/mnt/Watched" PollingInterval = 10 UsePolling = false UseInotify = false -- 2.45.2