コード例 #1
0
        public async Task Test_TraktCalendarModule_GetUserShows_With_Days()
        {
            TraktClient client = TestUtility.GetOAuthMockClient($"{GET_USER_SHOWS_URI}/{TODAY.ToTraktDateString()}/{DAYS}",
                                                                CALENDAR_ALL_SHOWS_JSON,
                                                                startDate: START_DATE, endDate: END_DATE);

            TraktListResponse <ITraktCalendarShow> response = await client.Calendar.GetUserShowsAsync(null, DAYS);

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.HasValue.Should().BeTrue();
            response.Value.Should().NotBeNull().And.HaveCount(2);
            response.StartDate.Should().HaveValue();
            response.StartDate.Equals(StartDateTime).Should().BeTrue();
            response.EndDate.Should().HaveValue();
            response.EndDate.Equals(EndDateTime).Should().BeTrue();
        }
        public async Task Test_TraktCalendarModule_GetUserSeasonPremieres_Filtered()
        {
            TraktClient client = TestUtility.GetOAuthMockClient($"{GET_USER_SEASON_PREMIERES_URI}?{FILTER}",
                                                                CALENDAR_ALL_SHOWS_JSON,
                                                                startDate: START_DATE, endDate: END_DATE);

            TraktListResponse <ITraktCalendarShow> response = await client.Calendar.GetUserSeasonPremieresAsync(null, null, null, FILTER);

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.HasValue.Should().BeTrue();
            response.Value.Should().NotBeNull().And.HaveCount(2);
            response.StartDate.Should().HaveValue();
            response.StartDate.Equals(StartDateTime).Should().BeTrue();
            response.EndDate.Should().HaveValue();
            response.EndDate.Equals(EndDateTime).Should().BeTrue();
        }
コード例 #3
0
        public async Task Test_TraktCalendarModule_GetUserShows_With_ExtendedInfo_And_StartDate_Filtered()
        {
            TraktClient client = TestUtility.GetOAuthMockClient($"{GET_USER_SHOWS_URI}/{TODAY.ToTraktDateString()}?extended={EXTENDED_INFO}&{FILTER}",
                                                                CALENDAR_ALL_SHOWS_JSON,
                                                                startDate: START_DATE, endDate: END_DATE);

            TraktListResponse <ITraktCalendarShow> response = await client.Calendar.GetUserShowsAsync(TODAY, null, EXTENDED_INFO, FILTER);

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.HasValue.Should().BeTrue();
            response.Value.Should().NotBeNull().And.HaveCount(2);
            response.StartDate.Should().HaveValue();
            response.StartDate.Equals(StartDateTime).Should().BeTrue();
            response.EndDate.Should().HaveValue();
            response.EndDate.Equals(EndDateTime).Should().BeTrue();
        }
        public async Task Test_TraktCalendarModule_GetUserNewShows()
        {
            TraktClient client = TestUtility.GetOAuthMockClient(GET_USER_NEW_SHOWS_URI,
                                                                CALENDAR_ALL_SHOWS_JSON,
                                                                startDate: START_DATE, endDate: END_DATE);

            TraktListResponse <ITraktCalendarShow> response = await client.Calendar.GetUserNewShowsAsync();

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.HasValue.Should().BeTrue();
            response.Value.Should().NotBeNull().And.HaveCount(2);
            response.StartDate.Should().HaveValue();
            response.StartDate.Equals(StartDateTime).Should().BeTrue();
            response.EndDate.Should().HaveValue();
            response.EndDate.Equals(EndDateTime).Should().BeTrue();
        }
        public async Task Test_TraktCalendarModule_GetAllSeasonPremieres_With_StartDate()
        {
            TraktClient client = TestUtility.GetMockClient($"{GET_ALL_SEASON_PREMIERES_URI}/{TODAY.ToTraktDateString()}",
                                                           CALENDAR_ALL_SHOWS_JSON,
                                                           startDate: START_DATE, endDate: END_DATE);

            TraktListResponse <ITraktCalendarShow> response = await client.Calendar.GetAllSeasonPremieresAsync(TODAY);

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.HasValue.Should().BeTrue();
            response.Value.Should().NotBeNull().And.HaveCount(2);
            response.StartDate.Should().HaveValue();
            response.StartDate.Equals(StartDateTime).Should().BeTrue();
            response.EndDate.Should().HaveValue();
            response.EndDate.Equals(EndDateTime).Should().BeTrue();
        }
