Search in sources :

Example 1 with SeriesImageQueryResultResponse

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;
}
Also used : TheTvdbSeries(com.uwetrottmann.thetvdb.services.TheTvdbSeries) Series(com.uwetrottmann.thetvdb.entities.Series) BaseShow(com.uwetrottmann.trakt5.entities.BaseShow) Show(com.battlelancer.seriesguide.dataliberation.model.Show) SeriesImageQueryResultResponse(com.uwetrottmann.thetvdb.entities.SeriesImageQueryResultResponse) NonNull(android.support.annotation.NonNull)

Aggregations

NonNull (android.support.annotation.NonNull)1 Show (com.battlelancer.seriesguide.dataliberation.model.Show)1 Series (com.uwetrottmann.thetvdb.entities.Series)1 SeriesImageQueryResultResponse (com.uwetrottmann.thetvdb.entities.SeriesImageQueryResultResponse)1 TheTvdbSeries (com.uwetrottmann.thetvdb.services.TheTvdbSeries)1 BaseShow (com.uwetrottmann.trakt5.entities.BaseShow)1