use of com.uwetrottmann.trakt5.entities.Show in project SeriesGuide by UweTrottmann.
the class TraktTask method buildComment.
private Comment buildComment() {
Comment comment = new Comment();
comment.comment = mArgs.getString(InitBundle.MESSAGE);
comment.spoiler = mArgs.getBoolean(InitBundle.ISSPOILER);
// as determined by "science", episode comments are most likely, so check for them first
// episode?
int episodeTvdbId = mArgs.getInt(InitBundle.EPISODE_TVDBID);
if (episodeTvdbId != 0) {
comment.episode = new Episode();
comment.episode.ids = EpisodeIds.tvdb(episodeTvdbId);
return comment;
}
// show?
int showTvdbId = mArgs.getInt(InitBundle.SHOW_TVDBID);
if (showTvdbId != 0) {
comment.show = new Show();
comment.show.ids = ShowIds.tvdb(showTvdbId);
return comment;
}
// movie!
int movieTmdbId = mArgs.getInt(InitBundle.MOVIE_TMDB_ID);
comment.movie = new Movie();
comment.movie.ids = MovieIds.tmdb(movieTmdbId);
return comment;
}
use of com.uwetrottmann.trakt5.entities.Show in project SeriesGuide by UweTrottmann.
the class EpisodeHistoryAdapter method getView.
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
// A ViewHolder keeps references to child views to avoid
// unnecessary calls to findViewById() on each row.
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item_history, parent, false);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
HistoryEntry item = getItem(position);
if (item == null) {
// all bets are off!
return convertView;
}
// show title
holder.title.setText(item.show == null ? null : item.show.title);
// show poster, use a TVDB one
String posterUrl;
Integer showTvdbId = (item.show == null || item.show.ids == null) ? null : item.show.ids.tvdb;
if (localShowPosters != null && showTvdbId != null) {
// prefer poster of already added show, fall back to first uploaded poster
posterUrl = TvdbImageTools.smallSizeOrFirstUrl(localShowPosters.get(showTvdbId), showTvdbId);
} else {
posterUrl = null;
}
TvdbImageTools.loadShowPosterResizeSmallCrop(getContext(), holder.poster, posterUrl);
// timestamp
if (item.watched_at != null) {
CharSequence timestamp = DateUtils.getRelativeTimeSpanString(item.watched_at.getMillis(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_ALL);
holder.timestamp.setText(timestamp);
} else {
holder.timestamp.setText(null);
}
// action type indicator
if ("watch".equals(item.action)) {
// marked watched
holder.type.setImageResource(getResIdDrawableWatched());
} else {
// check-in, scrobble
holder.type.setImageResource(getResIdDrawableCheckin());
}
// episode
if (item.episode != null && item.episode.season != null && item.episode.number != null) {
holder.description.setText(TextTools.getNextEpisodeString(getContext(), item.episode.season, item.episode.number, item.episode.title));
} else {
holder.description.setText(null);
}
return convertView;
}
use of com.uwetrottmann.trakt5.entities.Show in project SeriesGuide by UweTrottmann.
the class TraktAddLoader method parseTraktShowsToSearchResults.
/**
* Transforms a list of trakt shows to a list of {@link SearchResult}, marks shows already in
* the local database as added.
*/
public static List<SearchResult> parseTraktShowsToSearchResults(Context context, @NonNull List<Show> traktShows, @Nullable String overrideLanguage) {
List<SearchResult> results = new ArrayList<>();
// build list
SparseArrayCompat<String> existingPosterPaths = ShowTools.getShowTvdbIdsAndPosters(context);
for (Show show : traktShows) {
if (show.ids == null || show.ids.tvdb == null) {
// has no TheTVDB id
continue;
}
SearchResult result = new SearchResult();
result.tvdbid = show.ids.tvdb;
result.title = show.title;
// search results return an overview, while trending and other lists do not
result.overview = !TextUtils.isEmpty(show.overview) ? show.overview : show.year != null ? String.valueOf(show.year) : "";
if (existingPosterPaths != null && existingPosterPaths.indexOfKey(show.ids.tvdb) >= 0) {
// is already in local database
result.state = SearchResult.STATE_ADDED;
// use the poster we fetched for it (or null if there is none)
result.posterPath = existingPosterPaths.get(show.ids.tvdb);
}
if (overrideLanguage != null) {
result.language = overrideLanguage;
}
results.add(result);
}
return results;
}
use of com.uwetrottmann.trakt5.entities.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;
}
use of com.uwetrottmann.trakt5.entities.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;
}
Aggregations