mirror of
https://github.com/mitb-archive/filebot
synced 2025-03-11 14:59:44 -04:00
Implement XEM API
This commit is contained in:
parent
d0598ea9b9
commit
4b674db342
@ -235,14 +235,11 @@ public final class WebRequest {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
for (Entry<String, ?> entry : parameters.entrySet()) {
|
for (Entry<String, ?> entry : parameters.entrySet()) {
|
||||||
if (sb.length() > 0) {
|
|
||||||
sb.append("&");
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append(entry.getKey());
|
|
||||||
if (entry.getValue() != null) {
|
if (entry.getValue() != null) {
|
||||||
sb.append("=");
|
if (sb.length() > 0) {
|
||||||
sb.append(encode(entry.getValue().toString(), unicode));
|
sb.append("&");
|
||||||
|
}
|
||||||
|
sb.append(entry.getKey()).append("=").append(encode(entry.getValue().toString(), unicode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
65
source/net/filebot/web/XEM.java
Normal file
65
source/net/filebot/web/XEM.java
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package net.filebot.web;
|
||||||
|
|
||||||
|
import static java.util.Arrays.*;
|
||||||
|
import static java.util.stream.Collectors.*;
|
||||||
|
import static net.filebot.util.JsonUtilities.*;
|
||||||
|
import static net.filebot.web.WebRequest.*;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import net.filebot.Cache;
|
||||||
|
import net.filebot.CacheType;
|
||||||
|
|
||||||
|
public class XEM {
|
||||||
|
|
||||||
|
public List<SearchResult> getAllNames(String origin) throws Exception {
|
||||||
|
return getAllNames(origin, null, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SearchResult> getAllNames(String origin, String season, String language, boolean defaultNames) throws Exception {
|
||||||
|
Map<String, String> parameters = new LinkedHashMap<>(4);
|
||||||
|
parameters.put("origin", origin);
|
||||||
|
parameters.put("season", season);
|
||||||
|
parameters.put("language", language);
|
||||||
|
parameters.put("defaultNames", defaultNames ? "1" : "0");
|
||||||
|
|
||||||
|
Object response = request("allNames?" + encodeParameters(parameters, true));
|
||||||
|
|
||||||
|
List<SearchResult> result = new ArrayList<>();
|
||||||
|
getMap(response, "data").forEach((k, v) -> {
|
||||||
|
int id = Integer.parseInt(k.toString());
|
||||||
|
List<String> names = stream(asArray(v)).filter(Objects::nonNull).map(Objects::toString).filter(s -> s.length() > 0).collect(toList());
|
||||||
|
|
||||||
|
if (names.size() > 0) {
|
||||||
|
result.add(new SearchResult(id, names.get(0), names.subList(1, names.size())));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object request(String path) throws Exception {
|
||||||
|
return getCache().json(path, this::getResource).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected URL getResource(String path) throws Exception {
|
||||||
|
return new URL("http://thexem.de/map/" + path);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Cache getCache() {
|
||||||
|
return Cache.getCache("xem", CacheType.Monthly);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO REMOVE
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
XEM xem = new XEM();
|
||||||
|
System.out.println(xem.getAllNames("tvdb"));
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user