Пример #1
0
        public async Task <IActionResult> Overview(Guid identifier)
        {
            var viewedItems = await _netflixViewedItemRepository.GetByGuidAsync(identifier);

            if (!viewedItems?.Any() ?? true)
            {
                return(RedirectToAction("NoResults"));
            }

            var playbacks =
                NetflixViewingHistoryLoader.GetNetflixPlaybacksFromViewingActivity(
                    _mapper.Map <List <NetflixViewedItem> >(viewedItems));

            var viewModel = _netflixStatsCreator.GetNetflixStatsViewModel(playbacks);

            viewModel.Identifier = identifier;

            var queryResult = await _queryResultRepository.GetByGuidWithoutViewedItemsAsync(identifier);

            viewModel.ResultsAreKept           = queryResult.KeepResults;
            viewModel.IsPublishedToLeaderboard = queryResult.IsPublishedToLeaderboard;
            viewModel.QueryDateTime            = queryResult.QueryDateTime;
            viewModel.ForProfile = queryResult.ForProfile;

            return(View("Index", viewModel));
        }
Пример #2
0
        public async Task <ActionResult <IEnumerable <NetflixViewedItem> > > GetViewingHistory(string cookies)
        {
            var cookieContainer    = new CookieContainer();
            var httpMessageHandler = new HttpClientHandler {
                CookieContainer = cookieContainer
            };

            foreach (var cookieString in cookies.RemoveWhitespaces().Split(';'))
            {
                var splittedCookie = cookieString.Split('=');
                var cookie         = new Cookie
                {
                    Name    = splittedCookie[0],
                    Value   = splittedCookie[1],
                    Path    = "/",
                    Expires = DateTime.Now.AddDays(1),
                    Domain  = ".netflix.com"
                };
                cookieContainer.Add(cookie);
            }

            var historyLoader = new NetflixViewingHistoryLoader(httpMessageHandler);
            var viewedItems   = (await historyLoader.LoadNetflixViewedItemsAsync()).ToList();

            return(Ok(viewedItems));
        }
Пример #3
0
        public async Task <IActionResult> GetPlaybacksForIdentifierOnDate(Guid identifier, DateTime forDate)
        {
            var viewedItems = await _netflixViewedItemRepository.GetByGuidForDayAsync(identifier, forDate);

            var playbacks =
                NetflixViewingHistoryLoader.GetNetflixPlaybacksFromViewingActivity(
                    _mapper.Map <List <NetflixViewedItem> >(viewedItems));

            return(PartialView("Partials/_PlaybacksPartial", _netflixStatsCreator.GetNetflixPlaybacksViewModel(playbacks)));
        }
Пример #4
0
        public async Task <IActionResult> Load(NetflixAccountInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("../Home/Index", model));
            }

            var historyLoader = new NetflixViewingHistoryLoader(new NetflixProfile
            {
                AccountEmail    = model.NetflixEmail,
                AccountPassword = model.NetflixPassword,
                ProfileName     = model.NetflixProfileName
            });

            List <NetflixViewedItem> viewedItems;

            try
            {
                viewedItems = (await historyLoader.LoadNetflixViewedItemsAsync()).ToList();
            }
            catch (NetflixProfileNotFoundException e)
            {
                ModelState.AddModelError("NetflixProfileNotFoundException", e.Message);
                return(View("../Home/Index", model));
            }
            catch (NetflixLoginException e)
            {
                ModelState.AddModelError("NetflixLoginException", $"There was a problem while login in to your Netflix account: {e.Message}");
                return(View("../Home/Index", model));
            }

            var mappedItems = _mapper.Map <List <Models.EntityFrameworkModels.NetflixViewedItem> >(viewedItems);

            var identificationGuid = await _netflixViewedItemRepository.CreateManyWithGuidAsync(mappedItems, model.NetflixProfileName);

            return(RedirectToAction("Overview", "Stats", new { id = identificationGuid }));
        }