mirror of
https://github.com/mitb-archive/filebot
synced 2025-03-09 22:09:47 -04:00
Add XEM convenience methods
This commit is contained in:
parent
433df82647
commit
6947bfb69e
@ -11,36 +11,48 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import net.filebot.Cache;
|
||||
import net.filebot.CacheType;
|
||||
|
||||
public class XEM {
|
||||
|
||||
public Object[] getAll(Integer id, String origin) throws Exception {
|
||||
public List<Map<String, Map<String, Integer>>> getAll(String origin, int id) throws Exception {
|
||||
Map<String, Object> parameters = new LinkedHashMap<>(2);
|
||||
parameters.put("id", id);
|
||||
parameters.put("origin", origin);
|
||||
parameters.put("id", id);
|
||||
|
||||
Object response = request("all?" + encodeParameters(parameters, true));
|
||||
Object response = request("all", parameters);
|
||||
return (List) asList(getArray(response, "data"));
|
||||
}
|
||||
|
||||
return getArray(response, "data");
|
||||
public Map<String, Map<String, Integer>> getSingle(String origin, int id, int season, int episode) throws Exception {
|
||||
Map<String, Object> parameters = new LinkedHashMap<>(4);
|
||||
parameters.put("origin", origin);
|
||||
parameters.put("id", id);
|
||||
parameters.put("season", season);
|
||||
parameters.put("episode", episode);
|
||||
|
||||
Object response = request("single", parameters);
|
||||
return (Map) getMap(response, "data");
|
||||
}
|
||||
|
||||
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 {
|
||||
public List<SearchResult> getAllNames(String origin, Integer season, String language, boolean defaultNames) throws Exception {
|
||||
List<SearchResult> result = new ArrayList<>();
|
||||
|
||||
Map<String, Object> 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));
|
||||
Object response = request("allNames", parameters);
|
||||
|
||||
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());
|
||||
@ -49,12 +61,34 @@ public class XEM {
|
||||
result.add(new SearchResult(id, names.get(0), names.subList(1, names.size())));
|
||||
}
|
||||
});
|
||||
return result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Set<Integer> getHaveMap(String origin) throws Exception {
|
||||
Map<String, Object> parameters = new LinkedHashMap<>(1);
|
||||
parameters.put("origin", origin);
|
||||
|
||||
Object response = request("havemap", parameters);
|
||||
return stream(getArray(response, "data")).map(Object::toString).map(Integer::parseInt).collect(toSet());
|
||||
}
|
||||
|
||||
public Map<String, String> getNames(String origin, int id, boolean defaultNames) throws Exception {
|
||||
Map<String, Object> parameters = new LinkedHashMap<>(3);
|
||||
parameters.put("origin", origin);
|
||||
parameters.put("id", id);
|
||||
parameters.put("defaultNames", "1");
|
||||
|
||||
Object response = request("names", parameters);
|
||||
return (Map) getMap(response, "data");
|
||||
}
|
||||
|
||||
public Object request(String path, Map<String, Object> parameters) throws Exception {
|
||||
return request(path + '?' + encodeParameters(parameters, true));
|
||||
}
|
||||
|
||||
public Object request(String path) throws Exception {
|
||||
return getCache().json(path, this::getResource).get();
|
||||
return getCache().json(path, this::getResource).expire(Cache.ONE_WEEK).get();
|
||||
}
|
||||
|
||||
protected URL getResource(String path) throws Exception {
|
||||
@ -65,16 +99,4 @@ public class XEM {
|
||||
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"));
|
||||
|
||||
for (Object i : xem.getAll(13033, "anidb")) {
|
||||
System.out.println(i);
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user