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 SimpleIntegerProperty port;
|
||||
private SimpleStringProperty path;
|
||||
private SimpleStringProperty downloadFilename;
|
||||
private SimpleBooleanProperty requireAuthentication;
|
||||
private SimpleBooleanProperty transportLayerSecurity;
|
||||
private ExclusiveSelectionProperty recordLocal;
|
||||
|
@ -140,6 +141,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
|||
server = new SimpleStringProperty(null, "httpServer", settings.httpServer);
|
||||
port = new SimpleIntegerProperty(null, "httpPort", settings.httpPort);
|
||||
path = new SimpleStringProperty(null, "servletContext", settings.servletContext);
|
||||
downloadFilename = new SimpleStringProperty(null, "downloadFilename", settings.downloadFilename);
|
||||
requireAuthentication = new SimpleBooleanProperty(null, "requireAuthentication", settings.requireAuthentication);
|
||||
requireAuthentication.addListener(this::requireAuthenticationChanged);
|
||||
transportLayerSecurity = new SimpleBooleanProperty(null, "transportLayerSecurity", settings.transportLayerSecurity);
|
||||
|
@ -196,6 +198,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
|||
Setting.of("Server", server),
|
||||
Setting.of("Port", port),
|
||||
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("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("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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
FileChooser chooser = new FileChooser();
|
||||
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);
|
||||
while(!dir.exists()) {
|
||||
while (!dir.exists()) {
|
||||
dir = dir.getParentFile();
|
||||
}
|
||||
chooser.setInitialDirectory(dir);
|
||||
}
|
||||
File target = chooser.showSaveDialog(null);
|
||||
if(target != null) {
|
||||
if (target != null) {
|
||||
config.getSettings().lastDownloadDir = target.getParent();
|
||||
startDownloadThread(target, recording);
|
||||
recording.setStatus(DOWNLOADING);
|
||||
|
@ -598,12 +598,12 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
|||
}
|
||||
|
||||
private String proposeTargetFilename(Recording recording) {
|
||||
String path = recording.getAbsoluteFile().getAbsolutePath().substring(1);
|
||||
if(recording.isSingleFile()) {
|
||||
return new File(path).getName();
|
||||
return recording.getAbsoluteFile().getName();
|
||||
} else {
|
||||
String downloadFilename = config.getSettings().downloadFilename;
|
||||
String fileSuffix = config.getSettings().ffmpegFileSuffix;
|
||||
String filename = path.replace("/", "-").replace(".mp4", "") + '.' + fileSuffix;
|
||||
String filename = new DownloadPostprocessor().fillInPlaceHolders(downloadFilename, recording, config) + '.' + fileSuffix;
|
||||
return filename;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ public class Settings {
|
|||
public int concurrentRecordings = 0;
|
||||
public boolean determineResolution = false;
|
||||
public List<String> disabledSites = new ArrayList<>();
|
||||
public String downloadFilename = "${modelSanitizedName}-${localDateTime}";
|
||||
public List<EventHandlerConfiguration> eventHandlers = new ArrayList<>();
|
||||
public String fc2livePassword = "";
|
||||
public String fc2liveUsername = "";
|
||||
|
|
|
@ -350,6 +350,19 @@ public class RemoteRecorder implements Recorder {
|
|||
}
|
||||
|
||||
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 {
|
||||
LOG.error(SERVER_RETURNED_ERROR, resp.status, resp.msg);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Recording;
|
||||
import ctbrec.sites.Site;
|
||||
|
||||
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("${modelDisplayName}", ofNullable(rec.getModel().getDisplayName()).orElse("displayName"))
|
||||
.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("${fileSuffix}", getFileSuffix(rec))
|
||||
.replace("${epochSecond}", Long.toString(rec.getStartDate().getEpochSecond()))
|
||||
|
@ -91,7 +92,7 @@ public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPost
|
|||
}
|
||||
|
||||
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