コード例 #6
0
        public async Task Test_TraktUsersModule_GetRatings_Complete()
        {
            var ratingsFilter = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            TraktClient client = TestUtility.GetMockClient(
                $"{GET_RATINGS_URI}/{RATINGS_ITEM_TYPE.UriName}" +
                $"/{BuildRatingsFilterString(ratingsFilter)}?extended={EXTENDED_INFO}",
                RATINGS_JSON);

            TraktListResponse <ITraktRatingsItem> response =
                await client.Users.GetRatingsAsync(USERNAME, RATINGS_ITEM_TYPE, ratingsFilter, EXTENDED_INFO);

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.HasValue.Should().BeTrue();
            response.Value.Should().NotBeNull().And.HaveCount(4);
        }
        public async Task Test_TraktCalendarModule_GetAllMovies_With_StartDate_Filtered()
        {
            TraktClient client = TestUtility.GetMockClient($"{GET_ALL_MOVIES_URI}/{TODAY.ToTraktDateString()}?{FILTER}",
                                                           CALENDAR_ALL_MOVIES_JSON,
                                                           startDate: START_DATE, endDate: END_DATE);

            TraktListResponse <ITraktCalendarMovie> response = await client.Calendar.GetAllMoviesAsync(TODAY, null, null, FILTER);

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.HasValue.Should().BeTrue();
            response.Value.Should().NotBeNull().And.HaveCount(3);
            response.StartDate.Should().HaveValue();
            response.StartDate.Equals(StartDateTime).Should().BeTrue();
            response.EndDate.Should().HaveValue();
            response.EndDate.Equals(EndDateTime).Should().BeTrue();
        }
        public async Task Test_TraktCalendarModule_GetAllMovies_With_ExtendedInfo_And_StartDate_And_Days()
        {
            TraktClient client = TestUtility.GetMockClient($"{GET_ALL_MOVIES_URI}/{TODAY.ToTraktDateString()}/{DAYS}?extended={EXTENDED_INFO}",
                                                           CALENDAR_ALL_MOVIES_JSON,
                                                           startDate: START_DATE, endDate: END_DATE);

            TraktListResponse <ITraktCalendarMovie> response = await client.Calendar.GetAllMoviesAsync(TODAY, DAYS, EXTENDED_INFO);

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.HasValue.Should().BeTrue();
            response.Value.Should().NotBeNull().And.HaveCount(3);
            response.StartDate.Should().HaveValue();
            response.StartDate.Equals(StartDateTime).Should().BeTrue();
            response.EndDate.Should().HaveValue();
            response.EndDate.Equals(EndDateTime).Should().BeTrue();
        }
        public async Task Test_TraktCalendarModule_GetAllMovies()
        {
            TraktClient client = TestUtility.GetMockClient(GET_ALL_MOVIES_URI,
                                                           CALENDAR_ALL_MOVIES_JSON,
                                                           startDate: START_DATE, endDate: END_DATE);

            TraktListResponse <ITraktCalendarMovie> response = await client.Calendar.GetAllMoviesAsync();

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.HasValue.Should().BeTrue();
            response.Value.Should().NotBeNull().And.HaveCount(3);
            response.StartDate.Should().HaveValue();
            response.StartDate.Equals(StartDateTime).Should().BeTrue();
            response.EndDate.Should().HaveValue();
            response.EndDate.Equals(EndDateTime).Should().BeTrue();
        }
        public async Task Test_TraktCalendarModule_GetAllDVDMovies_With_ExtendedInfo_Filtered()
        {
            TraktClient client = TestUtility.GetMockClient($"{GET_ALL_DVD_MOVIES_URI}?extended={EXTENDED_INFO}&{FILTER}",
                                                           CALENDAR_DVD_MOVIES_JSON,
                                                           startDate: START_DATE, endDate: END_DATE);

            TraktListResponse <ITraktCalendarMovie> response = await client.Calendar.GetAllDVDMoviesAsync(null, null, EXTENDED_INFO, FILTER);

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.HasValue.Should().BeTrue();
            response.Value.Should().NotBeNull().And.HaveCount(3);
            response.StartDate.Should().HaveValue();
            response.StartDate.Equals(StartDateTime).Should().BeTrue();
            response.EndDate.Should().HaveValue();
            response.EndDate.Equals(EndDateTime).Should().BeTrue();
        }
