From c5564f60c8a4ec907b3d94deff352c1d43550445 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Fri, 5 Feb 2016 10:49:34 +0000 Subject: [PATCH] Support SpokenLanguages with OMDb @see https://www.filebot.net/forums/viewtopic.php?f=5&t=2367&p=18803#p18800 --- source/net/filebot/web/OMDbClient.java | 29 +++++++++++++------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/source/net/filebot/web/OMDbClient.java b/source/net/filebot/web/OMDbClient.java index 19cef64a..ecfbcad0 100644 --- a/source/net/filebot/web/OMDbClient.java +++ b/source/net/filebot/web/OMDbClient.java @@ -1,6 +1,7 @@ package net.filebot.web; import static java.util.Collections.*; +import static java.util.stream.Collectors.*; import static net.filebot.util.StringUtilities.*; import static net.filebot.web.WebRequest.*; @@ -20,6 +21,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; import java.util.concurrent.TimeUnit; +import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -219,24 +221,23 @@ public class OMDbClient implements MovieIdentificationService { } } - List genres = new ArrayList(); - for (String it : data.get("genre").split(",")) { - genres.add(it.trim()); - } + Pattern delim = Pattern.compile(","); + + List genres = split(delim, data.get("genre"), String::toString); + List languages = split(delim, data.get("language"), String::toString); List actors = new ArrayList(); - for (String it : data.get("actors").split(",")) { - actors.add(new Person(it.trim(), null, null)); - } + actors.addAll(split(delim, data.get("actors"), (s) -> new Person(s, 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"))); - for (String director : data.get("director").split(",")) { - actors.add(new Person(director, null, "Director")); - } + return new MovieInfo(fields, emptyList(), genres, emptyMap(), languages, emptyList(), emptyList(), actors, emptyList()); + } - for (String writer : data.get("writer").split(",")) { - actors.add(new Person(writer, null, "Writer")); - } + private List split(Pattern regex, String value, Function toObject) { + if (value == null || value.isEmpty()) + return emptyList(); - return new MovieInfo(fields, emptyList(), genres, emptyMap(), emptyList(), emptyList(), emptyList(), actors, emptyList()); + return regex.splitAsStream(value).map(String::trim).map(toObject).collect(toList()); } }