use of com.uwetrottmann.trakt5.entities.Movie in project SeriesGuide by UweTrottmann.
the class BaseMovieActionTask method doBackgroundAction.
@Override
protected Integer doBackgroundAction(Void... params) {
// send to hexagon
if (isSendingToHexagon()) {
Movie movie = new Movie();
movie.setTmdbId(movieTmdbId);
setHexagonMovieProperties(movie);
List<Movie> movies = new ArrayList<>();
movies.add(movie);
MovieList movieList = new MovieList();
movieList.setMovies(movies);
try {
Movies moviesService = getContext().getHexagonTools().getMoviesService();
if (moviesService == null) {
return ERROR_HEXAGON_API;
}
moviesService.save(movieList).execute();
} catch (IOException e) {
HexagonTools.trackFailedRequest(getContext(), "save movie", e);
return ERROR_HEXAGON_API;
}
}
// send to trakt
if (isSendingToTrakt()) {
if (!TraktCredentials.get(getContext()).hasCredentials()) {
return ERROR_TRAKT_AUTH;
}
SyncItems items = new SyncItems().movies(new SyncMovie().id(MovieIds.tmdb(movieTmdbId)));
try {
Response<SyncResponse> response = doTraktAction(traktSync.get(), items).execute();
if (response.isSuccessful()) {
if (isMovieNotFound(response.body())) {
return ERROR_TRAKT_API_NOT_FOUND;
}
} else {
if (SgTrakt.isUnauthorized(getContext(), response)) {
return ERROR_TRAKT_AUTH;
}
SgTrakt.trackFailedRequest(getContext(), getTraktAction(), response);
return ERROR_TRAKT_API;
}
} catch (IOException e) {
SgTrakt.trackFailedRequest(getContext(), getTraktAction(), e);
return ERROR_TRAKT_API;
}
}
// update local state
if (!doDatabaseUpdate(getContext(), movieTmdbId)) {
return ERROR_DATABASE;
}
return SUCCESS;
}
use of com.uwetrottmann.trakt5.entities.Movie in project nzbhydra2 by theotherp.
the class TmdbHandler method getMovieByTmdbId.
private Movie getMovieByTmdbId(String tmdbId) throws InfoProviderException {
Movie movie;
Call<Movie> movieCall = tmdb.moviesService().summary(Integer.valueOf(tmdbId), configProvider.getBaseConfig().getSearching().getLanguage().orElse("en"), null);
try {
Response<Movie> response = movieCall.execute();
if (!response.isSuccessful()) {
throw new InfoProviderException("Error while contacting TMDB: " + response.errorBody().string());
}
movie = response.body();
} catch (IOException e) {
throw new InfoProviderException("Error while contacting TMDB", e);
}
return movie;
}
use of com.uwetrottmann.trakt5.entities.Movie in project nzbhydra2 by theotherp.
the class TmdbHandler method getMovieByImdbId.
private Movie getMovieByImdbId(String imdbId) throws InfoProviderException {
Movie movie;
Call<FindResults> resultsCall = tmdb.findService().find(imdbId, ExternalSource.IMDB_ID, configProvider.getBaseConfig().getSearching().getLanguage().orElse("en"));
try {
Response<FindResults> response = resultsCall.execute();
if (!response.isSuccessful()) {
throw new InfoProviderException("Error while contacting TMDB: " + response.errorBody().string());
}
if (response.body().movie_results.size() == 0) {
throw new InfoProviderException(String.format("TMDB query for IMDB ID %s returned no searchResults", imdbId));
}
movie = response.body().movie_results.get(0);
} catch (IOException e) {
throw new InfoProviderException("Error while contacting TMDB", e);
}
return movie;
}
use of com.uwetrottmann.trakt5.entities.Movie in project SeriesGuide by UweTrottmann.
the class MovieTools method lookupTraktId.
/**
* @return {@code null} if looking up the id failed, -1 if the movie was not found or the movie
* id if it was found.
*/
@Nullable
public Integer lookupTraktId(int movieTmdbId) {
try {
Response<List<SearchResult>> response = traktSearch.get().idLookup(IdType.TMDB, String.valueOf(movieTmdbId), Type.MOVIE, null, 1, 1).execute();
if (response.isSuccessful()) {
List<SearchResult> results = response.body();
if (results == null || results.size() != 1) {
Timber.e("Finding trakt movie failed (no results)");
return -1;
}
SearchResult result = results.get(0);
if (result.movie != null && result.movie.ids != null) {
return result.movie.ids.trakt;
}
Timber.e("Finding trakt movie failed (not in results)");
return -1;
} else {
Errors.logAndReport("movie trakt id lookup", response);
}
} catch (Exception e) {
Errors.logAndReport("movie trakt id lookup", e);
}
return null;
}
use of com.uwetrottmann.trakt5.entities.Movie in project SeriesGuide by UweTrottmann.
the class TraktFriendsMovieHistoryLoader method loadInBackground.
@Override
public List<NowAdapter.NowItem> loadInBackground() {
if (!TraktCredentials.get(getContext()).hasCredentials()) {
return null;
}
// get all trakt friends
Users traktUsers = SgApp.getServicesComponent(getContext()).traktUsers();
List<Friend> friends = SgTrakt.executeAuthenticatedCall(getContext(), traktUsers.friends(UserSlug.ME, Extended.FULL), "get friends");
if (friends == null) {
return null;
}
int size = friends.size();
if (size == 0) {
// no friends, done.
return null;
}
// estimate list size
List<NowAdapter.NowItem> items = new ArrayList<>(size + 1);
// add header
items.add(new NowAdapter.NowItem().header(getContext().getString(R.string.friends_recently)));
// add last watched movie for each friend
for (int i = 0; i < size; i++) {
Friend friend = friends.get(i);
// at least need a userSlug
if (friend.user == null) {
continue;
}
String userSlug = friend.user.ids.slug;
if (TextUtils.isEmpty(userSlug)) {
continue;
}
// get last watched episode
List<HistoryEntry> history = SgTrakt.executeCall(traktUsers.history(new UserSlug(userSlug), HistoryType.MOVIES, 1, 1, null, null, null), "get friend movie history");
if (history == null || history.size() == 0) {
// no history
continue;
}
HistoryEntry entry = history.get(0);
if (entry.watched_at == null || entry.movie == null) {
// missing required values
continue;
}
String avatar = (friend.user.images == null || friend.user.images.avatar == null) ? null : friend.user.images.avatar.full;
// trakt has removed image support: currently displaying no image
NowAdapter.NowItem nowItem = new NowAdapter.NowItem().displayData(entry.watched_at.toInstant().toEpochMilli(), entry.movie.title, null, null).tmdbId(entry.movie.ids == null ? null : entry.movie.ids.tmdb).friend(friend.user.username, avatar, entry.action);
items.add(nowItem);
}
// only have a header? return nothing
if (items.size() == 1) {
return Collections.emptyList();
}
return items;
}
Aggregations