Search in sources :

Example 6 with Movie

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;
}
Also used : SyncMovie(com.uwetrottmann.trakt5.entities.SyncMovie) Movie(com.uwetrottmann.seriesguide.backend.movies.model.Movie) SyncItems(com.uwetrottmann.trakt5.entities.SyncItems) SyncResponse(com.uwetrottmann.trakt5.entities.SyncResponse) ArrayList(java.util.ArrayList) MovieList(com.uwetrottmann.seriesguide.backend.movies.model.MovieList) SyncMovie(com.uwetrottmann.trakt5.entities.SyncMovie) Movies(com.uwetrottmann.seriesguide.backend.movies.Movies) IOException(java.io.IOException)

Example 7 with Movie

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;
}
Also used : Movie(com.uwetrottmann.tmdb2.entities.Movie) IOException(java.io.IOException)

Example 8 with 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;
}
Also used : Movie(com.uwetrottmann.tmdb2.entities.Movie) FindResults(com.uwetrottmann.tmdb2.entities.FindResults) IOException(java.io.IOException)

Example 9 with 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;
}
Also used : LinkedList(java.util.LinkedList) List(java.util.List) SearchResult(com.uwetrottmann.trakt5.entities.SearchResult) Nullable(androidx.annotation.Nullable)

Example 10 with Movie

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;
}
Also used : UserSlug(com.uwetrottmann.trakt5.entities.UserSlug) NowAdapter(com.battlelancer.seriesguide.ui.shows.NowAdapter) ArrayList(java.util.ArrayList) Users(com.uwetrottmann.trakt5.services.Users) Friend(com.uwetrottmann.trakt5.entities.Friend) HistoryEntry(com.uwetrottmann.trakt5.entities.HistoryEntry)

Aggregations

Movie (com.uwetrottmann.tmdb2.entities.Movie)14 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 SyncMovie (com.uwetrottmann.trakt5.entities.SyncMovie)5 List (java.util.List)5 OperationApplicationException (android.content.OperationApplicationException)4 LinkedList (java.util.LinkedList)4 ContentProviderOperation (android.content.ContentProviderOperation)3 Nullable (androidx.annotation.Nullable)3 HistoryEntry (com.uwetrottmann.trakt5.entities.HistoryEntry)3 Intent (android.content.Intent)2 Nullable (android.support.annotation.Nullable)2 MovieDetails (com.battlelancer.seriesguide.ui.movies.MovieDetails)2 MovieList (com.uwetrottmann.seriesguide.backend.movies.model.MovieList)2 BaseMovie (com.uwetrottmann.trakt5.entities.BaseMovie)2 Comment (com.uwetrottmann.trakt5.entities.Comment)2 Episode (com.uwetrottmann.trakt5.entities.Episode)2 Friend (com.uwetrottmann.trakt5.entities.Friend)2 LastActivities (com.uwetrottmann.trakt5.entities.LastActivities)2 Ratings (com.uwetrottmann.trakt5.entities.Ratings)2