Search in sources :

Example 26 with Movie

use of com.uwetrottmann.trakt5.entities.Movie in project nzbhydra2 by theotherp.

the class TmdbHandler method fromImdb.

private TmdbSearchResult fromImdb(String imdbId) throws InfoProviderException {
    Movie movie = getMovieByImdbId(imdbId);
    TmdbSearchResult result = getSearchResultFromMovie(movie);
    return result;
}
Also used : Movie(com.uwetrottmann.tmdb2.entities.Movie)

Example 27 with Movie

use of com.uwetrottmann.trakt5.entities.Movie in project SeriesGuide by UweTrottmann.

the class TmdbSyncTest method insertMovie.

private void insertMovie(int tmdbId, long releaseDateMs, Long lastUpdatedMs) {
    Movie movie = new Movie();
    movie.id = tmdbId;
    movie.release_date = new Date(releaseDateMs);
    MovieDetails details = new MovieDetails();
    details.setInCollection(true);
    details.setInWatchlist(true);
    details.tmdbMovie(movie);
    ContentValues values = details.toContentValuesInsert();
    if (lastUpdatedMs == null) {
        values.remove(Movies.LAST_UPDATED);
    } else {
        values.put(Movies.LAST_UPDATED, lastUpdatedMs);
    }
    resolver.insert(Movies.CONTENT_URI, values);
}
Also used : ContentValues(android.content.ContentValues) Movie(com.uwetrottmann.tmdb2.entities.Movie) SgMovie(com.battlelancer.seriesguide.model.SgMovie) Date(java.util.Date) MovieDetails(com.battlelancer.seriesguide.ui.movies.MovieDetails)

Example 28 with Movie

use of com.uwetrottmann.trakt5.entities.Movie in project SeriesGuide by UweTrottmann.

the class MigrationTest method getTestMovieDetails.

private static MovieDetails getTestMovieDetails(@Nullable Integer tmdbId) {
    MovieDetails movieDetails = new MovieDetails();
    Movie tmdbMovie = new Movie();
    if (tmdbId != null) {
        tmdbMovie.id = tmdbId;
    } else {
        tmdbMovie.id = 12;
    }
    movieDetails.tmdbMovie(tmdbMovie);
    return movieDetails;
}
Also used : Movie(com.uwetrottmann.tmdb2.entities.Movie) MovieDetails(com.battlelancer.seriesguide.ui.movies.MovieDetails)

Example 29 with Movie

use of com.uwetrottmann.trakt5.entities.Movie in project SeriesGuide by UweTrottmann.

the class TraktTask method buildComment.

@Nullable
private Comment buildComment() {
    Comment comment = new Comment();
    comment.comment = args.getString(InitBundle.MESSAGE);
    comment.spoiler = args.getBoolean(InitBundle.ISSPOILER);
    // episode?
    long episodeId = args.getLong(InitBundle.EPISODE_ID);
    if (episodeId != 0) {
        // Check in using episode TMDB ID
        // Note: using show Trakt ID and episode numbers does not work (comments on show).
        int episodeTmdbIdOrZero = SgRoomDatabase.getInstance(context).sgEpisode2Helper().getEpisodeTmdbId(episodeId);
        if (episodeTmdbIdOrZero == 0) {
            Timber.e("Failed to get episode %d", episodeId);
            return null;
        }
        comment.episode = new Episode();
        comment.episode.ids = EpisodeIds.tmdb(episodeTmdbIdOrZero);
        return comment;
    }
    // show?
    long showId = args.getLong(InitBundle.SHOW_ID);
    if (showId != 0) {
        Integer showTraktId = ShowTools.getShowTraktId(context, showId);
        if (showTraktId == null) {
            Timber.e("Failed to get show %d", showId);
            return null;
        }
        comment.show = new Show();
        comment.show.ids = ShowIds.trakt(showTraktId);
        return comment;
    }
    // movie!
    int movieTmdbId = args.getInt(InitBundle.MOVIE_TMDB_ID);
    comment.movie = new Movie();
    comment.movie.ids = MovieIds.tmdb(movieTmdbId);
    return comment;
}
Also used : Comment(com.uwetrottmann.trakt5.entities.Comment) Episode(com.uwetrottmann.trakt5.entities.Episode) SyncEpisode(com.uwetrottmann.trakt5.entities.SyncEpisode) SyncMovie(com.uwetrottmann.trakt5.entities.SyncMovie) Movie(com.uwetrottmann.trakt5.entities.Movie) Show(com.uwetrottmann.trakt5.entities.Show) SuppressLint(android.annotation.SuppressLint) Nullable(androidx.annotation.Nullable)

