Ejemplo n.º 1
0
        private async Task <List <ShowSql> > RefreshShowHiddenItem(IDatabase database)
        {
            List <ShowSql> res = new List <ShowSql>();
            TraktPagedResponse <ITraktUserHiddenItem> hiddenShow = await Client.Users
                                                                   .GetHiddenItemsAsync(TraktHiddenItemsSection.ProgressCollected, TraktHiddenItemType.Show)
                                                                   .ConfigureAwait(false);

            TraktPagedResponse <ITraktUserHiddenItem> hiddenShowRes = hiddenShow;

            foreach (ITraktUserHiddenItem traktUserHiddenItem in hiddenShowRes)
            {
                ShowSql localShow = GetShow(database, traktUserHiddenItem.Show.Ids.Trakt);

                localShow.Update(traktUserHiddenItem);

                res.Add(localShow);
            }

            return(res);
        }
Ejemplo n.º 2
0
        private async Task RefreshShow(TMDbClient client, ShowSql showSql)
        {
            if (!showSql.Blacklisted && showSql.Providers.ContainsKey(ProviderSql.Tmdb) && !string.IsNullOrEmpty(showSql.Providers[ProviderSql.Tmdb]) && int.TryParse(showSql.Providers[ProviderSql.Tmdb], out var showId))
            {
                bool first = true;

                // Refresh episodes
                foreach (var seasonSql in showSql.Seasons.Where(s => !s.Blacklisted))
                {
                    foreach (var episodeSql in seasonSql.Episodes)
                    {
                        if (string.IsNullOrEmpty(episodeSql.PosterUrl) && episodeSql.Status == EpisodeStatusSql.Missing)
                        {
                            if (first)
                            {
                                first = false;
                            }
                            else
                            {
                                await Task.Delay(1000);
                            }


                            await RefreshEpisode(client, episodeSql, showId);
                        }
                    }
                }

                // Missing show infos
                if (string.IsNullOrEmpty(showSql.PosterUrl))
                {
                    TvShow tvShow = await client.GetTvShowAsync(showId, TvShowMethods.ExternalIds, "fr-FR").ConfigureAwait(false);

                    showSql.Update(client.Config, tvShow);
                }
            }
        }
Ejemplo n.º 3
0
        public bool RefreshMissingEpisodes(IDatabase database)
        {
            SetupClient(database);

            RefreshHiddenItem(database);

            // Set all missing to unknown
            database.ClearMissingEpisodes();

            Task <TraktListResponse <ITraktCollectionShow> > collected = Client.Users.GetCollectionShowsAsync("me", new TraktExtendedInfo {
                Full = true
            });
            Task <TraktListResponse <ITraktWatchedShow> > watched = Client.Users.GetWatchedShowsAsync("me", new TraktExtendedInfo {
                Full = true
            });

            List <TraktShow> shows = new List <TraktShow>();

            watched.Wait();
            TraktListResponse <ITraktWatchedShow> watchedRes = watched.Result;

            foreach (ITraktWatchedShow traktWatchedShow in watchedRes)
            {
                int watchedEpisodes = traktWatchedShow.WatchedSeasons.Where(s => s.Number != 0).Sum(season => season.Episodes.Count());

                TraktShow show = new TraktShow
                {
                    Id        = traktWatchedShow.Ids.Trakt,
                    Year      = traktWatchedShow.Year,
                    SerieName = traktWatchedShow.Title,
                    Watched   = watchedEpisodes >= traktWatchedShow.AiredEpisodes,
                    Status    = traktWatchedShow.Status,
                    Imdb      = traktWatchedShow.Ids.Imdb,
                    Tmdb      = traktWatchedShow.Ids.Tmdb,
                };

                foreach (ITraktWatchedShowSeason season in traktWatchedShow.WatchedSeasons)
                {
                    TraktSeason traktSeason = new TraktSeason {
                        Season = season.Number.Value
                    };

                    foreach (ITraktWatchedShowEpisode episode in season.Episodes)
                    {
                        traktSeason.MissingEpisodes.Add(new TraktEpisode {
                            Episode = episode.Number.Value, Watched = true
                        });
                    }

                    show.Seasons.Add(traktSeason);
                }

                shows.Add(show);
            }

            collected.Wait();
            TraktListResponse <ITraktCollectionShow> collectedRes = collected.Result;

            foreach (ITraktCollectionShow traktCollectionShow in collectedRes)
            {
                TraktShow show = shows.SingleOrDefault(s => s.Id == traktCollectionShow.Ids.Trakt);
                if (show == null)
                {
                    show = new TraktShow
                    {
                        Id        = traktCollectionShow.Ids.Trakt,
                        Year      = traktCollectionShow.Year,
                        SerieName = traktCollectionShow.Title,
                        Status    = traktCollectionShow.Status,
                        Imdb      = traktCollectionShow.Ids.Imdb,
                        Tmdb      = traktCollectionShow.Ids.Tmdb,
                    };

                    shows.Add(show);
                }

                foreach (ITraktCollectionShowSeason season in traktCollectionShow.CollectionSeasons)
                {
                    TraktSeason misSeason = show.Seasons.SingleOrDefault(e => e.Season == season.Number);
                    if (misSeason == null)
                    {
                        misSeason = new TraktSeason {
                            Season = season.Number.Value
                        };
                        show.Seasons.Add(misSeason);
                    }

                    foreach (ITraktCollectionShowEpisode episode in season.Episodes)
                    {
                        TraktEpisode misEpisode = misSeason.MissingEpisodes.SingleOrDefault(e => e.Episode == episode.Number);
                        if (misEpisode != null)
                        {
                            misEpisode.Collected = true;
                        }
                        else
                        {
                            misSeason.MissingEpisodes.Add(new TraktEpisode {
                                Episode = episode.Number.Value, Collected = true
                            });
                        }
                    }
                }
            }

            shows.RemoveAll(s => s.Watched);

            // PrepareDB
            List <ShowSql> bddShows    = database.GetShows();
            List <ShowSql> updateShows = new List <ShowSql>();

            // Remove Show blacklist
            shows.RemoveAll(s => bddShows.Any(b => b.Id == s.Id && b.Blacklisted));
            List <Task> tasks = new List <Task>();

            foreach (TraktShow traktShow in shows)
            {
                ShowSql localShow = GetShow(database, traktShow.Id);
                localShow.Update(traktShow);
                updateShows.Add(localShow);
                tasks.Add(HandleProgress(traktShow, localShow));
            }

            Task.WaitAll(tasks.ToArray());

            database.AddOrUpdateShows(updateShows);

            database.ClearUnknownEpisodes();

            shows.RemoveAll(s => !s.Seasons.Any());



            return(true);
        }