generated from Nekojimi/JavaMavenTemplate
parent
c814c3ab4c
commit
4d7eccd1e0
@ -0,0 +1,14 @@ |
||||
/* |
||||
* 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; |
||||
|
||||
/** |
||||
* |
||||
* @author jim |
||||
*/ |
||||
public class Result { |
||||
|
||||
} |
@ -0,0 +1,32 @@ |
||||
/* |
||||
* 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.providers; |
||||
|
||||
import java.util.List; |
||||
import java.util.Set; |
||||
import moe.nekojimi.musicsearcher.Result; |
||||
|
||||
/** |
||||
* |
||||
* @author jim |
||||
*/ |
||||
public class MetaSearcher extends Searcher |
||||
{ |
||||
|
||||
private final Set<Searcher> searchers; |
||||
|
||||
public MetaSearcher() |
||||
{ |
||||
super("meta"); |
||||
} |
||||
|
||||
@Override |
||||
public List<Result> search(String query) |
||||
{ |
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,59 @@ |
||||
/* |
||||
* 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.providers; |
||||
|
||||
import java.util.List; |
||||
import java.util.concurrent.ExecutionException; |
||||
import java.util.concurrent.ForkJoinPool; |
||||
import java.util.concurrent.Future; |
||||
import java.util.concurrent.FutureTask; |
||||
import java.util.concurrent.TimeUnit; |
||||
import java.util.concurrent.TimeoutException; |
||||
import moe.nekojimi.musicsearcher.Result; |
||||
|
||||
/** |
||||
* |
||||
* @author jim |
||||
*/ |
||||
public abstract class Searcher |
||||
{ |
||||
private final String name; |
||||
private final ForkJoinPool executor; |
||||
|
||||
public Searcher(String name) |
||||
{ |
||||
this.name = name; |
||||
this.executor = new ForkJoinPool(); |
||||
} |
||||
|
||||
public List<Result> searchAndWait(String query) throws InterruptedException, ExecutionException |
||||
{ |
||||
try |
||||
{ |
||||
return searchAndWait(query, Long.MAX_VALUE, TimeUnit.DAYS); |
||||
} catch (TimeoutException ex) |
||||
{ |
||||
throw new RuntimeException("This should never happen!",ex); |
||||
} |
||||
} |
||||
|
||||
public List<Result> searchAndWait(String query, long limit, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException |
||||
{ |
||||
return search(query).get(limit, unit); |
||||
} |
||||
|
||||
public Future<List<Result>> search(String query) |
||||
{ |
||||
FutureTask<List<Result>> task = new FutureTask<>(() -> |
||||
{ |
||||
return doSearch(query); |
||||
}); |
||||
executor.execute(task); |
||||
return task; |
||||
} |
||||
|
||||
protected abstract List<Result> doSearch(String query); |
||||
} |
@ -0,0 +1,37 @@ |
||||
/* |
||||
* 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.providers; |
||||
|
||||
import java.util.List; |
||||
import moe.nekojimi.musicsearcher.Result; |
||||
import org.jsoup.Jsoup; |
||||
|
||||
/** |
||||
* |
||||
* @author jim |
||||
*/ |
||||
public class WebScraperSearcher extends Searcher |
||||
{ |
||||
private String searchUrl; |
||||
|
||||
private String resultItem; |
||||
private String artistItem; |
||||
private String titleItem; |
||||
private String linkHrefItem; |
||||
private String albumArtistItem; |
||||
|
||||
public WebScraperSearcher(String name) |
||||
{ |
||||
super(name); |
||||
} |
||||
|
||||
@Override |
||||
protected List<Result> doSearch(String query) |
||||
{ |
||||
Jsoup. |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue