Refactor MediaBindingBean error handling
This commit is contained in:
parent
1d997e556e
commit
7feeb0a3be
|
@ -515,16 +515,16 @@ public class ExpressionFormatMethods {
|
||||||
* Episode utilities (EXPERIMENTAL)
|
* Episode utilities (EXPERIMENTAL)
|
||||||
*/
|
*/
|
||||||
public static EpisodeInfo getInfo(Episode self) throws Exception {
|
public static EpisodeInfo getInfo(Episode self) throws Exception {
|
||||||
if (TheTVDB.getIdentifier().equals(self.getSeriesInfo().getDatabase()))
|
if (TheTVDB.getIdentifier().equals(self.getSeriesInfo().getDatabase())) {
|
||||||
return TheTVDBv2.getEpisodeInfo(self.getId(), Locale.ENGLISH);
|
return TheTVDBv2.getEpisodeInfo(self.getId(), Locale.ENGLISH);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getActors(SeriesInfo self) throws Exception {
|
public static List<String> getActors(SeriesInfo self) throws Exception {
|
||||||
if (TheTVDB.getIdentifier().equals(self.getDatabase()))
|
if (TheTVDB.getIdentifier().equals(self.getDatabase())) {
|
||||||
return TheTVDBv2.getActors(self.getId(), Locale.ENGLISH).stream().map(Person::getName).collect(toList());
|
return TheTVDBv2.getActors(self.getId(), Locale.ENGLISH).stream().map(Person::getName).collect(toList());
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -181,23 +181,22 @@ public class MediaBindingBean {
|
||||||
|
|
||||||
@Define("t")
|
@Define("t")
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
|
String t = null;
|
||||||
|
|
||||||
if (infoObject instanceof Episode) {
|
if (infoObject instanceof Episode) {
|
||||||
// support multi-episode title formatting
|
t = infoObject instanceof MultiEpisode ? EpisodeFormat.SeasonEpisode.formatMultiTitle(getEpisodes()) : getEpisode().getTitle(); // implicit support for multi-episode title formatting
|
||||||
String t = infoObject instanceof MultiEpisode ? EpisodeFormat.SeasonEpisode.formatMultiTitle(getEpisodes()) : getEpisode().getTitle();
|
} else if (infoObject instanceof Movie) {
|
||||||
|
t = getMovieInfo().getTagline();
|
||||||
// enforce title length limit by default
|
} else if (infoObject instanceof AudioTrack) {
|
||||||
return truncateText(t, NamingStandard.TITLE_MAX_LENGTH);
|
t = getMusic().getTrackTitle() != null ? getMusic().getTrackTitle() : getMusic().getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (infoObject instanceof AudioTrack) {
|
// enforce title length limit by default
|
||||||
return getMusic().getTrackTitle() != null ? getMusic().getTrackTitle() : getMusic().getTitle();
|
return truncateText(t, NamingStandard.TITLE_MAX_LENGTH);
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("d")
|
@Define("d")
|
||||||
public SimpleDate getReleaseDate() throws Exception {
|
public SimpleDate getReleaseDate() {
|
||||||
if (infoObject instanceof Episode)
|
if (infoObject instanceof Episode)
|
||||||
return getEpisode().getAirdate();
|
return getEpisode().getAirdate();
|
||||||
if (infoObject instanceof Movie)
|
if (infoObject instanceof Movie)
|
||||||
|
@ -260,7 +259,7 @@ public class MediaBindingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("primaryTitle")
|
@Define("primaryTitle")
|
||||||
public String getPrimaryTitle() throws Exception {
|
public String getPrimaryTitle() {
|
||||||
if (infoObject instanceof Movie)
|
if (infoObject instanceof Movie)
|
||||||
return getPrimaryMovieInfo().getOriginalName();
|
return getPrimaryMovieInfo().getOriginalName();
|
||||||
if (infoObject instanceof Episode)
|
if (infoObject instanceof Episode)
|
||||||
|
@ -282,7 +281,7 @@ public class MediaBindingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("tmdbid")
|
@Define("tmdbid")
|
||||||
public String getTmdbId() throws Exception {
|
public String getTmdbId() {
|
||||||
if (getMovie().getTmdbId() > 0)
|
if (getMovie().getTmdbId() > 0)
|
||||||
return String.valueOf(getMovie().getTmdbId());
|
return String.valueOf(getMovie().getTmdbId());
|
||||||
if (getMovie().getImdbId() > 0)
|
if (getMovie().getImdbId() > 0)
|
||||||
|
@ -292,7 +291,7 @@ public class MediaBindingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("imdbid")
|
@Define("imdbid")
|
||||||
public String getImdbId() throws Exception {
|
public String getImdbId() {
|
||||||
if (getMovie().getImdbId() > 0)
|
if (getMovie().getImdbId() > 0)
|
||||||
return String.format("tt%07d", getMovie().getImdbId());
|
return String.format("tt%07d", getMovie().getImdbId());
|
||||||
if (getMovie().getTmdbId() > 0)
|
if (getMovie().getTmdbId() > 0)
|
||||||
|
@ -556,7 +555,7 @@ public class MediaBindingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("languages")
|
@Define("languages")
|
||||||
public List<Language> getSpokenLanguages() throws Exception {
|
public List<Language> getSpokenLanguages() {
|
||||||
if (infoObject instanceof Movie) {
|
if (infoObject instanceof Movie) {
|
||||||
List<Locale> languages = getMovieInfo().getSpokenLanguages();
|
List<Locale> languages = getMovieInfo().getSpokenLanguages();
|
||||||
return languages.stream().map(Language::getLanguage).filter(Objects::nonNull).collect(toList());
|
return languages.stream().map(Language::getLanguage).filter(Objects::nonNull).collect(toList());
|
||||||
|
@ -569,7 +568,7 @@ public class MediaBindingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("runtime")
|
@Define("runtime")
|
||||||
public Integer getRuntime() throws Exception {
|
public Integer getRuntime() {
|
||||||
if (infoObject instanceof Movie)
|
if (infoObject instanceof Movie)
|
||||||
return getMovieInfo().getRuntime();
|
return getMovieInfo().getRuntime();
|
||||||
if (infoObject instanceof Episode)
|
if (infoObject instanceof Episode)
|
||||||
|
@ -589,7 +588,7 @@ public class MediaBindingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("genres")
|
@Define("genres")
|
||||||
public List<String> getGenres() throws Exception {
|
public List<String> getGenres() {
|
||||||
if (infoObject instanceof Movie)
|
if (infoObject instanceof Movie)
|
||||||
return getMovieInfo().getGenres();
|
return getMovieInfo().getGenres();
|
||||||
if (infoObject instanceof Episode)
|
if (infoObject instanceof Episode)
|
||||||
|
@ -599,7 +598,7 @@ public class MediaBindingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("genre")
|
@Define("genre")
|
||||||
public String getPrimaryGenre() throws Exception {
|
public String getPrimaryGenre() {
|
||||||
return getGenres().iterator().next();
|
return getGenres().iterator().next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -608,13 +607,13 @@ public class MediaBindingBean {
|
||||||
if (infoObject instanceof Movie)
|
if (infoObject instanceof Movie)
|
||||||
return getMovieInfo().getDirector();
|
return getMovieInfo().getDirector();
|
||||||
if (infoObject instanceof Episode)
|
if (infoObject instanceof Episode)
|
||||||
return ExpressionFormatMethods.getInfo(getEpisode()).getDirectors().iterator().next(); // use TheTVDB API v2 to retrieve extended episode info
|
return ExpressionFormatMethods.getInfo(getEpisode()).getDirector(); // use TheTVDB API v2 to retrieve extended episode info
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("certification")
|
@Define("certification")
|
||||||
public String getCertification() throws Exception {
|
public String getCertification() {
|
||||||
if (infoObject instanceof Movie)
|
if (infoObject instanceof Movie)
|
||||||
return getMovieInfo().getCertification();
|
return getMovieInfo().getCertification();
|
||||||
if (infoObject instanceof Episode)
|
if (infoObject instanceof Episode)
|
||||||
|
@ -624,7 +623,7 @@ public class MediaBindingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("rating")
|
@Define("rating")
|
||||||
public Double getRating() throws Exception {
|
public Double getRating() {
|
||||||
if (infoObject instanceof Movie)
|
if (infoObject instanceof Movie)
|
||||||
return getMovieInfo().getRating();
|
return getMovieInfo().getRating();
|
||||||
if (infoObject instanceof Episode)
|
if (infoObject instanceof Episode)
|
||||||
|
@ -634,7 +633,7 @@ public class MediaBindingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("votes")
|
@Define("votes")
|
||||||
public Integer getVotes() throws Exception {
|
public Integer getVotes() {
|
||||||
if (infoObject instanceof Movie)
|
if (infoObject instanceof Movie)
|
||||||
return getMovieInfo().getVotes();
|
return getMovieInfo().getVotes();
|
||||||
if (infoObject instanceof Episode)
|
if (infoObject instanceof Episode)
|
||||||
|
@ -644,7 +643,7 @@ public class MediaBindingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("collection")
|
@Define("collection")
|
||||||
public String getCollection() throws Exception {
|
public String getCollection() {
|
||||||
if (infoObject instanceof Movie)
|
if (infoObject instanceof Movie)
|
||||||
return getMovieInfo().getCollection();
|
return getMovieInfo().getCollection();
|
||||||
|
|
||||||
|
@ -652,7 +651,7 @@ public class MediaBindingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("info")
|
@Define("info")
|
||||||
public synchronized AssociativeScriptObject getMetaInfo() throws Exception {
|
public synchronized AssociativeScriptObject getMetaInfo() {
|
||||||
if (infoObject instanceof Movie)
|
if (infoObject instanceof Movie)
|
||||||
return createPropertyBindings(getMovieInfo());
|
return createPropertyBindings(getMovieInfo());
|
||||||
if (infoObject instanceof Episode)
|
if (infoObject instanceof Episode)
|
||||||
|
@ -683,7 +682,7 @@ public class MediaBindingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("localize")
|
@Define("localize")
|
||||||
public Object getLocalizedInfoObject() throws Exception {
|
public Object getLocalizedInfoObject() {
|
||||||
return new DynamicBindings(Language::availableLanguages, k -> {
|
return new DynamicBindings(Language::availableLanguages, k -> {
|
||||||
Language language = Language.findLanguage(k);
|
Language language = Language.findLanguage(k);
|
||||||
if (language == null) {
|
if (language == null) {
|
||||||
|
@ -1034,9 +1033,14 @@ public class MediaBindingBean {
|
||||||
return getMediaFile();
|
return getMediaFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SeriesInfo getPrimarySeriesInfo() throws Exception {
|
public SeriesInfo getPrimarySeriesInfo() {
|
||||||
if (TheTVDB.getIdentifier().equals(getSeriesInfo().getDatabase()))
|
if (TheTVDB.getIdentifier().equals(getSeriesInfo().getDatabase())) {
|
||||||
return TheTVDB.getSeriesInfo(getSeriesInfo().getId(), Locale.ENGLISH);
|
try {
|
||||||
|
return TheTVDB.getSeriesInfo(getSeriesInfo().getId(), Locale.ENGLISH);
|
||||||
|
} catch (Exception e) {
|
||||||
|
debug.warning("Failed to retrieve primary series info: " + e); // default to seriesInfo property
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return getSeriesInfo();
|
return getSeriesInfo();
|
||||||
}
|
}
|
||||||
|
@ -1044,12 +1048,20 @@ public class MediaBindingBean {
|
||||||
private final Resource<MovieInfo> primaryMovieInfo = Resource.lazy(() -> TheMovieDB.getMovieInfo(getMovie(), Locale.ENGLISH, false));
|
private final Resource<MovieInfo> primaryMovieInfo = Resource.lazy(() -> TheMovieDB.getMovieInfo(getMovie(), Locale.ENGLISH, false));
|
||||||
private final Resource<MovieInfo> extendedMovieInfo = Resource.lazy(() -> getMovieInfo(getMovie().getLanguage(), true));
|
private final Resource<MovieInfo> extendedMovieInfo = Resource.lazy(() -> getMovieInfo(getMovie().getLanguage(), true));
|
||||||
|
|
||||||
public MovieInfo getPrimaryMovieInfo() throws Exception {
|
public MovieInfo getPrimaryMovieInfo() {
|
||||||
return primaryMovieInfo.get();
|
try {
|
||||||
|
return primaryMovieInfo.get();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BindingException("info", "Failed to retrieve primary movie info: " + e, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MovieInfo getMovieInfo() throws Exception {
|
public MovieInfo getMovieInfo() {
|
||||||
return extendedMovieInfo.get();
|
try {
|
||||||
|
return extendedMovieInfo.get();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BindingException("info", "Failed to retrieve extended movie info: " + e, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized MovieInfo getMovieInfo(Locale locale, boolean extendedInfo) throws Exception {
|
public synchronized MovieInfo getMovieInfo(Locale locale, boolean extendedInfo) throws Exception {
|
||||||
|
|
|
@ -106,7 +106,7 @@ public class Normalization {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String truncateText(String title, int limit) {
|
public static String truncateText(String title, int limit) {
|
||||||
if (title.length() < limit) {
|
if (title == null || title.length() < limit) {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue