SRT works ; adds support for export/import ass
This commit is contained in:
@@ -62,7 +62,7 @@ public class FXParametersController extends AbstractFXController implements Para
|
||||
extractionOutputFormat.valueProperty().bindBidirectional(model.outputFormatProperty());
|
||||
|
||||
fontFamilyCombobox.setItems(model.availableFontFamilies());
|
||||
fontFamilyCombobox.valueProperty().bindBidirectional(model.fontFamilyProperty());
|
||||
fontFamilyCombobox.valueProperty().bindBidirectional(model.fontNameProperty());
|
||||
|
||||
final UnaryOperator<TextFormatter.Change> integerFilter = change -> {
|
||||
final var newText = change.getControlNewText();
|
||||
@@ -85,14 +85,14 @@ public class FXParametersController extends AbstractFXController implements Para
|
||||
private void loadPreferences() {
|
||||
final var extractionModel = preferences.get("extractionModel", model.extractionModel().name());
|
||||
final var outputFormat = preferences.get("outputFormat", model.outputFormat().name());
|
||||
final var fontFamily = preferences.get("fontFamily", model.fontFamily());
|
||||
final var fontFamily = preferences.get("fontName", model.fontName());
|
||||
final var fontSize = preferences.getInt("fontSize", model.fontSize());
|
||||
final var maxLineLength = preferences.getInt("maxLineLength", model.maxLineLength());
|
||||
final var maxLines = preferences.getInt("maxLines", model.maxLines());
|
||||
|
||||
model.setExtractionModel(extractionModelProvider.getExtractionModel(extractionModel));
|
||||
model.setOutputFormat(OutputFormat.valueOf(outputFormat));
|
||||
model.setFontFamily(fontFamily);
|
||||
model.setFontName(fontFamily);
|
||||
model.setFontSize(fontSize);
|
||||
model.setMaxLineLength(maxLineLength);
|
||||
model.setMaxLines(maxLines);
|
||||
@@ -105,7 +105,7 @@ public class FXParametersController extends AbstractFXController implements Para
|
||||
logger.info("Saving preferences");
|
||||
preferences.put("extractionModel", model.extractionModel().name());
|
||||
preferences.put("outputFormat", model.outputFormat().name());
|
||||
preferences.put("fontFamily", model.fontFamily());
|
||||
preferences.put("fontName", model.fontName());
|
||||
preferences.putInt("fontSize", model.fontSize());
|
||||
preferences.putInt("maxLineLength", model.maxLineLength());
|
||||
preferences.putInt("maxLines", model.maxLines());
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.github.gtache.autosubtitle.gui.fx;
|
||||
|
||||
import com.github.gtache.autosubtitle.gui.ParametersModel;
|
||||
import com.github.gtache.autosubtitle.modules.gui.impl.FontFamily;
|
||||
import com.github.gtache.autosubtitle.modules.gui.impl.FontSize;
|
||||
import com.github.gtache.autosubtitle.modules.impl.FontName;
|
||||
import com.github.gtache.autosubtitle.modules.impl.FontSize;
|
||||
import com.github.gtache.autosubtitle.modules.impl.MaxLineLength;
|
||||
import com.github.gtache.autosubtitle.modules.impl.MaxLines;
|
||||
import com.github.gtache.autosubtitle.subtitle.OutputFormat;
|
||||
@@ -31,20 +31,20 @@ public class FXParametersModel implements ParametersModel {
|
||||
private final ObservableList<OutputFormat> availableOutputFormats;
|
||||
private final ObjectProperty<OutputFormat> outputFormat;
|
||||
private final ObservableList<String> availableFontFamilies;
|
||||
private final StringProperty fontFamily;
|
||||
private final StringProperty fontName;
|
||||
private final IntegerProperty fontSize;
|
||||
private final IntegerProperty maxLineLength;
|
||||
private final IntegerProperty maxLines;
|
||||
|
||||
@Inject
|
||||
FXParametersModel(final ExtractionModelProvider extractionModelProvider, @FontFamily final String defaultFontFamily,
|
||||
FXParametersModel(final ExtractionModelProvider extractionModelProvider, @FontName final String defaultFontFamily,
|
||||
@FontSize final int defaultFontSize, @MaxLineLength final int defaultMaxLineLength, @MaxLines final int defaultMaxLines) {
|
||||
this.availableExtractionModels = FXCollections.unmodifiableObservableList(FXCollections.observableArrayList(extractionModelProvider.getAvailableExtractionModels()));
|
||||
this.extractionModel = new SimpleObjectProperty<>(extractionModelProvider.getDefaultExtractionModel());
|
||||
this.availableOutputFormats = FXCollections.unmodifiableObservableList(FXCollections.observableArrayList(OutputFormat.SRT));
|
||||
this.outputFormat = new SimpleObjectProperty<>(OutputFormat.SRT);
|
||||
this.availableOutputFormats = FXCollections.unmodifiableObservableList(FXCollections.observableArrayList(OutputFormat.values()));
|
||||
this.outputFormat = new SimpleObjectProperty<>(OutputFormat.ASS);
|
||||
this.availableFontFamilies = FXCollections.unmodifiableObservableList(FXCollections.observableArrayList("Arial"));
|
||||
this.fontFamily = new SimpleStringProperty(defaultFontFamily);
|
||||
this.fontName = new SimpleStringProperty(defaultFontFamily);
|
||||
this.fontSize = new SimpleIntegerProperty(defaultFontSize);
|
||||
this.maxLineLength = new SimpleIntegerProperty(defaultMaxLineLength);
|
||||
this.maxLines = new SimpleIntegerProperty(defaultMaxLines);
|
||||
@@ -94,17 +94,17 @@ public class FXParametersModel implements ParametersModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fontFamily() {
|
||||
return fontFamily.get();
|
||||
public String fontName() {
|
||||
return fontName.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFontFamily(final String fontFamily) {
|
||||
this.fontFamily.set(fontFamily);
|
||||
public void setFontName(final String fontFamily) {
|
||||
this.fontName.set(fontFamily);
|
||||
}
|
||||
|
||||
StringProperty fontFamilyProperty() {
|
||||
return fontFamily;
|
||||
StringProperty fontNameProperty() {
|
||||
return fontName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.github.gtache.autosubtitle.gui.fx;
|
||||
|
||||
import com.github.gtache.autosubtitle.Language;
|
||||
import com.github.gtache.autosubtitle.Video;
|
||||
import com.github.gtache.autosubtitle.gui.WorkStatus;
|
||||
import com.github.gtache.autosubtitle.subtitle.gui.fx.ObservableSubtitleCollectionImpl;
|
||||
import javafx.beans.binding.Bindings;
|
||||
@@ -34,6 +35,7 @@ public class FXSubtitlesBinder implements FXBinder {
|
||||
workModel.selectedSubtitleProperty().bind(subtitlesModel.selectedSubtitleProperty());
|
||||
workModel.canExportProperty().bind(Bindings.isNotEmpty(subtitlesModel.collections()).and(workModel.statusProperty().isEqualTo(WorkStatus.IDLE)));
|
||||
workModel.videoLanguageProperty().bind(subtitlesModel.videoLanguageProperty());
|
||||
subtitlesModel.videoInfoProperty().bind(workModel.videoProperty().map(Video::info));
|
||||
|
||||
subtitlesModel.translatingProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue) {
|
||||
|
||||
@@ -152,6 +152,9 @@ public class FXSubtitlesController extends AbstractFXController implements Subti
|
||||
model.setSelectedCollection(model.collections().get(value));
|
||||
} else {
|
||||
logger.error("Error while translating to {}", value, t);
|
||||
final var newCollection = new ObservableSubtitleCollectionImpl();
|
||||
loadCollection(newCollection);
|
||||
model.setSelectedCollection(newCollection);
|
||||
}
|
||||
model.setTranslating(false);
|
||||
}, Platform::runLater);
|
||||
@@ -284,9 +287,9 @@ public class FXSubtitlesController extends AbstractFXController implements Subti
|
||||
final var filename = file.getFileName().toString();
|
||||
final var extension = filename.substring(filename.lastIndexOf('.') + 1);
|
||||
if (subtitleExtensions.contains(extension)) {
|
||||
importerExporter.exportSubtitles(model.selectedCollection(), file);
|
||||
importerExporter.exportSubtitles(model.selectedCollection(), model.videoInfo(), file);
|
||||
} else {
|
||||
importerExporter.exportSubtitles(model.collections().values(), file);
|
||||
importerExporter.exportSubtitles(model.collections().values(), model.videoInfo(), file);
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
logger.error("Error saving subtitles {}", file, e);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.github.gtache.autosubtitle.gui.fx;
|
||||
|
||||
import com.github.gtache.autosubtitle.Language;
|
||||
import com.github.gtache.autosubtitle.VideoInfo;
|
||||
import com.github.gtache.autosubtitle.gui.SubtitlesModel;
|
||||
import com.github.gtache.autosubtitle.subtitle.gui.fx.ObservableSubtitleCollectionImpl;
|
||||
import com.github.gtache.autosubtitle.subtitle.gui.fx.ObservableSubtitleImpl;
|
||||
@@ -29,6 +30,7 @@ public class FXSubtitlesModel implements SubtitlesModel<ObservableSubtitleImpl,
|
||||
|
||||
private final ObservableList<Language> availableVideoLanguages;
|
||||
private final ObjectProperty<Language> videoLanguage;
|
||||
private final ObjectProperty<VideoInfo> videoInfo;
|
||||
private final ObservableList<Language> availableTranslationLanguages;
|
||||
private final ObservableList<Language> selectedTranslationsLanguages;
|
||||
private final ObjectProperty<Language> selectedLanguage;
|
||||
@@ -59,6 +61,7 @@ public class FXSubtitlesModel implements SubtitlesModel<ObservableSubtitleImpl,
|
||||
}).toList()));
|
||||
this.availableTranslationLanguages = FXCollections.observableArrayList(Arrays.stream(Language.values()).filter(l -> l != Language.AUTO).toList());
|
||||
this.videoLanguage = new SimpleObjectProperty<>(Language.AUTO);
|
||||
this.videoInfo = new SimpleObjectProperty<>();
|
||||
this.selectedTranslationsLanguages = FXCollections.observableArrayList();
|
||||
this.selectedLanguage = new SimpleObjectProperty<>(Language.AUTO);
|
||||
this.collections = FXCollections.observableHashMap();
|
||||
@@ -108,6 +111,20 @@ public class FXSubtitlesModel implements SubtitlesModel<ObservableSubtitleImpl,
|
||||
return videoLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VideoInfo videoInfo() {
|
||||
return videoInfo.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVideoInfo(final VideoInfo videoInfo) {
|
||||
this.videoInfo.set(videoInfo);
|
||||
}
|
||||
|
||||
ObjectProperty<VideoInfo> videoInfoProperty() {
|
||||
return videoInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObservableList<Language> availableTranslationsLanguage() {
|
||||
return FXCollections.unmodifiableObservableList(availableTranslationLanguages);
|
||||
|
||||
@@ -77,13 +77,13 @@ class TestFXParametersModel {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFontFamily() {
|
||||
assertEquals(DEFAULT_FONT_FAMILY, model.fontFamily());
|
||||
assertEquals(DEFAULT_FONT_FAMILY, model.fontFamilyProperty().get());
|
||||
void testFontName() {
|
||||
assertEquals(DEFAULT_FONT_FAMILY, model.fontName());
|
||||
assertEquals(DEFAULT_FONT_FAMILY, model.fontNameProperty().get());
|
||||
final var fontFamily = DEFAULT_FONT_FAMILY + " A";
|
||||
model.setFontFamily(fontFamily);
|
||||
assertEquals(fontFamily, model.fontFamily());
|
||||
assertEquals(fontFamily, model.fontFamilyProperty().get());
|
||||
model.setFontName(fontFamily);
|
||||
assertEquals(fontFamily, model.fontName());
|
||||
assertEquals(fontFamily, model.fontNameProperty().get());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user