diff --git a/src/main/java/net/knarcraft/ffmpegconverter/converter/ConverterProfiles.java b/src/main/java/net/knarcraft/ffmpegconverter/converter/ConverterProfiles.java new file mode 100644 index 0000000..b6a45ba --- /dev/null +++ b/src/main/java/net/knarcraft/ffmpegconverter/converter/ConverterProfiles.java @@ -0,0 +1,64 @@ +package net.knarcraft.ffmpegconverter.converter; + +import net.knarcraft.ffmpegconverter.utility.FileUtil; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * The ConverterProfiles class is responsible for loading and retrieving settings for a converter + */ +public class ConverterProfiles { + + private Map> loadedProfiles; + + /** + * Instantiates a new converter profiles object + */ + public ConverterProfiles() { + loadedProfiles = new HashMap<>(); + try { + loadProfiles(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Gets all available converter profiles as a set + * @return

A set of all loaded converter profiles.

+ */ + public Set getProfiles() { + return loadedProfiles.keySet(); + } + + /** + * Gets all profile settings for the given converter profile + * @param profileName

The name of the converter profile to get settings for.

+ * @return

Settings for the converter profile.

+ */ + public Map getProfileSettings(String profileName) { + return loadedProfiles.get(profileName); + } + + /** + * Loads all converter profiles + * @throws IOException

If unable to read the converter profiles file.

+ */ + private void loadProfiles() throws IOException { + String[] profiles = FileUtil.readFileLines("converter_profiles.txt"); + for (String profile : profiles) { + Map profileSettings = new HashMap<>(); + String[] settings = profile.split("\\|"); + String profileName = settings[0]; + for (int i = 1; i < settings.length; i++) { + String[] settingParts = settings[i].split(":"); + profileSettings.put(settingParts[0], settingParts[1]); + } + loadedProfiles.put(profileName, profileSettings); + } + } + +}