Search in sources :

Example 6 with Show

use of com.battlelancer.seriesguide.dataliberation.model.Show 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)

Example 7 with Show

use of com.battlelancer.seriesguide.dataliberation.model.Show in project SeriesGuide by UweTrottmann.

the class TvdbTools method getShowDetails.

/**
     * Get show details from TVDb in the user preferred language. Tries to fetch additional
     * information from trakt.
     *
     * @param language A TVDb language code (ISO 639-1 two-letter format, see <a
     * href="http://www.thetvdb.com/wiki/index.php/API:languages.xml">TVDb wiki</a>). If not
     * supplied, TVDb falls back to English.
     */
@NonNull
public Show getShowDetails(int showTvdbId, @NonNull String language) throws TvdbException {
    // try to get some details from trakt
    com.uwetrottmann.trakt5.entities.Show traktShow = null;
    // always look up the trakt id based on the TVDb id
    // e.g. a TVDb id might be linked against the wrong trakt entry, then get fixed
    Integer showTraktId = lookupShowTraktId(showTvdbId);
    if (showTraktId != null) {
        traktShow = SgTrakt.executeCall(app, traktShows.get().summary(String.valueOf(showTraktId), Extended.FULL), "get show summary");
    }
    // get full show details from TVDb
    final Show show = downloadAndParseShow(showTvdbId, language);
    // fill in data from trakt
    if (traktShow != null) {
        if (traktShow.ids != null && traktShow.ids.trakt != null) {
            show.trakt_id = traktShow.ids.trakt;
        }
        if (traktShow.airs != null) {
            show.release_time = TimeTools.parseShowReleaseTime(traktShow.airs.time);
            show.release_weekday = TimeTools.parseShowReleaseWeekDay(traktShow.airs.day);
            show.release_timezone = traktShow.airs.timezone;
        }
        show.country = traktShow.country;
        show.first_aired = TimeTools.parseShowFirstRelease(traktShow.first_aired);
        show.rating = traktShow.rating == null ? 0.0 : traktShow.rating;
    } else {
        // keep any pre-existing trakt id (e.g. trakt call above might have failed temporarily)
        Timber.w("getShowDetails: failed to get trakt show details.");
        show.trakt_id = ShowTools.getShowTraktId(app, showTvdbId);
        // set default values
        show.release_time = -1;
        show.release_weekday = -1;
        show.first_aired = "";
        show.rating = 0.0;
    }
    return show;
}
Also used : BaseShow(com.uwetrottmann.trakt5.entities.BaseShow) Show(com.battlelancer.seriesguide.dataliberation.model.Show) NonNull(android.support.annotation.NonNull)

Example 8 with Show

use of com.battlelancer.seriesguide.dataliberation.model.Show in project SeriesGuide by UweTrottmann.

the class EpisodesActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_episodes);
    setupNavDrawer();
    // if coming from a notification, set last cleared time
    NotificationService.handleDeleteIntent(this, getIntent());
    // check for dual pane layout
    ButterKnife.bind(this);
    isDualPane = episodeDetailsPager != null;
    boolean isFinishing = false;
    // check if we have a certain episode to display
    final int episodeId = getIntent().getIntExtra(InitBundle.EPISODE_TVDBID, 0);
    if (episodeId != 0) {
        if (!isDualPane) {
            // display just the episode pager in its own activity
            Intent intent = new Intent(this, EpisodeDetailsActivity.class);
            intent.putExtra(EpisodeDetailsActivity.InitBundle.EPISODE_TVDBID, episodeId);
            startActivity(intent);
            isFinishing = true;
        } else {
            // get season id
            final Cursor episode = getContentResolver().query(Episodes.buildEpisodeUri(String.valueOf(episodeId)), new String[] { Episodes._ID, Seasons.REF_SEASON_ID }, null, null, null);
            if (episode != null && episode.moveToFirst()) {
                seasonTvdbId = episode.getInt(1);
            } else {
                // could not get season id
                isFinishing = true;
            }
            if (episode != null) {
                episode.close();
            }
        }
    }
    if (isFinishing) {
        finish();
        return;
    }
    if (seasonTvdbId == 0) {
        seasonTvdbId = getIntent().getIntExtra(InitBundle.SEASON_TVDBID, 0);
    }
    // get show id and season number
    final Cursor season = getContentResolver().query(Seasons.buildSeasonUri(String.valueOf(seasonTvdbId)), new String[] { Seasons._ID, Seasons.COMBINED, Shows.REF_SHOW_ID }, null, null, null);
    if (season != null && season.moveToFirst()) {
        seasonNumber = season.getInt(1);
        showTvdbId = season.getInt(2);
    } else {
        isFinishing = true;
    }
    if (season != null) {
        season.close();
    }
    if (isFinishing) {
        finish();
        return;
    }
    final Show show = DBUtils.getShow(this, showTvdbId);
    if (show == null) {
        finish();
        return;
    }
    setupActionBar(show);
    setupViews(savedInstanceState, show, episodeId);
    updateShowDelayed(showTvdbId);
}
Also used : Intent(android.content.Intent) Show(com.battlelancer.seriesguide.dataliberation.model.Show) Cursor(android.database.Cursor)

