Skip to content

Commit

Permalink
Added filter by song length
Browse files Browse the repository at this point in the history
  • Loading branch information
ringosham committed Jun 27, 2019
1 parent 1795e6a commit e40b1df
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 25 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
39 changes: 38 additions & 1 deletion src/com/ringosham/controllers/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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));
Expand All @@ -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!
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/com/ringosham/export/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ");
Expand Down
29 changes: 22 additions & 7 deletions src/com/ringosham/export/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Song> 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<Song> songList;

public Filter(List<Song> songList, boolean filterPractice, boolean filterDuplicates, int filterSeconds) {
public Filter(List<Song> 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;
Expand All @@ -38,13 +46,20 @@ List<Song> 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();
Expand Down
3 changes: 3 additions & 0 deletions src/com/ringosham/fxml/main.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<CheckBox fx:id="filterDuplicates" mnemonicParsing="false" onAction="#onFilterDuplicatesChecked" text="Filter duplicate songs if their length difference is less than " />
<TextField fx:id="filterSeconds" prefHeight="25.0" prefWidth="29.0" />
<Label text=" seconds" />
<CheckBox fx:id="filterFarm" mnemonicParsing="false" onAction="#onFilterFarmChecked" text="Filter songs less than " />
<TextField fx:id="filterFarmSeconds" prefHeight="25.0" prefWidth="29.0" />
<Label text=" seconds" />
<Separator orientation="VERTICAL" prefHeight="9.0" prefWidth="13.0" visible="false" />
<TextArea fx:id="consoleArea" editable="false" prefHeight="94.0" prefWidth="410.0" wrapText="true">
<font>
Expand Down
40 changes: 26 additions & 14 deletions src/com/ringosham/objects/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@

public class Settings {

private boolean convertOgg;
private boolean filterPractice;
private boolean overwrite;
private boolean applyTags;
private boolean overrideTags;
private boolean renameAsBeatmap;
private boolean filterDuplicates;
private boolean romajiNaming;
private boolean mirrorOutput;
private int filterSeconds;
private File exportDirectory;


public Settings(boolean convertOgg, boolean filterPractice, boolean overwrite, boolean applyTags, boolean overrideTags, boolean renameAsBeatmap, boolean romajiNaming, boolean filterDuplicates, boolean mirrorOutput, int filterSeconds, File exportDirectory) {
private final boolean convertOgg;
private final boolean filterPractice;
private final boolean overwrite;
private final boolean applyTags;
private final boolean overrideTags;
private final boolean renameAsBeatmap;
private final boolean filterDuplicates;
private final boolean romajiNaming;
private final boolean mirrorOutput;
private final boolean filterFarm;
private final int farmSeconds;
private final int filterSeconds;
private final File exportDirectory;


public Settings(boolean convertOgg, boolean filterPractice, boolean overwrite, boolean applyTags, boolean overrideTags, boolean renameAsBeatmap, boolean romajiNaming, boolean filterDuplicates, boolean mirrorOutput, boolean filterFarm, int farmSeconds, int filterSeconds, File exportDirectory) {
this.convertOgg = convertOgg;
this.filterPractice = filterPractice;
this.overwrite = overwrite;
Expand All @@ -27,6 +29,8 @@ public Settings(boolean convertOgg, boolean filterPractice, boolean overwrite, b
this.filterDuplicates = filterDuplicates;
this.romajiNaming = romajiNaming;
this.mirrorOutput = mirrorOutput;
this.filterFarm = filterFarm;
this.farmSeconds = farmSeconds;
this.filterSeconds = filterSeconds;
this.exportDirectory = exportDirectory;
}
Expand Down Expand Up @@ -74,4 +78,12 @@ public boolean isRomajiNaming() {
public boolean isMirrorOutput() {
return mirrorOutput;
}

public boolean isFilterFarm() {
return filterFarm;
}

public int getFarmSeconds() {
return farmSeconds;
}
}

0 comments on commit e40b1df

Please sign in to comment.