forked from j62/ctbrec
Extend manual add function to allow to add models by their URL
This commit is contained in:
parent
88bddcb188
commit
afd5d3caa3
|
@ -1,3 +1,9 @@
|
||||||
|
1.12.2
|
||||||
|
========================
|
||||||
|
* Fix: Player not starting when path contains spaces
|
||||||
|
* Added setting to toggle "Player Starting" message
|
||||||
|
* Added possibility to add models by their URL
|
||||||
|
|
||||||
1.12.1
|
1.12.1
|
||||||
========================
|
========================
|
||||||
* Fixed downloads in client / server mode
|
* Fixed downloads in client / server mode
|
||||||
|
|
|
@ -155,8 +155,8 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
|
||||||
ObservableList<String> suggestions = FXCollections.observableArrayList();
|
ObservableList<String> suggestions = FXCollections.observableArrayList();
|
||||||
sites.forEach(site -> suggestions.add(site.getName()));
|
sites.forEach(site -> suggestions.add(site.getName()));
|
||||||
model = new AutoFillTextField(suggestions);
|
model = new AutoFillTextField(suggestions);
|
||||||
model.setPrefWidth(300);
|
model.setPrefWidth(600);
|
||||||
model.setPromptText("e.g. MyFreeCams:ModelName");
|
model.setPromptText("e.g. MyFreeCams:ModelName or an URL like https://chaturbate.com/modelname/");
|
||||||
model.onActionHandler(e -> addModel(e));
|
model.onActionHandler(e -> addModel(e));
|
||||||
model.setTooltip(new Tooltip("To add a model enter SiteName:ModelName\n" +
|
model.setTooltip(new Tooltip("To add a model enter SiteName:ModelName\n" +
|
||||||
"press ENTER to confirm a suggested site name"));
|
"press ENTER to confirm a suggested site name"));
|
||||||
|
@ -174,6 +174,43 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addModel(ActionEvent e) {
|
private void addModel(ActionEvent e) {
|
||||||
|
String input = model.getText();
|
||||||
|
if(StringUtil.isBlank(input)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(input.startsWith("http")) {
|
||||||
|
addModelByUrl(input);
|
||||||
|
} else {
|
||||||
|
addModelByName(input);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private void addModelByUrl(String url) {
|
||||||
|
for (Site site : sites) {
|
||||||
|
Model model = site.createModelFromUrl(url);
|
||||||
|
if(model != null) {
|
||||||
|
try {
|
||||||
|
recorder.startRecording(model);
|
||||||
|
} catch (IOException | InvalidKeyException | NoSuchAlgorithmException | IllegalStateException e1) {
|
||||||
|
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR);
|
||||||
|
alert.setTitle("Error");
|
||||||
|
alert.setHeaderText("Couldn't add model");
|
||||||
|
alert.setContentText("The model " + model.getName() + " could not be added: " + e1.getLocalizedMessage());
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR);
|
||||||
|
alert.setTitle("Unknown URL format");
|
||||||
|
alert.setHeaderText("Couldn't add model");
|
||||||
|
alert.setContentText("The URL you entered has an unknown format or the function does not support this site, yet");
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addModelByName(String siteModelCombo) {
|
||||||
String[] parts = model.getText().trim().split(":");
|
String[] parts = model.getText().trim().split(":");
|
||||||
if (parts.length != 2) {
|
if (parts.length != 2) {
|
||||||
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR);
|
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR);
|
||||||
|
@ -207,8 +244,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
|
||||||
alert.setHeaderText("Couldn't add model");
|
alert.setHeaderText("Couldn't add model");
|
||||||
alert.setContentText("The site you entered is unknown");
|
alert.setContentText("The site you entered is unknown");
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
void initializeUpdateService() {
|
void initializeUpdateService() {
|
||||||
updateService = createUpdateService();
|
updateService = createUpdateService();
|
||||||
|
|
|
@ -46,4 +46,9 @@ public abstract class AbstractSite implements Site {
|
||||||
public boolean searchRequiresLogin() {
|
public boolean searchRequiresLogin() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model createModelFromUrl(String url) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,4 +29,5 @@ public interface Site {
|
||||||
public boolean isEnabled();
|
public boolean isEnabled();
|
||||||
public List<Model> search(String q) throws IOException, InterruptedException;
|
public List<Model> search(String q) throws IOException, InterruptedException;
|
||||||
public boolean searchRequiresLogin();
|
public boolean searchRequiresLogin();
|
||||||
|
public Model createModelFromUrl(String url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -184,4 +186,14 @@ public class BongaCams extends AbstractSite {
|
||||||
return username != null && !username.trim().isEmpty();
|
return username != null && !username.trim().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model createModelFromUrl(String url) {
|
||||||
|
Matcher m = Pattern.compile("https?://.*?bongacams.com(?:/profile)?/([^/]*?)/?").matcher(url);
|
||||||
|
if(m.matches()) {
|
||||||
|
String modelName = m.group(1);
|
||||||
|
return createModel(modelName);
|
||||||
|
} else {
|
||||||
|
return super.createModelFromUrl(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import java.io.IOException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -154,4 +156,15 @@ public class Cam4 extends AbstractSite {
|
||||||
String username = Config.getInstance().getSettings().cam4Username;
|
String username = Config.getInstance().getSettings().cam4Username;
|
||||||
return username != null && !username.trim().isEmpty();
|
return username != null && !username.trim().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model createModelFromUrl(String url) {
|
||||||
|
Matcher m = Pattern.compile("https?://(?:www\\.)?cam4(?:.*?).com/([^/]*?)/?").matcher(url);
|
||||||
|
if(m.matches()) {
|
||||||
|
String modelName = m.group(1);
|
||||||
|
return createModel(modelName);
|
||||||
|
} else {
|
||||||
|
return super.createModelFromUrl(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -161,4 +163,15 @@ public class Camsoda extends AbstractSite {
|
||||||
String username = Config.getInstance().getSettings().camsodaUsername;
|
String username = Config.getInstance().getSettings().camsodaUsername;
|
||||||
return username != null && !username.trim().isEmpty();
|
return username != null && !username.trim().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model createModelFromUrl(String url) {
|
||||||
|
Matcher m = Pattern.compile("https?://(?:www\\.)?camsoda.com/([^/]*?)/?").matcher(url);
|
||||||
|
if(m.matches()) {
|
||||||
|
String modelName = m.group(1);
|
||||||
|
return createModel(modelName);
|
||||||
|
} else {
|
||||||
|
return super.createModelFromUrl(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -340,4 +342,15 @@ public class Chaturbate extends AbstractSite {
|
||||||
String username = Config.getInstance().getSettings().username;
|
String username = Config.getInstance().getSettings().username;
|
||||||
return username != null && !username.trim().isEmpty();
|
return username != null && !username.trim().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model createModelFromUrl(String url) {
|
||||||
|
Matcher m = Pattern.compile("https?://.*?chaturbate.com(?:/p)?/([^/]*?)/?").matcher(url);
|
||||||
|
if(m.matches()) {
|
||||||
|
String modelName = m.group(1);
|
||||||
|
return createModel(modelName);
|
||||||
|
} else {
|
||||||
|
return super.createModelFromUrl(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package ctbrec.sites.mfc;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
|
@ -122,4 +124,20 @@ public class MyFreeCams extends AbstractSite {
|
||||||
String username = Config.getInstance().getSettings().mfcUsername;
|
String username = Config.getInstance().getSettings().mfcUsername;
|
||||||
return username != null && !username.trim().isEmpty();
|
return username != null && !username.trim().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model createModelFromUrl(String url) {
|
||||||
|
String[] patterns = new String[] {
|
||||||
|
"https?://profiles.myfreecams.com/([^/]*?)",
|
||||||
|
"https?://(?:www.)?myfreecams.com/#(.*)"
|
||||||
|
};
|
||||||
|
for (String pattern : patterns) {
|
||||||
|
Matcher m = Pattern.compile(pattern).matcher(url);
|
||||||
|
if(m.matches()) {
|
||||||
|
String modelName = m.group(1);
|
||||||
|
return createModel(modelName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.createModelFromUrl(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue