From d349629574104e7c435c7b9889535056d4de934c Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Mon, 25 Jan 2021 22:06:54 +0100 Subject: [PATCH] Adds a new class for handling converter profiles --- .../converter/ConverterProfiles.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/main/java/net/knarcraft/ffmpegconverter/converter/ConverterProfiles.java 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); + } + } + +}