Convert the model name in URLs to lower case for Chaturbate
This commit is contained in:
parent
f2df8deb0c
commit
c6e96825a2
|
@ -2,14 +2,10 @@ package ctbrec;
|
||||||
|
|
||||||
import com.squareup.moshi.JsonAdapter;
|
import com.squareup.moshi.JsonAdapter;
|
||||||
import com.squareup.moshi.Moshi;
|
import com.squareup.moshi.Moshi;
|
||||||
import ctbrec.Settings.SplitStrategy;
|
|
||||||
import ctbrec.io.*;
|
import ctbrec.io.*;
|
||||||
import ctbrec.recorder.postprocessing.DeleteTooShort;
|
|
||||||
import ctbrec.recorder.postprocessing.PostProcessor;
|
import ctbrec.recorder.postprocessing.PostProcessor;
|
||||||
import ctbrec.recorder.postprocessing.RemoveKeepFile;
|
|
||||||
import ctbrec.recorder.postprocessing.Script;
|
|
||||||
import ctbrec.sites.Site;
|
import ctbrec.sites.Site;
|
||||||
import ctbrec.sites.cam4.Cam4Model;
|
import ctbrec.sites.chaturbate.ChaturbateModel;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -24,7 +20,6 @@ import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.format.FormatStyle;
|
import java.time.format.FormatStyle;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
@ -35,6 +30,8 @@ public class Config {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(Config.class);
|
private static final Logger LOG = LoggerFactory.getLogger(Config.class);
|
||||||
private static final String SYSPROP_CONFIG_DIR = "ctbrec.config.dir";
|
private static final String SYSPROP_CONFIG_DIR = "ctbrec.config.dir";
|
||||||
|
private static final String V_4_7_5 = "4.7.5";
|
||||||
|
|
||||||
|
|
||||||
private static Config instance;
|
private static Config instance;
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
|
@ -111,7 +108,7 @@ public class Config {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previousVersion.compareTo(Version.of("4.7.5")) <= 0) {
|
if (previousVersion.compareTo(Version.of(V_4_7_5)) <= 0) {
|
||||||
src = configDirectory;
|
src = configDirectory;
|
||||||
} else {
|
} else {
|
||||||
src = new File(configDirectory, previousVersion.toString());
|
src = new File(configDirectory, previousVersion.toString());
|
||||||
|
@ -134,9 +131,9 @@ public class Config {
|
||||||
.map(File::getName)
|
.map(File::getName)
|
||||||
.map(Version::of)
|
.map(Version::of)
|
||||||
.max(Comparator.naturalOrder());
|
.max(Comparator.naturalOrder());
|
||||||
return previousVersion.orElse(Version.of("4.7.5"));
|
return previousVersion.orElse(Version.of(V_4_7_5));
|
||||||
} else {
|
} else {
|
||||||
return Version.of("4.7.5");
|
return Version.of(V_4_7_5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,87 +182,54 @@ public class Config {
|
||||||
migrateOldSettings();
|
migrateOldSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private void migrateOldSettings() {
|
private void migrateOldSettings() {
|
||||||
// 3.8.0 from maxResolution only to resolution range
|
// 4.7.18
|
||||||
if (settings.minimumResolution == settings.maximumResolution && settings.minimumResolution == 0) {
|
convertChaturbateModelNamesToLowerCase();
|
||||||
settings.minimumResolution = 0;
|
|
||||||
settings.maximumResolution = 8640;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3.10.0
|
}
|
||||||
if (StringUtil.isNotBlank(settings.postProcessing)) {
|
|
||||||
Script script = new Script();
|
|
||||||
script.getConfig().put(Script.SCRIPT_EXECUTABLE, settings.postProcessing);
|
|
||||||
script.getConfig().put(Script.SCRIPT_PARAMS, "${absoluteParentPath} ${absolutePath} ${modelName} ${siteName} ${epochSecond}");
|
|
||||||
settings.postProcessors.add(script);
|
|
||||||
settings.postProcessing = null;
|
|
||||||
}
|
|
||||||
if (settings.minimumLengthInSeconds > 0) {
|
|
||||||
DeleteTooShort deleteTooShort = new DeleteTooShort();
|
|
||||||
deleteTooShort.getConfig().put(DeleteTooShort.MIN_LEN_IN_SECS, Integer.toString(settings.minimumLengthInSeconds));
|
|
||||||
settings.postProcessors.add(deleteTooShort);
|
|
||||||
settings.minimumLengthInSeconds = 0;
|
|
||||||
}
|
|
||||||
if (settings.removeRecordingAfterPostProcessing) {
|
|
||||||
RemoveKeepFile removeKeepFile = new RemoveKeepFile();
|
|
||||||
settings.postProcessors.add(removeKeepFile);
|
|
||||||
settings.removeRecordingAfterPostProcessing = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3.10.7
|
private void convertChaturbateModelNamesToLowerCase() {
|
||||||
if (StringUtil.isNotBlank(settings.username)) {
|
final String CTB = "chaturbate.com";
|
||||||
settings.chaturbateUsername = settings.username;
|
|
||||||
settings.username = null;
|
// convert mode notes
|
||||||
}
|
getSettings().modelNotes.forEach((key, value) -> {
|
||||||
if (StringUtil.isNotBlank(settings.password)) {
|
if (key.contains(CTB)) {
|
||||||
settings.chaturbatePassword = settings.password;
|
getSettings().modelNotes.remove(key);
|
||||||
settings.password = null;
|
getSettings().modelNotes.put(key.toLowerCase(), value);
|
||||||
}
|
|
||||||
if (settings.splitRecordings > 0) {
|
|
||||||
settings.splitStrategy = SplitStrategy.TIME;
|
|
||||||
settings.splitRecordingsAfterSecs = settings.splitRecordings;
|
|
||||||
settings.splitRecordings = 0;
|
|
||||||
}
|
|
||||||
// migrate old config from ctbrec-minimal browser
|
|
||||||
File oldLocation = new File(OS.getConfigDir().getParentFile(), "ctbrec-minimal-browser");
|
|
||||||
if (oldLocation.exists()) {
|
|
||||||
File newLocation = new File(getConfigDir(), oldLocation.getName());
|
|
||||||
try {
|
|
||||||
if (!newLocation.exists()) {
|
|
||||||
LOG.debug("Moving minimal browser config {} --> {}", oldLocation, newLocation);
|
|
||||||
FileUtils.moveDirectory(oldLocation, newLocation);
|
|
||||||
} else {
|
|
||||||
LOG.debug("minimal browser settings have been migrated before");
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOG.error("Couldn't migrate minimal browser config location", e);
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
// 3.10.10 model notes due to Cam4 URL change
|
|
||||||
for (Iterator<Entry<String, String>> iterator = settings.modelNotes.entrySet().iterator(); iterator.hasNext(); ) {
|
// convert model portraits
|
||||||
Entry<String, String> note = iterator.next();
|
getSettings().modelPortraits.forEach((key, value) -> {
|
||||||
if (note.getKey().contains("cam4") && note.getKey().endsWith("/")) {
|
if (key.contains(CTB)) {
|
||||||
Cam4Model model = new Cam4Model();
|
getSettings().modelPortraits.remove(key);
|
||||||
model.setUrl(note.getKey());
|
getSettings().modelPortraits.put(key.toLowerCase(), value);
|
||||||
settings.modelNotes.put(model.getUrl(), note.getValue());
|
|
||||||
iterator.remove();
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
// 3.11.0 make Cam4 model names lower case
|
|
||||||
settings.models.stream()
|
// convert model groups
|
||||||
.filter(Cam4Model.class::isInstance)
|
getSettings().modelGroups.forEach(mg -> mg.setModelUrls(mg.getModelUrls().stream().map(url -> url.contains(CTB) ? url.toLowerCase() : url)
|
||||||
.forEach(m -> m.setName(m.getName().toLowerCase()));
|
.collect(Collectors.toList()))); // NOSONAR - has to be mutable
|
||||||
settings.modelsIgnored.stream()
|
|
||||||
.filter(Cam4Model.class::isInstance)
|
// convert ignored models
|
||||||
.forEach(m -> m.setName(m.getName().toLowerCase()));
|
getSettings().ignoredModels = getSettings().ignoredModels.stream().map(url -> url.contains(CTB) ? url.toLowerCase() : url)
|
||||||
// 4.1.2 reduce models ignore to store only the URL
|
.collect(Collectors.toList()); // NOSONAR - has to be mutable
|
||||||
if (settings.modelsIgnored != null && !settings.modelsIgnored.isEmpty()) {
|
|
||||||
settings.ignoredModels = settings.modelsIgnored.stream()
|
// change the model objects
|
||||||
.map(Model::getUrl)
|
getSettings().models.stream()
|
||||||
.collect(Collectors.toList()); // NOSONAR modifiable list desired here
|
.filter(ChaturbateModel.class::isInstance)
|
||||||
settings.modelsIgnored = null;
|
.forEach(m -> {
|
||||||
}
|
m.setDisplayName(m.getName());
|
||||||
|
m.setName(m.getName().toLowerCase());
|
||||||
|
m.setUrl(m.getUrl().toLowerCase());
|
||||||
|
});
|
||||||
|
getSettings().recordLater.stream()
|
||||||
|
.filter(ChaturbateModel.class::isInstance)
|
||||||
|
.forEach(m -> {
|
||||||
|
m.setDisplayName(m.getName());
|
||||||
|
m.setName(m.getName().toLowerCase());
|
||||||
|
m.setUrl(m.getUrl().toLowerCase());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void init(List<Site> sites) throws IOException {
|
public static synchronized void init(List<Site> sites) throws IOException {
|
||||||
|
@ -328,14 +292,16 @@ public class Config {
|
||||||
|
|
||||||
private File getDirForRecording(Model model, String formattedDate) {
|
private File getDirForRecording(Model model, String formattedDate) {
|
||||||
switch (getSettings().recordingsDirStructure) {
|
switch (getSettings().recordingsDirStructure) {
|
||||||
case ONE_PER_MODEL:
|
case ONE_PER_MODEL -> {
|
||||||
return new File(getSettings().recordingsDir, model.getSanitizedNamed());
|
return new File(getSettings().recordingsDir, model.getSanitizedNamed());
|
||||||
case ONE_PER_RECORDING:
|
}
|
||||||
|
case ONE_PER_RECORDING -> {
|
||||||
File modelDir = new File(getSettings().recordingsDir, model.getSanitizedNamed());
|
File modelDir = new File(getSettings().recordingsDir, model.getSanitizedNamed());
|
||||||
return new File(modelDir, formattedDate);
|
return new File(modelDir, formattedDate);
|
||||||
case FLAT:
|
}
|
||||||
default:
|
default -> {
|
||||||
return new File(getSettings().recordingsDir);
|
return new File(getSettings().recordingsDir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,10 +51,11 @@ public class Chaturbate extends AbstractSite {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Model createModel(String name) {
|
public Model createModel(String name) {
|
||||||
|
String normalizedName = name.toLowerCase().trim();
|
||||||
ChaturbateModel m = new ChaturbateModel(this);
|
ChaturbateModel m = new ChaturbateModel(this);
|
||||||
m.setName(name);
|
m.setName(normalizedName);
|
||||||
m.setUrl(getBaseUrl() + '/' + name + '/');
|
m.setUrl(getBaseUrl() + '/' + normalizedName + '/');
|
||||||
m.setPreview("https://roomimg.stream.highwebmedia.com/ri/" + name + ".jpg?" + Instant.now().getEpochSecond());
|
m.setPreview("https://roomimg.stream.highwebmedia.com/ri/" + normalizedName + ".jpg?" + Instant.now().getEpochSecond());
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
|
||||||
if (ignoreCache) {
|
if (ignoreCache) {
|
||||||
StreamInfo info = loadStreamInfo();
|
StreamInfo info = loadStreamInfo();
|
||||||
roomStatus = Optional.ofNullable(info).map(i -> i.room_status).orElse("");
|
roomStatus = Optional.ofNullable(info).map(i -> i.room_status).orElse("");
|
||||||
LOG.trace("Model {} room status: {}", getName(), info.room_status);
|
LOG.trace("Model {} room status: {}", getName(), Optional.ofNullable(info).map(i -> i.room_status).orElse("unknown"));
|
||||||
} else {
|
} else {
|
||||||
StreamInfo info = getStreamInfo(true);
|
StreamInfo info = getStreamInfo(true);
|
||||||
roomStatus = Optional.ofNullable(info).map(i -> i.room_status).orElse("");
|
roomStatus = Optional.ofNullable(info).map(i -> i.room_status).orElse("");
|
||||||
|
@ -343,4 +343,14 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setName(String name) {
|
||||||
|
super.setName(name.toLowerCase().trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUrl(String url) {
|
||||||
|
super.setUrl(url.toLowerCase().trim());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue