diff --git a/server/src/main/java/ctbrec/recorder/server/RecorderServlet.java b/server/src/main/java/ctbrec/recorder/server/RecorderServlet.java index 3efb2f46..bb433526 100644 --- a/server/src/main/java/ctbrec/recorder/server/RecorderServlet.java +++ b/server/src/main/java/ctbrec/recorder/server/RecorderServlet.java @@ -8,6 +8,7 @@ import java.security.NoSuchAlgorithmException; import java.time.Instant; import java.util.Iterator; import java.util.List; +import java.util.Objects; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -77,6 +78,12 @@ public class RecorderServlet extends AbstractCtbrecServlet { response = "{\"status\": \"success\", \"msg\": \"Recording started\"}"; resp.getWriter().write(response); break; + case "startByName": + LOG.debug("Starting recording for model {}", request.model.getUrl()); + startByName(request); + response = "{\"status\": \"success\", \"msg\": \"Recording started\"}"; + resp.getWriter().write(response); + break; case "stop": new Thread(() -> { try { @@ -223,6 +230,20 @@ public class RecorderServlet extends AbstractCtbrecServlet { throw new IllegalArgumentException("No site found to record " + url); } + private void startByName(Request request) throws InvalidKeyException, NoSuchAlgorithmException, IOException { + String[] input = request.model.getUrl().split(":"); + String siteName = input[0]; + String modelName = input[1]; + for (Site site : sites) { + if (Objects.equals(siteName.toLowerCase(), site.getClass().getSimpleName().toLowerCase())) { + Model m = site.createModel(modelName); + recorder.startRecording(m); + return; + } + } + throw new IllegalArgumentException("No site found to record " + request.model.getUrl()); + } + private static class Request { public String action; public Model model; diff --git a/server/src/main/resources/html/static/index.html b/server/src/main/resources/html/static/index.html index 66dc1d28..060b6d01 100644 --- a/server/src/main/resources/html/static/index.html +++ b/server/src/main/resources/html/static/index.html @@ -77,13 +77,13 @@
-
+
-
@@ -172,7 +172,7 @@
-
+
@@ -254,35 +254,41 @@ text: ko.observable('') }; let hmac; - + function addModelKeyPressed(e) { let charCode = (typeof e.which === "number") ? e.which : e.keyCode; - if(charCode === 13) { - let url = $('#addModelByUrl').val(); - ctbrec.add(url, function() { + let val = $('#addModelByUrl').val(); + if (charCode === 13) { + ctbrec.add(val, function() { $('#addModelByUrl').val(''); }); + } else { + $('#addModelByUrl').autocomplete({ + source: ["BongaCams:", "Cam4:", "Camsoda:", "Chaturbate:", "Fc2Live:", "Flirt4Free:", "LiveJasmin:", "MyFreeCams:", "Showup:", "Streamate:", "Stripchat:"] + }); } } let ctbrec = { - add: function(modelUrl, onsuccess) { + add: function(input, onsuccess) { try { let model = { type: null, name: '', - url: modelUrl + url: input }; + if(console) console.log(model); - let action = '{"action": "startByUrl", "model": ' + JSON.stringify(model) + '}'; + let action = input.startsWith('http') ? 'startByUrl' : 'startByName'; + let msg = '{"action": "' + action + '", "model": ' + JSON.stringify(model) + '}'; $.ajax({ type : 'POST', url : '../rec', dataType : 'json', async : true, timeout : 60000, - headers : {'CTBREC-HMAC': CryptoJS.HmacSHA256(action, hmac)}, - data : action + headers : {'CTBREC-HMAC': CryptoJS.HmacSHA256(msg, hmac)}, + data : msg }) .done(function(data) { if (data.status === 'success') {