コード例 #11
0
        public async Task Test_TraktCalendarModule_GetAllNewShows_With_ExtendedInfo()
        {
            TraktClient client = TestUtility.GetMockClient($"{GET_ALL_NEW_SHOWS_URI}?extended={EXTENDED_INFO}",
                                                           CALENDAR_ALL_SHOWS_JSON,
                                                           startDate: START_DATE, endDate: END_DATE);

            TraktListResponse <ITraktCalendarShow> response = await client.Calendar.GetAllNewShowsAsync(null, null, EXTENDED_INFO);

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.HasValue.Should().BeTrue();
            response.Value.Should().NotBeNull().And.HaveCount(2);
            response.StartDate.Should().HaveValue();
            response.StartDate.Equals(StartDateTime).Should().BeTrue();
            response.EndDate.Should().HaveValue();
            response.EndDate.Equals(EndDateTime).Should().BeTrue();
        }
コード例 #12
0
        public async Task Test_TraktNetworksModule_GetNetworks()
        {
            TraktClient client = TestUtility.GetMockClient(GET_NETWORKS_URI, GET_NETWORKS_JSON);
            TraktListResponse <ITraktNetwork> response = await client.Networks.GetNetworksAsync();

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.Value.Should().NotBeNull();
            response.HasValue.Should().BeTrue();
            response.Exception.Should().BeNull();
            response.Value.Should().NotBeEmpty().And.HaveCount(2);

            ITraktNetwork[] networks = response.ToArray();

            networks[0].Should().NotBeNull();
            networks[0].Network.Should().Be("ABC(US)");

            networks[1].Should().NotBeNull();
            networks[1].Network.Should().Be("The CW");
        }
コード例 #13
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);
        }
コード例 #14
0
ファイル: TraktApi.cs プロジェクト: PoppyPop/Docker.AutoDl
        public List <Show> GetMissingEpisodes()
        {
            RefreshHiddenItem().Wait();

            var collected = Client.Users.GetCollectionShowsAsync("me", new TraktExtendedInfo {
                Full = true
            });
            var 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.Sum(season => season.Episodes.Count());

                var show = new TraktShow
                {
                    Id        = traktWatchedShow.Ids.Trakt,
                    Year      = traktWatchedShow.Year,
                    SerieName = traktWatchedShow.Title,
                    Watched   = watchedEpisodes >= traktWatchedShow.AiredEpisodes,
                    Status    = traktWatchedShow.Status,
                    Providers = new Dictionary <string, string>
                    {
                        { "Imdb", traktWatchedShow.Ids.Imdb },
                        { "Tmdb", traktWatchedShow.Ids.Tmdb.ToString() }
                    }
                };

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

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

                    show.Seasons.Add(traktSeason);
                }

                shows.Add(show);
            }

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

            foreach (ITraktCollectionShow traktCollectionShow in collectedRes)
            {
                var 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,
                        Providers = new Dictionary <string, string>
                        {
                            { "Imdb", traktCollectionShow.Ids.Imdb },
                            { "Tmdb", traktCollectionShow.Ids.Tmdb.ToString() }
                        }
                    };

                    shows.Add(show);
                }

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

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

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

            // Prepare blacklist
            List <BlackListShow> blackList = Database.BlackLists;

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

            foreach (TraktShow traktShow in shows)
            {
                tasks.Add(HandleProgress(traktShow, blackList));
            }

            Task.WaitAll(tasks.ToArray());

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

            return(shows.Select(s => (Show)s).ToList());
        }