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));
        }
Beispiel #2
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 }));
        }