Example 9 with Show

use of com.battlelancer.seriesguide.dataliberation.model.Show in project SeriesGuide by UweTrottmann.

the class TvdbTools method getShowDetailsWithHexagon.

/**
     * Like {@link #getShowDetails(int, String)}, but if signed in and available adds properties
     * stored on Hexagon.
     */
@NonNull
private Show getShowDetailsWithHexagon(int showTvdbId, @Nullable String language) throws TvdbException {
    // check for show on hexagon
    com.uwetrottmann.seriesguide.backend.shows.model.Show hexagonShow;
    try {
        hexagonShow = ShowTools.Download.showFromHexagon(app, showTvdbId);
    } catch (IOException e) {
        HexagonTools.trackFailedRequest(app, "get show details", e);
        throw new TvdbCloudException("getShowDetailsWithHexagon: " + e.getMessage(), e);
    }
    // if no language is given, try to get the language stored on hexagon
    if (language == null && hexagonShow != null) {
        language = hexagonShow.getLanguage();
    }
    // if we still have no language, use the users default language
    if (TextUtils.isEmpty(language)) {
        language = DisplaySettings.getContentLanguage(app);
    }
    // get show info from TVDb and trakt
    Show show = getShowDetails(showTvdbId, language);
    if (hexagonShow != null) {
        // restore properties from hexagon
        if (hexagonShow.getIsFavorite() != null) {
            show.favorite = hexagonShow.getIsFavorite();
        }
        if (hexagonShow.getIsHidden() != null) {
            show.hidden = hexagonShow.getIsHidden();
        }
    }
    return show;
}
Also used : BaseShow(com.uwetrottmann.trakt5.entities.BaseShow) Show(com.battlelancer.seriesguide.dataliberation.model.Show) IOException(java.io.IOException) NonNull(android.support.annotation.NonNull)

Example 10 with Show

use of com.battlelancer.seriesguide.dataliberation.model.Show in project SeriesGuide by UweTrottmann.

the class DBUtils method getShow.

/**
     * Returns a {@link Show} object with only TVDB id, title and poster populated. Might return
     * {@code null} if there is no show with that TVDb id.
     */
@Nullable
public static Show getShow(Context context, int showTvdbId) {
    Cursor details = context.getContentResolver().query(Shows.buildShowUri(showTvdbId), SHOW_PROJECTION, null, null, null);
    Show show = null;
    if (details != null) {
        if (details.moveToFirst()) {
            show = new Show();
            show.tvdb_id = details.getInt(0);
            show.poster = details.getString(1);
            show.title = details.getString(2);
        }
        details.close();
    }
    return show;
}
Also used : Show(com.battlelancer.seriesguide.dataliberation.model.Show) Cursor(android.database.Cursor) Nullable(android.support.annotation.Nullable)

Aggregations

Show (com.battlelancer.seriesguide.dataliberation.model.Show)11 BaseShow (com.uwetrottmann.trakt5.entities.BaseShow)5 Intent (android.content.Intent)3 NonNull (android.support.annotation.NonNull)3 ArrayList (java.util.ArrayList)3 ContentProviderOperation (android.content.ContentProviderOperation)2 Cursor (android.database.Cursor)2 Gson (com.google.gson.Gson)2 SuppressLint (android.annotation.SuppressLint)1 ContentValues (android.content.ContentValues)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 TextAppearanceSpan (android.text.style.TextAppearanceSpan)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 List (com.battlelancer.seriesguide.dataliberation.model.List)1