public ActionResult NextEpisode() { var episodes = episodeService.GetEpisodes(); TvShowViewModel model = converter.Convert(episodes); return(View(model)); }
public async Task <IActionResult> Find(string search, string pageNum = "1") { var tvshowVM = new TvShowViewModel { TvShows = new List <TvShow>(), // need to initialize List first Searched_Word = search, Current_Page = Int32.Parse(pageNum) }; if (String.IsNullOrEmpty(search)) { return(View(tvshowVM)); } var client = _clientFactory.CreateClient(); var responseTask = client.GetAsync($"https://api.themoviedb.org/3/search/tv?api_key={api_key}&query=" + search + "&page=" + pageNum); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var objects = JObject.Parse(result.Content.ReadAsStringAsync().Result); var results = (JArray)objects["results"]; int numberOfResults = results.Count; tvshowVM.Total_Pages = (int)objects["total_pages"]; for (int i = 0; i < numberOfResults; i++) { DateTime nextEpisode = new DateTime(); string tv_id = (string)results[i]["id"]; responseTask = client.GetAsync($"https://api.themoviedb.org/3/tv/{tv_id}?api_key={api_key}"); responseTask.Wait(); result = responseTask.Result; objects = JObject.Parse(result.Content.ReadAsStringAsync().Result); string next_episode_date = objects["next_episode_to_air"].ToString(); if (!String.IsNullOrEmpty(next_episode_date)) { nextEpisode = (DateTime)objects["next_episode_to_air"]["air_date"]; } TvShow tv = new TvShow { Id = (int)results[i]["id"], Title = (string)results[i]["name"], Details = (string)results[i]["overview"], Next_Episode_Date = nextEpisode, Poster_Path = $"https://image.tmdb.org/t/p/original/{(string)results[i]["poster_path"]}" }; tvshowVM.TvShows.Add(tv); } return(View(tvshowVM)); } return(View(tvshowVM)); }
public async Task <IActionResult> TvShows(string order = null) { var model = new TvShowViewModel { Order = order, files = analysisService.FindVideo(ShowSearchLocation) }; model.files = readService.ExtractMetaInfoFromMediaTitle(model.files).SuccessFiles; if (string.IsNullOrEmpty(order)) { model.files = model.files.Where(x => x.MediaInformation.IsMovie == false && x.MediaInformation.IsPersonal == false).OrderBy(x => x.MediaInformation.Name).ToList(); List <string> searchedFiles = new List <string>(); foreach (var f in model.files) { var matchName = searchedFiles.FirstOrDefault(x => x.Equals(f.MediaInformation.Name)); if (string.IsNullOrEmpty(matchName)) { searchedFiles.Add(f.MediaInformation.Name); var cacheResult = await tvdbService.GetFileCachedInfo(f); if (cacheResult != null) { f.FileImageUrl = cacheResult.SiteRelativeImageUrl; } else { f.FileImageUrl = DefaultImaageUrl; } } else { f.FileImageUrl = model.files.FirstOrDefault(x => x.MediaInformation.Name.Equals(f.MediaInformation.Name)).FileImageUrl; } } } else if (order.Equals("CreatedDesc", StringComparison.OrdinalIgnoreCase)) { model.files = model.files .Where(x => x.MediaInformation.IsMovie == false && x.MediaInformation.IsPersonal == false) .OrderByDescending(x => x.FileInfo.CreationTime).ToList(); } return(View(model)); }
public TvShowViewModelTests() { _viewModelFactory = Substitute.For<ITvShowViewModelFactory>(); _tvShowFileService = Substitute.For<ITvShowFileService>(); _metadataService = Substitute.For<ITvShowMetadataService>(); _busyProvider = Substitute.For<IBusyProvider>(); _keyDataStore = Substitute.For<IKeyDataStore>(); _path = @"C:\Folder\TV Shows\Game of Thrones"; _viewModelFactory = Substitute.For<ITvShowViewModelFactory>(); IActorManagerViewModel actorManager = Substitute.For<IActorManagerViewModel>(); actorManager.Actors .Returns(new ObservableCollection<IActorViewModel>()); _viewModelFactory.GetActorManager(_path, Arg.Any<Action>()) .Returns(actorManager); _viewModel = new TvShowViewModel(_viewModelFactory, _tvShowFileService, _metadataService, _busyProvider, null, null, _keyDataStore, _path); }
public async Task Refresh_Always_RefreshesImages() { // Arrange _metadataService.Get(_path) .Returns(new TvShowMetadata().ToTask()); ITvShowImagesViewModel imagesViewModel = Substitute.For<ITvShowImagesViewModel>(); _viewModelFactory.GetTvShowImages(Arg.Any<ITvShowViewModel>(), _path) .Returns(imagesViewModel); // Recreate the ViewModel as the ImagesViewModel is retrieved in the constructor _viewModel = new TvShowViewModel(_viewModelFactory, _tvShowFileService, _metadataService, _busyProvider, null, null, _keyDataStore, _path); // Act await _viewModel.Refresh(); // Assert imagesViewModel.Received() .Refresh().Async(); }