Example 30 with Movie

use of com.uwetrottmann.trakt5.entities.Movie in project SeriesGuide by UweTrottmann.

the class TraktSync method sync.

/**
 * @param onlyRatings To not conflict with Hexagon sync, can turn on so only
 *                    ratings are synced.
 */
public SgSyncAdapter.UpdateResult sync(long currentTime, boolean onlyRatings) {
    // get last activity timestamps
    progress.publish(SyncProgress.Step.TRAKT);
    if (!AndroidUtils.isNetworkConnected(context)) {
        progress.recordError();
        return SgSyncAdapter.UpdateResult.INCOMPLETE;
    }
    LastActivities lastActivity = getLastActivity();
    if (lastActivity == null || lastActivity.episodes == null || lastActivity.shows == null || lastActivity.movies == null) {
        // trakt is offline or busy, or there are server errors, try later.
        progress.recordError();
        Timber.e("performTraktSync: last activity download failed");
        return SgSyncAdapter.UpdateResult.INCOMPLETE;
    }
    TraktRatingsSync ratingsSync = new TraktRatingsSync(context, traktSync);
    Map<Integer, Long> tmdbIdsToShowIds = SgApp.getServicesComponent(context).showTools().getTmdbIdsToShowIds();
    if (tmdbIdsToShowIds.size() == 0) {
        Timber.d("performTraktSync: no local shows, skip shows");
    } else {
        if (!onlyRatings) {
            // EPISODES
            // download and upload episode watched and collected flags
            progress.publish(SyncProgress.Step.TRAKT_EPISODES);
            if (!AndroidUtils.isNetworkConnected(context)) {
                progress.recordError();
                return SgSyncAdapter.UpdateResult.INCOMPLETE;
            }
            if (!syncEpisodes(tmdbIdsToShowIds, lastActivity.episodes, currentTime)) {
                progress.recordError();
                return SgSyncAdapter.UpdateResult.INCOMPLETE;
            }
        }
        // download ratings
        progress.publish(SyncProgress.Step.TRAKT_RATINGS);
        if (!AndroidUtils.isNetworkConnected(context)) {
            progress.recordError();
            return SgSyncAdapter.UpdateResult.INCOMPLETE;
        }
        if (!ratingsSync.downloadForEpisodes(lastActivity.episodes.rated_at)) {
            progress.recordError();
            return SgSyncAdapter.UpdateResult.INCOMPLETE;
        }
        // download ratings
        if (!AndroidUtils.isNetworkConnected(context)) {
            progress.recordError();
            return SgSyncAdapter.UpdateResult.INCOMPLETE;
        }
        if (!ratingsSync.downloadForShows(lastActivity.shows.rated_at)) {
            progress.recordError();
            return SgSyncAdapter.UpdateResult.INCOMPLETE;
        }
    }
    // MOVIES
    progress.publish(SyncProgress.Step.TRAKT_MOVIES);
    TraktMovieSync movieSync = new TraktMovieSync(context, movieTools, traktSync);
    // sync watchlist, collection and watched movies with trakt
    if (!onlyRatings) {
        if (!AndroidUtils.isNetworkConnected(context)) {
            progress.recordError();
            return SgSyncAdapter.UpdateResult.INCOMPLETE;
        }
        if (!movieSync.syncLists(lastActivity.movies)) {
            progress.recordError();
            return SgSyncAdapter.UpdateResult.INCOMPLETE;
        }
        // clean up any useless movies (not watched or not in any list)
        MovieTools.deleteUnusedMovies(context);
    }
    // download movie ratings
    progress.publish(SyncProgress.Step.TRAKT_RATINGS);
    if (!AndroidUtils.isNetworkConnected(context)) {
        progress.recordError();
        return SgSyncAdapter.UpdateResult.INCOMPLETE;
    }
    if (!ratingsSync.downloadForMovies(lastActivity.movies.rated_at)) {
        progress.recordError();
        return SgSyncAdapter.UpdateResult.INCOMPLETE;
    }
    return SgSyncAdapter.UpdateResult.SUCCESS;
}
Also used : LastActivities(com.uwetrottmann.trakt5.entities.LastActivities)

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