use of com.uwetrottmann.thetvdb.entities.SeriesImageQueryResultResponse in project SeriesGuide by UweTrottmann.
the class TvdbTools method downloadAndParseShow.
/**
* Get a show from TVDb. Tries to fetch in the desired language, but will fall back to the
* default entry if no translation exists. The returned entity will still have its <b>language
* property set to the desired language</b>, which might not be the language of the actual
* content.
*/
@NonNull
private Show downloadAndParseShow(int showTvdbId, @NonNull String desiredLanguage) throws TvdbException {
Series series = getSeries(showTvdbId, desiredLanguage);
// title is null if no translation exists
boolean noTranslation = TextUtils.isEmpty(series.seriesName);
if (noTranslation) {
// try to fetch default entry
series = getSeries(showTvdbId, null);
}
Show result = new Show();
result.tvdb_id = showTvdbId;
// actors are unused, are fetched from tmdb
result.title = series.seriesName != null ? series.seriesName.trim() : null;
result.network = series.network;
result.content_rating = series.rating;
result.imdb_id = series.imdbId;
result.genres = TextTools.mendTvdbStrings(series.genre);
// requested language, might not be the content language.
result.language = desiredLanguage;
result.last_edited = series.lastUpdated;
if (noTranslation || TextUtils.isEmpty(series.overview)) {
// add note about non-translated or non-existing overview
String untranslatedOverview = series.overview;
result.overview = app.getString(R.string.no_translation, LanguageTools.getShowLanguageStringFor(app, desiredLanguage), app.getString(R.string.tvdb));
if (!TextUtils.isEmpty(untranslatedOverview)) {
result.overview += "\n\n" + untranslatedOverview;
}
} else {
result.overview = series.overview;
}
try {
result.runtime = Integer.parseInt(series.runtime);
} catch (NumberFormatException e) {
// an hour is always a good estimate...
result.runtime = 60;
}
String status = series.status;
if (status != null) {
if (status.length() == 10) {
result.status = ShowStatusExport.CONTINUING;
} else if (status.length() == 5) {
result.status = ShowStatusExport.ENDED;
} else {
result.status = ShowStatusExport.UNKNOWN;
}
}
// poster
retrofit2.Response<SeriesImageQueryResultResponse> posterResponse;
posterResponse = getSeriesPosters(showTvdbId, desiredLanguage);
if (posterResponse.code() == 404) {
// no posters for this language, fall back to default
posterResponse = getSeriesPosters(showTvdbId, null);
}
if (posterResponse.isSuccessful()) {
result.poster = getHighestRatedPoster(posterResponse.body().data);
}
return result;
}
Aggregations