Convert illegal runtime values like "1h 30min" or "90min" to valid Integer values

This commit is contained in:
Reinhard Pointner 2016-08-07 19:46:18 +08:00
parent b49859f894
commit 5c1e91c397
1 changed files with 13 additions and 1 deletions

View File

@ -165,7 +165,7 @@ public class OMDbClient implements MovieIdentificationService {
Map<MovieProperty, String> fields = new EnumMap<MovieProperty, String>(MovieProperty.class);
fields.put(MovieProperty.title, data.get("title"));
fields.put(MovieProperty.certification, data.get("rated"));
fields.put(MovieProperty.runtime, data.get("runtime"));
fields.put(MovieProperty.runtime, getRuntimeMinutes(data.get("runtime")));
fields.put(MovieProperty.tagline, data.get("plot"));
fields.put(MovieProperty.vote_average, data.get("imdbRating"));
fields.put(MovieProperty.vote_count, data.get("imdbVotes").replaceAll("\\D", ""));
@ -194,6 +194,18 @@ public class OMDbClient implements MovieIdentificationService {
return new MovieInfo(fields, emptyList(), genres, emptyMap(), languages, emptyList(), emptyList(), actors, emptyList());
}
private String getRuntimeMinutes(String runtime) {
List<Integer> n = matchIntegers(runtime);
switch (n.size()) {
case 0:
return null;
case 1:
return Integer.toString(n.get(0));// e.g 162 min
default:
return Integer.toString(n.get(0) * 60 + n.get(1));// e.g 1h 30min
}
}
private SimpleDate parsePartialDate(String value, String format) {
if (value != null && value.length() > 0) {
try {