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.Moshi;
|
||||
import ctbrec.Settings.SplitStrategy;
|
||||
import ctbrec.io.*;
|
||||
import ctbrec.recorder.postprocessing.DeleteTooShort;
|
||||
import ctbrec.recorder.postprocessing.PostProcessor;
|
||||
import ctbrec.recorder.postprocessing.RemoveKeepFile;
|
||||
import ctbrec.recorder.postprocessing.Script;
|
||||
import ctbrec.sites.Site;
|
||||
import ctbrec.sites.cam4.Cam4Model;
|
||||
import ctbrec.sites.chaturbate.ChaturbateModel;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -24,7 +20,6 @@ import java.time.ZoneId;
|
|||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.FormatStyle;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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 String SYSPROP_CONFIG_DIR = "ctbrec.config.dir";
|
||||
private static final String V_4_7_5 = "4.7.5";
|
||||
|
||||
|
||||
private static Config instance;
|
||||
private Settings settings;
|
||||
|
@ -111,7 +108,7 @@ public class Config {
|
|||
return;
|
||||
}
|
||||
|
||||
if (previousVersion.compareTo(Version.of("4.7.5")) <= 0) {
|
||||
if (previousVersion.compareTo(Version.of(V_4_7_5)) <= 0) {
|
||||
src = configDirectory;
|
||||
} else {
|
||||
src = new File(configDirectory, previousVersion.toString());
|
||||
|
@ -134,9 +131,9 @@ public class Config {
|
|||
.map(File::getName)
|
||||
.map(Version::of)
|
||||
.max(Comparator.naturalOrder());
|
||||
return previousVersion.orElse(Version.of("4.7.5"));
|
||||
return previousVersion.orElse(Version.of(V_4_7_5));
|
||||
} else {
|
||||
return Version.of("4.7.5");
|
||||
return Version.of(V_4_7_5);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,87 +182,54 @@ public class Config {
|
|||
migrateOldSettings();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void migrateOldSettings() {
|
||||
// 3.8.0 from maxResolution only to resolution range
|
||||
if (settings.minimumResolution == settings.maximumResolution && settings.minimumResolution == 0) {
|
||||
settings.minimumResolution = 0;
|
||||
settings.maximumResolution = 8640;
|
||||
}
|
||||
// 4.7.18
|
||||
convertChaturbateModelNamesToLowerCase();
|
||||
|
||||
// 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
|
||||
if (StringUtil.isNotBlank(settings.username)) {
|
||||
settings.chaturbateUsername = settings.username;
|
||||
settings.username = null;
|
||||
}
|
||||
if (StringUtil.isNotBlank(settings.password)) {
|
||||
settings.chaturbatePassword = settings.password;
|
||||
settings.password = null;
|
||||
}
|
||||
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);
|
||||
private void convertChaturbateModelNamesToLowerCase() {
|
||||
final String CTB = "chaturbate.com";
|
||||
|
||||
// convert mode notes
|
||||
getSettings().modelNotes.forEach((key, value) -> {
|
||||
if (key.contains(CTB)) {
|
||||
getSettings().modelNotes.remove(key);
|
||||
getSettings().modelNotes.put(key.toLowerCase(), value);
|
||||
}
|
||||
}
|
||||
// 3.10.10 model notes due to Cam4 URL change
|
||||
for (Iterator<Entry<String, String>> iterator = settings.modelNotes.entrySet().iterator(); iterator.hasNext(); ) {
|
||||
Entry<String, String> note = iterator.next();
|
||||
if (note.getKey().contains("cam4") && note.getKey().endsWith("/")) {
|
||||
Cam4Model model = new Cam4Model();
|
||||
model.setUrl(note.getKey());
|
||||
settings.modelNotes.put(model.getUrl(), note.getValue());
|
||||
iterator.remove();
|
||||
});
|
||||
|
||||
// convert model portraits
|
||||
getSettings().modelPortraits.forEach((key, value) -> {
|
||||
if (key.contains(CTB)) {
|
||||
getSettings().modelPortraits.remove(key);
|
||||
getSettings().modelPortraits.put(key.toLowerCase(), value);
|
||||
}
|
||||
}
|
||||
// 3.11.0 make Cam4 model names lower case
|
||||
settings.models.stream()
|
||||
.filter(Cam4Model.class::isInstance)
|
||||
.forEach(m -> m.setName(m.getName().toLowerCase()));
|
||||
settings.modelsIgnored.stream()
|
||||
.filter(Cam4Model.class::isInstance)
|
||||
.forEach(m -> m.setName(m.getName().toLowerCase()));
|
||||
// 4.1.2 reduce models ignore to store only the URL
|
||||
if (settings.modelsIgnored != null && !settings.modelsIgnored.isEmpty()) {
|
||||
settings.ignoredModels = settings.modelsIgnored.stream()
|
||||
.map(Model::getUrl)
|
||||
.collect(Collectors.toList()); // NOSONAR modifiable list desired here
|
||||
settings.modelsIgnored = null;
|
||||
}
|
||||
});
|
||||
|
||||
// convert model groups
|
||||
getSettings().modelGroups.forEach(mg -> mg.setModelUrls(mg.getModelUrls().stream().map(url -> url.contains(CTB) ? url.toLowerCase() : url)
|
||||
.collect(Collectors.toList()))); // NOSONAR - has to be mutable
|
||||
|
||||
// convert ignored models
|
||||
getSettings().ignoredModels = getSettings().ignoredModels.stream().map(url -> url.contains(CTB) ? url.toLowerCase() : url)
|
||||
.collect(Collectors.toList()); // NOSONAR - has to be mutable
|
||||
|
||||
// change the model objects
|
||||
getSettings().models.stream()
|
||||
.filter(ChaturbateModel.class::isInstance)
|
||||
.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 {
|
||||
|
@ -328,14 +292,16 @@ public class Config {
|
|||
|
||||
private File getDirForRecording(Model model, String formattedDate) {
|
||||
switch (getSettings().recordingsDirStructure) {
|
||||
case ONE_PER_MODEL:
|
||||
case ONE_PER_MODEL -> {
|
||||
return new File(getSettings().recordingsDir, model.getSanitizedNamed());
|
||||
case ONE_PER_RECORDING:
|
||||
}
|
||||
case ONE_PER_RECORDING -> {
|
||||
File modelDir = new File(getSettings().recordingsDir, model.getSanitizedNamed());
|
||||
return new File(modelDir, formattedDate);
|
||||
case FLAT:
|
||||
default:
|
||||
}
|
||||
default -> {
|
||||
return new File(getSettings().recordingsDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,10 +51,11 @@ public class Chaturbate extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public Model createModel(String name) {
|
||||
String normalizedName = name.toLowerCase().trim();
|
||||
ChaturbateModel m = new ChaturbateModel(this);
|
||||
m.setName(name);
|
||||
m.setUrl(getBaseUrl() + '/' + name + '/');
|
||||
m.setPreview("https://roomimg.stream.highwebmedia.com/ri/" + name + ".jpg?" + Instant.now().getEpochSecond());
|
||||
m.setName(normalizedName);
|
||||
m.setUrl(getBaseUrl() + '/' + normalizedName + '/');
|
||||
m.setPreview("https://roomimg.stream.highwebmedia.com/ri/" + normalizedName + ".jpg?" + Instant.now().getEpochSecond());
|
||||
return m;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
|
|||
if (ignoreCache) {
|
||||
StreamInfo info = loadStreamInfo();
|
||||
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 {
|
||||
StreamInfo info = getStreamInfo(true);
|
||||
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