forked from j62/ctbrec
Add setting to define the download file name
This commit is contained in:
parent
9ed4ded258
commit
5fa72eaaa0
|
@ -93,6 +93,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
||||||
private SimpleStringProperty server;
|
private SimpleStringProperty server;
|
||||||
private SimpleIntegerProperty port;
|
private SimpleIntegerProperty port;
|
||||||
private SimpleStringProperty path;
|
private SimpleStringProperty path;
|
||||||
|
private SimpleStringProperty downloadFilename;
|
||||||
private SimpleBooleanProperty requireAuthentication;
|
private SimpleBooleanProperty requireAuthentication;
|
||||||
private SimpleBooleanProperty transportLayerSecurity;
|
private SimpleBooleanProperty transportLayerSecurity;
|
||||||
private ExclusiveSelectionProperty recordLocal;
|
private ExclusiveSelectionProperty recordLocal;
|
||||||
|
@ -140,6 +141,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
||||||
server = new SimpleStringProperty(null, "httpServer", settings.httpServer);
|
server = new SimpleStringProperty(null, "httpServer", settings.httpServer);
|
||||||
port = new SimpleIntegerProperty(null, "httpPort", settings.httpPort);
|
port = new SimpleIntegerProperty(null, "httpPort", settings.httpPort);
|
||||||
path = new SimpleStringProperty(null, "servletContext", settings.servletContext);
|
path = new SimpleStringProperty(null, "servletContext", settings.servletContext);
|
||||||
|
downloadFilename = new SimpleStringProperty(null, "downloadFilename", settings.downloadFilename);
|
||||||
requireAuthentication = new SimpleBooleanProperty(null, "requireAuthentication", settings.requireAuthentication);
|
requireAuthentication = new SimpleBooleanProperty(null, "requireAuthentication", settings.requireAuthentication);
|
||||||
requireAuthentication.addListener(this::requireAuthenticationChanged);
|
requireAuthentication.addListener(this::requireAuthenticationChanged);
|
||||||
transportLayerSecurity = new SimpleBooleanProperty(null, "transportLayerSecurity", settings.transportLayerSecurity);
|
transportLayerSecurity = new SimpleBooleanProperty(null, "transportLayerSecurity", settings.transportLayerSecurity);
|
||||||
|
@ -196,6 +198,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
||||||
Setting.of("Server", server),
|
Setting.of("Server", server),
|
||||||
Setting.of("Port", port),
|
Setting.of("Port", port),
|
||||||
Setting.of("Path", path, "Leave empty, if you didn't change the servletContext in the server config"),
|
Setting.of("Path", path, "Leave empty, if you didn't change the servletContext in the server config"),
|
||||||
|
Setting.of("Download Filename", downloadFilename, "File name pattern for downloads"),
|
||||||
Setting.of("Require authentication", requireAuthentication),
|
Setting.of("Require authentication", requireAuthentication),
|
||||||
Setting.of("Use Secure Communication (TLS)", transportLayerSecurity)
|
Setting.of("Use Secure Communication (TLS)", transportLayerSecurity)
|
||||||
)
|
)
|
||||||
|
@ -241,6 +244,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
||||||
prefs.getSetting("minimumLengthInSeconds").ifPresent(s -> bindEnabledProperty(s, recordLocal.not()));
|
prefs.getSetting("minimumLengthInSeconds").ifPresent(s -> bindEnabledProperty(s, recordLocal.not()));
|
||||||
prefs.getSetting("concurrentRecordings").ifPresent(s -> bindEnabledProperty(s, recordLocal.not()));
|
prefs.getSetting("concurrentRecordings").ifPresent(s -> bindEnabledProperty(s, recordLocal.not()));
|
||||||
prefs.getSetting("concurrentRecordings").ifPresent(s -> bindEnabledProperty(s, recordLocal.not()));
|
prefs.getSetting("concurrentRecordings").ifPresent(s -> bindEnabledProperty(s, recordLocal.not()));
|
||||||
|
prefs.getSetting("downloadFilename").ifPresent(s -> bindEnabledProperty(s, recordLocal));
|
||||||
postProcessingStepPanel.disableProperty().bind(recordLocal.not());
|
postProcessingStepPanel.disableProperty().bind(recordLocal.not());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package ctbrec.ui.tabs;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import ctbrec.Config;
|
||||||
|
import ctbrec.Recording;
|
||||||
|
import ctbrec.recorder.RecordingManager;
|
||||||
|
import ctbrec.recorder.postprocessing.AbstractPlaceholderAwarePostProcessor;
|
||||||
|
|
||||||
|
public class DownloadPostprocessor extends AbstractPlaceholderAwarePostProcessor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "download renamer";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
|
||||||
|
// nothing really to do in here, we just inherit from AbstractPlaceholderAwarePostProcessor to use fillInPlaceHolders
|
||||||
|
}
|
||||||
|
}
|
|
@ -581,15 +581,15 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
||||||
String filename = proposeTargetFilename(recording);
|
String filename = proposeTargetFilename(recording);
|
||||||
FileChooser chooser = new FileChooser();
|
FileChooser chooser = new FileChooser();
|
||||||
chooser.setInitialFileName(filename);
|
chooser.setInitialFileName(filename);
|
||||||
if(config.getSettings().lastDownloadDir != null && !config.getSettings().lastDownloadDir.equals("")) {
|
if (config.getSettings().lastDownloadDir != null && !config.getSettings().lastDownloadDir.equals("")) {
|
||||||
File dir = new File(config.getSettings().lastDownloadDir);
|
File dir = new File(config.getSettings().lastDownloadDir);
|
||||||
while(!dir.exists()) {
|
while (!dir.exists()) {
|
||||||
dir = dir.getParentFile();
|
dir = dir.getParentFile();
|
||||||
}
|
}
|
||||||
chooser.setInitialDirectory(dir);
|
chooser.setInitialDirectory(dir);
|
||||||
}
|
}
|
||||||
File target = chooser.showSaveDialog(null);
|
File target = chooser.showSaveDialog(null);
|
||||||
if(target != null) {
|
if (target != null) {
|
||||||
config.getSettings().lastDownloadDir = target.getParent();
|
config.getSettings().lastDownloadDir = target.getParent();
|
||||||
startDownloadThread(target, recording);
|
startDownloadThread(target, recording);
|
||||||
recording.setStatus(DOWNLOADING);
|
recording.setStatus(DOWNLOADING);
|
||||||
|
@ -598,12 +598,12 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String proposeTargetFilename(Recording recording) {
|
private String proposeTargetFilename(Recording recording) {
|
||||||
String path = recording.getAbsoluteFile().getAbsolutePath().substring(1);
|
|
||||||
if(recording.isSingleFile()) {
|
if(recording.isSingleFile()) {
|
||||||
return new File(path).getName();
|
return recording.getAbsoluteFile().getName();
|
||||||
} else {
|
} else {
|
||||||
|
String downloadFilename = config.getSettings().downloadFilename;
|
||||||
String fileSuffix = config.getSettings().ffmpegFileSuffix;
|
String fileSuffix = config.getSettings().ffmpegFileSuffix;
|
||||||
String filename = path.replace("/", "-").replace(".mp4", "") + '.' + fileSuffix;
|
String filename = new DownloadPostprocessor().fillInPlaceHolders(downloadFilename, recording, config) + '.' + fileSuffix;
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ public class Settings {
|
||||||
public int concurrentRecordings = 0;
|
public int concurrentRecordings = 0;
|
||||||
public boolean determineResolution = false;
|
public boolean determineResolution = false;
|
||||||
public List<String> disabledSites = new ArrayList<>();
|
public List<String> disabledSites = new ArrayList<>();
|
||||||
|
public String downloadFilename = "${modelSanitizedName}-${localDateTime}";
|
||||||
public List<EventHandlerConfiguration> eventHandlers = new ArrayList<>();
|
public List<EventHandlerConfiguration> eventHandlers = new ArrayList<>();
|
||||||
public String fc2livePassword = "";
|
public String fc2livePassword = "";
|
||||||
public String fc2liveUsername = "";
|
public String fc2liveUsername = "";
|
||||||
|
|
|
@ -350,6 +350,19 @@ public class RemoteRecorder implements Recorder {
|
||||||
}
|
}
|
||||||
|
|
||||||
recordings = newRecordings;
|
recordings = newRecordings;
|
||||||
|
|
||||||
|
// assign a site to the model
|
||||||
|
for (Site site : sites) {
|
||||||
|
for (Recording recording : recordings) {
|
||||||
|
Model m = recording.getModel();
|
||||||
|
if (m.getSite() == null) {
|
||||||
|
if (site.isSiteForModel(m)) {
|
||||||
|
m.setSite(site);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.error(SERVER_RETURNED_ERROR, resp.status, resp.msg);
|
LOG.error(SERVER_RETURNED_ERROR, resp.status, resp.msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Recording;
|
import ctbrec.Recording;
|
||||||
|
import ctbrec.sites.Site;
|
||||||
|
|
||||||
public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPostProcessor {
|
public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPostProcessor {
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPost
|
||||||
.replace("${modelName}", ofNullable(rec.getModel().getName()).orElse("modelName"))
|
.replace("${modelName}", ofNullable(rec.getModel().getName()).orElse("modelName"))
|
||||||
.replace("${modelDisplayName}", ofNullable(rec.getModel().getDisplayName()).orElse("displayName"))
|
.replace("${modelDisplayName}", ofNullable(rec.getModel().getDisplayName()).orElse("displayName"))
|
||||||
.replace("${modelSanitizedName}", ofNullable(rec.getModel().getSanitizedNamed()).orElse("sanitizedName"))
|
.replace("${modelSanitizedName}", ofNullable(rec.getModel().getSanitizedNamed()).orElse("sanitizedName"))
|
||||||
.replace("${siteName}", rec.getModel().getSite().getName())
|
.replace("${siteName}", ofNullable(rec.getModel().getSite()).map(Site::getName).orElse("site"))
|
||||||
.replace("${siteSanitizedName}", getSanitizedSiteName(rec))
|
.replace("${siteSanitizedName}", getSanitizedSiteName(rec))
|
||||||
.replace("${fileSuffix}", getFileSuffix(rec))
|
.replace("${fileSuffix}", getFileSuffix(rec))
|
||||||
.replace("${epochSecond}", Long.toString(rec.getStartDate().getEpochSecond()))
|
.replace("${epochSecond}", Long.toString(rec.getStartDate().getEpochSecond()))
|
||||||
|
@ -91,7 +92,7 @@ public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPost
|
||||||
}
|
}
|
||||||
|
|
||||||
private CharSequence getSanitizedSiteName(Recording rec) {
|
private CharSequence getSanitizedSiteName(Recording rec) {
|
||||||
return rec.getModel().getSite().getName().replace(' ', '_').replace('\\', '_').replace('/', '_');
|
return ofNullable(rec.getModel().getSite()).map(Site::getName).orElse("").replace(' ', '_').replace('\\', '_').replace('/', '_');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue