diff --git a/README.md b/README.md index f1a9eb9..0a23e18 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,10 @@ Do not use this program for distributing songs illegally. The creator of this pr * Export all beatmaps as .osz or just the songs * Proper file renaming (or rename it after beatmap ID if you really want to) * Adding MP3 tags based on beatmap info -* Filter practice songs -* **Filter any similar songs with the same names to prevent duplicates** (Extremely useful for saving space and if you have a large amount of beatmaps) +* Filters! + * Practice songs + * By song length (Skip any ~60 second farm maps. Unless you really like hearing haitai) + * Similar songs with the same names to prevent duplicates (Extremely useful for saving space and if you have a large amount of beatmaps) * Conversion from ogg to mp3 (Conversion is done via FFmpeg, included in the program) * osu library synchronisation if you frequently update your song library diff --git a/src/com/ringosham/controllers/Controller.java b/src/com/ringosham/controllers/Controller.java index 79594c5..b307d6c 100644 --- a/src/com/ringosham/controllers/Controller.java +++ b/src/com/ringosham/controllers/Controller.java @@ -50,6 +50,10 @@ public class Controller { private CheckBox romajiNaming; @FXML private CheckBox mirrorOutput; + @FXML + private CheckBox filterFarm; + @FXML + private TextField filterFarmSeconds; public static File beatmapDir = new File(System.getProperty("user.home") + "/AppData/Local/Osu!/Songs"); @@ -72,6 +76,7 @@ private void initialize() { String overwriteTooltip = "Overwrite the file even if it already exists. Otherwise it will overwrite if the file sizes are different"; String romajiTooltip = "Rename the song after romaji instead of its Japanese/other languages' name. This has no effect if \"Using beatmap ID\" is selected."; String mirrorTooltip = "Synchronize songs between the export and the folder. Any songs not belong to the output will be deleted."; + String filterFarmTooltip = "Filter maps shorter than your specified length"; convertCheckbox.setTooltip(new Tooltip(convertTooltip)); overrideTags.setTooltip(new Tooltip(overrideTooltip)); useBeatmapID.setTooltip(new Tooltip(useIDTooltip)); @@ -82,6 +87,7 @@ private void initialize() { overwriteCheckbox.setTooltip(new Tooltip(overwriteTooltip)); romajiNaming.setTooltip(new Tooltip(romajiTooltip)); mirrorOutput.setTooltip(new Tooltip(mirrorTooltip)); + filterFarm.setTooltip(new Tooltip(filterFarmTooltip)); //Some checks to make sure stuff works //Unofficial macOS port of osu! @@ -118,11 +124,17 @@ private void initialize() { overrideTags.setDisable(true); filterPractice.setSelected(true); filterDuplicates.setSelected(true); + filterFarm.setSelected(true); filterSeconds.setText("10"); filterSeconds.textProperty().addListener((observable, oldValue, newValue) -> { if (newValue.length() > 2 || !newValue.matches("\\d*") || newValue.equals("0")) filterSeconds.setText(oldValue); }); + filterFarmSeconds.setText("60"); + filterFarmSeconds.textProperty().addListener(((observable, oldValue, newValue) -> { + if (newValue.length() > 2 || !newValue.matches("\\d*") || newValue.equals("0")) + filterFarmSeconds.setText(oldValue); + })); } //Toggle stuff @@ -146,21 +158,46 @@ private void onFilterDuplicatesChecked() { filterSeconds.setDisable(false); } + @FXML + private void onFilterFarmChecked() { + if (filterFarm.isSelected()) + filterFarmSeconds.setDisable(false); + else { + filterFarmSeconds.setText(""); + filterFarmSeconds.setDisable(true); + } + } + @FXML private void onExportButtonClick() { + if (filterDuplicates.isSelected() && filterSeconds.getText().trim().isEmpty()) { + filterSeconds.requestFocus(); + filterSeconds.setStyle("-fx-text-box-boarder: red; -fx-focus-color: red"); + return; + } + if (filterFarm.isSelected() && filterFarmSeconds.getText().trim().isEmpty()) { + filterFarmSeconds.requestFocus(); + filterFarmSeconds.setStyle("-fx-text-box-boarder: red; -fx-focus-color: red"); + return; + } DirectoryChooser chooser = new DirectoryChooser(); chooser.setTitle("Select export directory"); File exportDirectory = chooser.showDialog(pane.getScene().getWindow()); if (exportDirectory != null) { boolean renameAsBeatmap = ((RadioButton) renameOptions.getSelectedToggle()).getText().equals("Rename after beatmap"); int seconds; + int farmSeconds; if (!filterDuplicates.isSelected()) seconds = 0; else seconds = Integer.parseInt(filterSeconds.getText()); + if (!filterFarm.isSelected()) + farmSeconds = 0; + else + farmSeconds = Integer.parseInt(filterFarmSeconds.getText()); Settings settings = new Settings(convertCheckbox.isSelected(), filterPractice.isSelected(), overwriteCheckbox.isSelected(), addTags.isSelected(), overrideTags.isSelected(), renameAsBeatmap, romajiNaming.isSelected(), - filterDuplicates.isSelected(), mirrorOutput.isSelected(), seconds, exportDirectory); + filterDuplicates.isSelected(), mirrorOutput.isSelected(), filterFarm.isSelected(), farmSeconds, seconds, exportDirectory); consoleArea.clear(); Exporter exporter = new Exporter(this, settings); exporter.execute(); diff --git a/src/com/ringosham/export/Exporter.java b/src/com/ringosham/export/Exporter.java index d5dbe9b..31a7669 100644 --- a/src/com/ringosham/export/Exporter.java +++ b/src/com/ringosham/export/Exporter.java @@ -82,7 +82,7 @@ public Void doInBackground(Void... params) { publishProgress("text", "Filtering beatmaps..."); publishProgress("progress", -1, 1); - Filter filter = new Filter(songList, settings.isFilterPractice(), settings.isFilterDuplicates(), settings.getFilterSeconds()); + Filter filter = new Filter(songList, settings.isFilterPractice(), settings.isFilterDuplicates(), settings.getFilterSeconds(), settings.isFilterFarm(), settings.getFarmSeconds()); songList = filter.start(); builder = new StringBuilder(); builder.append("Filtered songs down to "); diff --git a/src/com/ringosham/export/Filter.java b/src/com/ringosham/export/Filter.java index 21d6357..7af4ffd 100644 --- a/src/com/ringosham/export/Filter.java +++ b/src/com/ringosham/export/Filter.java @@ -2,16 +2,24 @@ import com.ringosham.objects.Song; -import java.util.*; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; public class Filter { - private List songList = new ArrayList<>(); - private boolean filterPractice; - private boolean filterDuplicates; - private int filterSeconds; + private final boolean filterFarm; + private final int farmSeconds; + private final boolean filterPractice; + private final boolean filterDuplicates; + private final int filterSeconds; + private List songList; - public Filter(List songList, boolean filterPractice, boolean filterDuplicates, int filterSeconds) { + public Filter(List songList, boolean filterPractice, boolean filterDuplicates, int filterSeconds, boolean filterFarm, int farmSeconds) { + this.songList = songList; + this.filterFarm = filterFarm; + this.farmSeconds = farmSeconds; this.songList.addAll(songList); this.filterPractice = filterPractice; this.filterDuplicates = filterDuplicates; @@ -38,13 +46,20 @@ List start() { if (title.contains(filter)) return true; if (unicodeTitle != null) - if (unicodeTitle.contains(filter) && !unicodeTitle.isEmpty()) + if (unicodeTitle.contains(filter)) return true; } return false; }); } + //Filter based on song length + if (filterFarm) { + for (Song song : songList) + if (song.getDuration() < farmSeconds) + songList.remove(song); + } + //Filter duplicates based on the length of the file if (filterDuplicates) { int j = songList.size(); diff --git a/src/com/ringosham/fxml/main.fxml b/src/com/ringosham/fxml/main.fxml index 7ce314e..322d473 100644 --- a/src/com/ringosham/fxml/main.fxml +++ b/src/com/ringosham/fxml/main.fxml @@ -46,6 +46,9 @@