generated from Nekojimi/JavaMavenTemplate
74 lines
2.7 KiB
Java
74 lines
2.7 KiB
Java
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package moe.nekojimi.musicsearcher;
|
|
|
|
import com.amihaiemil.eoyaml.Yaml;
|
|
import com.amihaiemil.eoyaml.YamlInput;
|
|
import com.amihaiemil.eoyaml.YamlMapping;
|
|
import com.amihaiemil.eoyaml.YamlSequence;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.lang.reflect.Constructor;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import moe.nekojimi.musicsearcher.providers.Searcher;
|
|
|
|
/**
|
|
*
|
|
* @author jim
|
|
*/
|
|
public class Main
|
|
{
|
|
private static final Map<String, Searcher> searchers = new HashMap<>();
|
|
|
|
/**
|
|
* @param args the command line arguments
|
|
*/
|
|
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<? 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);
|
|
String query = "Test";
|
|
for (Searcher searcher: searchers.values())
|
|
{
|
|
System.out.println("Searching " + searcher.getName() + " for " + query);
|
|
try
|
|
{
|
|
List<Result> results = searcher.searchAndWait(query);
|
|
for (Result result: results)
|
|
{
|
|
System.out.println("\t" + result);
|
|
}
|
|
} catch (InterruptedException | ExecutionException ex) {
|
|
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
|
}
|
|
}
|
|
}
|
|
}
|