Update test program.

master
Jim 3 years ago
parent b8c3972f54
commit 4df2f55922
  1. 61
      src/main/java/moe/nekojimi/musicsearcher/Main.java

@ -19,55 +19,48 @@ import java.util.Map;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import moe.nekojimi.musicsearcher.providers.MetaSearcher;
import moe.nekojimi.musicsearcher.providers.Searcher; import moe.nekojimi.musicsearcher.providers.Searcher;
/** /**
* *
* @author jim * @author jim
*/ */
public class Main public class Main
{ {
private static final Map<String, Searcher> searchers = new HashMap<>(); private static final Map<String, Searcher> searchers = new HashMap<>();
/** /**
* @param args the command line arguments * @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!"); // 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<? extends Searcher> clazz = (Class<? extends Searcher>) Class.forName("moe.nekojimi.musicsearcher.providers." + type);
Constructor<? extends Searcher> 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); System.out.println(searchers);
String query = "everybodys circulation"; String query = "eminem lose yourself";
for (Searcher searcher: searchers.values())
MetaSearcher metaSearch = MetaSearcher.loadYAML(new File("searchproviders.yml"));
try
{
List<Result> results = metaSearch.searchAndWait(Query.fullText(query));
// for (Searcher searcher: searchers.values())
// {
// System.out.println("Searching " + searcher.getName() + " for " + query);
// try
// {
// List<Result> 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); Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
try
{
List<Result> 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);
}
} }
} }
} }

Loading…
Cancel
Save