From 4df2f55922c09cd6b11cc5d63abfb74ccba3be5a Mon Sep 17 00:00:00 2001 From: Jim Date: Fri, 1 Oct 2021 13:22:59 +0100 Subject: [PATCH] Update test program. --- .../java/moe/nekojimi/musicsearcher/Main.java | 61 ++++++++----------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/src/main/java/moe/nekojimi/musicsearcher/Main.java b/src/main/java/moe/nekojimi/musicsearcher/Main.java index d947845..76747b4 100644 --- a/src/main/java/moe/nekojimi/musicsearcher/Main.java +++ b/src/main/java/moe/nekojimi/musicsearcher/Main.java @@ -19,55 +19,48 @@ import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.logging.Level; import java.util.logging.Logger; +import moe.nekojimi.musicsearcher.providers.MetaSearcher; import moe.nekojimi.musicsearcher.providers.Searcher; /** * * @author jim */ -public class Main +public class Main { private static final Map searchers = new HashMap<>(); - + /** * @param args the command line arguments */ - public static void main(String[] args) throws IOException + public static void main(String[] args) throws IOException { // System.out.println("Hello world!"); - YamlInput input = Yaml.createYamlInput(new File("searchproviders.yml")); - YamlSequence seq = input.readYamlSequence(); - for (int i = 0; i < seq.size(); i++) - { - try - { - YamlMapping map = seq.yamlMapping(i); - String type = map.string("type"); - Class clazz = (Class) Class.forName("moe.nekojimi.musicsearcher.providers." + type); - Constructor constructor = clazz.getConstructor(YamlMapping.class); - Searcher searcher = constructor.newInstance(map); - searchers.put(searcher.getName(), searcher); - - } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); - } - } - + + System.out.println(searchers); - String query = "everybodys circulation"; - for (Searcher searcher: searchers.values()) + String query = "eminem lose yourself"; + + MetaSearcher metaSearch = MetaSearcher.loadYAML(new File("searchproviders.yml")); + + try + { + List results = metaSearch.searchAndWait(Query.fullText(query)); +// for (Searcher searcher: searchers.values()) +// { +// System.out.println("Searching " + searcher.getName() + " for " + query); +// try +// { +// List results = searcher.searchAndWait(Query.fullText(query)); + for (Result result : results) + System.out.println("\t" + result); +// } catch (InterruptedException | ExecutionException ex) { +// Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); +// } +// } + } catch (ExecutionException | InterruptedException ex) { - System.out.println("Searching " + searcher.getName() + " for " + query); - try - { - List results = searcher.searchAndWait(Query.fullText(query)); - for (Result result: results) - { - System.out.println("\t" + result); - } - } catch (InterruptedException | ExecutionException ex) { - Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); - } + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } }