Search in sources :

Example 1 with Series

use of com.uwetrottmann.thetvdb.entities.Series in project SeriesGuide by UweTrottmann.

the class TvdbTools method searchSeries.

@Nullable
public List<SearchResult> searchSeries(@NonNull String query, @Nullable final String language) throws TvdbException {
    retrofit2.Response<SeriesResultsResponse> response;
    try {
        response = tvdbSearch.get().series(query, null, null, language).execute();
    } catch (IOException e) {
        throw new TvdbException("searchSeries: " + e.getMessage(), e);
    }
    if (response.code() == 404) {
        // API returns 404 if there are no search results
        return null;
    }
    ensureSuccessfulResponse(response.raw(), "searchSeries: ");
    List<Series> tvdbResults = response.body().data;
    if (tvdbResults == null || tvdbResults.size() == 0) {
        // no results from tvdb
        return null;
    }
    // parse into our data format
    List<SearchResult> results = new ArrayList<>(tvdbResults.size());
    for (Series tvdbResult : tvdbResults) {
        SearchResult result = new SearchResult();
        result.tvdbid = tvdbResult.id;
        result.title = tvdbResult.seriesName;
        result.overview = tvdbResult.overview;
        result.language = language;
        results.add(result);
    }
    return results;
}
Also used : TheTvdbSeries(com.uwetrottmann.thetvdb.services.TheTvdbSeries) Series(com.uwetrottmann.thetvdb.entities.Series) SeriesResultsResponse(com.uwetrottmann.thetvdb.entities.SeriesResultsResponse) ArrayList(java.util.ArrayList) SearchResult(com.battlelancer.seriesguide.items.SearchResult) IOException(java.io.IOException) Nullable(android.support.annotation.Nullable)

Example 2 with Series

use of com.uwetrottmann.thetvdb.entities.Series 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

Series (com.uwetrottmann.thetvdb.entities.Series)2 TheTvdbSeries (com.uwetrottmann.thetvdb.services.TheTvdbSeries)2 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 Show (com.battlelancer.seriesguide.dataliberation.model.Show)1 SearchResult (com.battlelancer.seriesguide.items.SearchResult)1 SeriesImageQueryResultResponse (com.uwetrottmann.thetvdb.entities.SeriesImageQueryResultResponse)1 SeriesResultsResponse (com.uwetrottmann.thetvdb.entities.SeriesResultsResponse)1 BaseShow (com.uwetrottmann.trakt5.entities.BaseShow)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1