Refactor Movie (use 0 as undefined ID)

This commit is contained in:
Reinhard Pointner 2016-10-09 16:19:39 +08:00
parent 37cdce1111
commit fe30f8a8d5
7 changed files with 14 additions and 16 deletions

View File

@ -19,11 +19,15 @@ public class Movie extends SearchResult {
}
public Movie(int imdbId) {
this(null, 0, imdbId, 0);
this(null, null, 0, imdbId, 0, null);
}
public Movie(String name, int year, int imdbId, int tmdbId) {
this(name, null, year, imdbId, tmdbId, null);
public Movie(String name, int year) {
this(name, null, year, 0, 0, null);
}
public Movie(String name, int year, int imdbId) {
this(name, null, year, imdbId, 0, null);
}
public Movie(String name, String[] aliasNames, int year, int imdbId, int tmdbId, Locale locale) {

View File

@ -1,7 +1,6 @@
package net.filebot.web;
import java.text.FieldPosition;
import java.text.Format;
import java.text.ParseException;
@ -9,7 +8,6 @@ import java.text.ParsePosition;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MovieFormat extends Format {
public static final MovieFormat NameYear = new MovieFormat(true, true, true);
@ -18,14 +16,12 @@ public class MovieFormat extends Format {
private final boolean includePartIndex;
private final boolean smart;
public MovieFormat(boolean includeYear, boolean includePartIndex, boolean smart) {
this.includeYear = includeYear;
this.includePartIndex = includePartIndex;
this.smart = smart;
}
@Override
public StringBuffer format(Object obj, StringBuffer sb, FieldPosition pos) {
// format episode object, e.g. Avatar (2009), Part 1
@ -53,7 +49,6 @@ public class MovieFormat extends Format {
private final Pattern moviePattern = Pattern.compile("([^\\p{Punct}]+?)[\\p{Punct}\\s]+(\\d{4})(?:[\\p{Punct}\\s]+|$)");
private final Pattern partPattern = Pattern.compile("(?:Part|CD)\\D?(\\d)$", Pattern.CASE_INSENSITIVE);
@Override
public Movie parseObject(String source, ParsePosition pos) {
String s = source;
@ -72,7 +67,7 @@ public class MovieFormat extends Format {
String name = m.group(1).trim();
int year = Integer.parseInt(m.group(2));
Movie movie = new Movie(name, year, -1, -1);
Movie movie = new Movie(name, year);
if (partIndex >= 0) {
movie = new MoviePart(movie, partIndex, partCount);
}
@ -87,7 +82,6 @@ public class MovieFormat extends Format {
return null;
}
@Override
public Movie parseObject(String source) throws ParseException {
return (Movie) super.parseObject(source);

View File

@ -120,7 +120,7 @@ public class OMDbClient implements MovieIdentificationService {
if (name.length() <= 0 || year <= 1900 || imdbid <= 0)
throw new IllegalArgumentException();
return new Movie(name, year, imdbid, 0);
return new Movie(name, year, imdbid);
} catch (Exception e) {
throw new IllegalArgumentException("Illegal fields: " + info);
}

View File

@ -268,7 +268,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
String imdb = fields.get("IDMovieImdb");
String name = fields.get("MovieName");
String year = fields.get("MovieYear");
identity = new Movie(name, Integer.parseInt(year), Integer.parseInt(imdb), -1);
identity = new Movie(name, Integer.parseInt(year), Integer.parseInt(imdb));
} catch (Exception e) {
debug.log(Level.SEVERE, "Failed to upload subtitles", e);
}

View File

@ -157,7 +157,7 @@ public class OpenSubtitlesXmlRpc {
String name = data.get("title");
int year = Integer.parseInt(data.get("year"));
return new Movie(name, year, imdbid, -1);
return new Movie(name, year, imdbid);
} catch (RuntimeException e) {
// ignore, invalid response
debug.log(Level.WARNING, String.format("Failed to lookup movie by imdbid %s: %s", imdbid, e.getMessage()));
@ -289,7 +289,7 @@ public class OpenSubtitlesXmlRpc {
int year = Integer.parseInt(info.get("MovieYear"));
int imdb = Integer.parseInt(info.get("MovieImdbID"));
matches.add(new Movie(name, year, imdb, -1));
matches.add(new Movie(name, year, imdb));
}
}
}

View File

@ -28,7 +28,7 @@ public class SearchResult implements Serializable {
public SearchResult(int id, String name, String[] aliasNames) {
this.id = id;
this.name = name;
this.aliasNames = (aliasNames == null || aliasNames.length == 0) ? EMPTY_STRING_ARRAY : aliasNames.clone();
this.aliasNames = aliasNames == null || aliasNames.length == 0 ? EMPTY_STRING_ARRAY : aliasNames.clone();
}
public int getId() {

View File

@ -354,7 +354,7 @@ public class TMDbClient implements MovieIdentificationService, ArtworkProvider {
String title = getString(it, "title");
int year = getStringValue(it, "release_date", SimpleDate::parse).getYear();
int id = getInteger(it, "id");
return new Movie(title, year, 0, id);
return new Movie(title, null, year, 0, id, locale);
}).collect(toList());
}