Support SpokenLanguages with OMDb

@see https://www.filebot.net/forums/viewtopic.php?f=5&t=2367&p=18803#p18800
This commit is contained in:
Reinhard Pointner 2016-02-05 10:49:34 +00:00
parent 6c011f60bb
commit c5564f60c8
1 changed files with 15 additions and 14 deletions

View File

@ -1,6 +1,7 @@
package net.filebot.web; package net.filebot.web;
import static java.util.Collections.*; import static java.util.Collections.*;
import static java.util.stream.Collectors.*;
import static net.filebot.util.StringUtilities.*; import static net.filebot.util.StringUtilities.*;
import static net.filebot.web.WebRequest.*; import static net.filebot.web.WebRequest.*;
@ -20,6 +21,7 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -219,24 +221,23 @@ public class OMDbClient implements MovieIdentificationService {
} }
} }
List<String> genres = new ArrayList<String>(); Pattern delim = Pattern.compile(",");
for (String it : data.get("genre").split(",")) {
genres.add(it.trim()); List<String> genres = split(delim, data.get("genre"), String::toString);
} List<String> languages = split(delim, data.get("language"), String::toString);
List<Person> actors = new ArrayList<Person>(); List<Person> actors = new ArrayList<Person>();
for (String it : data.get("actors").split(",")) { actors.addAll(split(delim, data.get("actors"), (s) -> new Person(s, null, null)));
actors.add(new Person(it.trim(), null, null)); actors.addAll(split(delim, data.get("director"), (s) -> new Person(s, null, "Director")));
actors.addAll(split(delim, data.get("writer"), (s) -> new Person(s, null, "Writer")));
return new MovieInfo(fields, emptyList(), genres, emptyMap(), languages, emptyList(), emptyList(), actors, emptyList());
} }
for (String director : data.get("director").split(",")) { private <T> List<T> split(Pattern regex, String value, Function<String, T> toObject) {
actors.add(new Person(director, null, "Director")); if (value == null || value.isEmpty())
} return emptyList();
for (String writer : data.get("writer").split(",")) { return regex.splitAsStream(value).map(String::trim).map(toObject).collect(toList());
actors.add(new Person(writer, null, "Writer"));
}
return new MovieInfo(fields, emptyList(), genres, emptyMap(), emptyList(), emptyList(), emptyList(), actors, emptyList());
} }
} }