public async Task <TvShowContainer> GetTvShowAsync(int tvShowId, CancellationToken cancellationToken) { TvShowContainer container = TvShows.FindById(tvShowId); if (container != null) { return(container); } TvShowMethods methods = TvShowMethods.Credits | TvShowMethods.Images | TvShowMethods.Videos | TvShowMethods.Translations | TvShowMethods.Keywords | TvShowMethods.ExternalIds; TvShow tmdbResult = await TMDbClient.GetTvShowAsync(tvShowId, methods, cancellationToken); container = new TvShowContainer(tmdbResult); ImdbHelper.GetImdbInfo(tmdbResult.ExternalIds.ImdbId).ContinueWith(x => { if (x.IsCompleted && !x.IsFaulted && x.Result != null) { container.Votes = x.Result.Resource.RatingCount; container.ImdbRating = x.Result.Resource.Rating; if (x.Result.Resource.OtherRanks?.Length > 0) { container.TopRating = x.Result.Resource.OtherRanks[0].Rank; } } }, TaskScheduler.FromCurrentSynchronizationContext()).LogIfFaulted(); return(container); }
public async Task <List <TvShowContainer> > GetTvShowIMDbTop250ListAsync(string language, CancellationToken cancellationToken) { var tmdbResult = await TMDbClient.GetListAsync(listId : "142134", language : language, cancellationToken : cancellationToken); List <TvShowContainer> result = new List <TvShowContainer>(tmdbResult.ItemCount); for (int i = 0; i < tmdbResult.Items.Count; i++) { if (tmdbResult.Items[i] is SearchTv tvShow) { TvShowContainer container = GetContainer(tvShow); result.Add(container); if (container.TopRating != i + 1) { container.TopRating = i + 1; if (container.IsAdded) { TvShows.Update(container); } } } } return(result); }
private TvShowContainer GetContainer(SearchTv item) { TvShowContainer container = TvShows.FindById(item.Id); if (container == null) { container = new TvShowContainer(item); } return(container); }
public void CreateTvShowContainerView(TvShowContainer container) { if (container == null) { return; } string documentType = "TvShowSingleView"; string documentId = String.Format("{0}:{1}", documentType, container.Id); if (ShowDocument(String.Empty, documentId)) { return; } CreateDocument(() => container.GetName(Settings.Default.Language), documentType, container, documentId); }
public async Task CreateTvShowView(int tvShowId) { string documentType = "TvShowSingleView"; string documentId = String.Format("{0}:{1}", documentType, tvShowId); if (ShowDocument(String.Empty, documentId)) { return; } CancellationTokenSource tokenSource = this.GetAsyncCommand(x => x.CreateTvShowView(tvShowId)).CancellationTokenSource; TvShowContainer container = await RunAsync(() => App.Repository.GetTvShowAsync(tvShowId, tokenSource.Token)); if (container != null) { CreateDocument(() => container.GetName(Settings.Default.Language), documentType, container, documentId); } }
public async Task UpdateTvShowAsync(TvShowContainer container, CancellationToken cancellationToken) { TvShowMethods methods = TvShowMethods.Credits | TvShowMethods.Images | TvShowMethods.Videos | TvShowMethods.Translations | TvShowMethods.Keywords | TvShowMethods.ExternalIds; TvShow tmdbResult = await TMDbClient.GetTvShowAsync(container.Id, methods, cancellationToken); container.Item = tmdbResult; ImdbInfo imdbInfo = await ImdbHelper.GetImdbInfo(tmdbResult.ExternalIds.ImdbId); container.Votes = imdbInfo.Resource.RatingCount; container.ImdbRating = imdbInfo.Resource.Rating; if (imdbInfo.Resource.OtherRanks?.Length > 0) { container.TopRating = imdbInfo.Resource.OtherRanks[0].Rank; } TvShows.Update(container); }
public async Task CreateImportView(MediaType mediaType) { ImportViewModel viewModel = ViewModelSource.Create <ImportViewModel>(); viewModel.ParentViewModel = this; viewModel.MediaType = mediaType; DialogService.ShowDialog(null, Properties.Resources.Import, "ImportView", viewModel); if (viewModel.SelectedMediaFileInfoList != null) { try { BeginProgress(); IAsyncCommand command = this.GetAsyncCommand(x => x.CreateImportView(mediaType)); CancellationToken cancellationToken = command.CancellationTokenSource.Token; BackgroundOperation.Register(Properties.Resources.ImportWizard, command.CancelCommand); List <ContainerBase> newItems = new List <ContainerBase>(); List <ContainerBase> existingItems = new List <ContainerBase>(); if (viewModel.MediaType == MediaType.Movie) { foreach (MediaFileInfo info in viewModel.SelectedMediaFileInfoList) { if (cancellationToken.IsCancellationRequested) { break; } SearchBase selectedItem = info.SelectedMediaItem as SearchBase; if (selectedItem != null) { MovieContainer container = await App.Repository.GetMovieAsync(selectedItem.Id, cancellationToken); if (container != null) { container.Seen = info.PersonalInfo.Seen; container.Favorite = info.PersonalInfo.Favorite; container.Watchlist = info.PersonalInfo.Watchlist; container.LocalPath = info.PersonalInfo.LocalPath; container.PersonalRating = info.PersonalInfo.PersonalRating; if (container.IsAdded == false) { newItems.Add(container); } else { existingItems.Add(container); } } } } foreach (MovieContainer movieContainer in newItems) { App.Repository.Movies.Add(movieContainer); } foreach (MovieContainer movieContainer in existingItems) { App.Repository.Movies.Update(movieContainer); } } else if (viewModel.MediaType == MediaType.Tv) { foreach (MediaFileInfo info in viewModel.SelectedMediaFileInfoList) { if (cancellationToken.IsCancellationRequested) { break; } SearchBase selectedItem = info.SelectedMediaItem as SearchBase; if (selectedItem != null) { TvShowContainer container = await App.Repository.GetTvShowAsync(selectedItem.Id, cancellationToken); if (container != null) { container.Seen = info.PersonalInfo.Seen; container.Favorite = info.PersonalInfo.Favorite; container.Watchlist = info.PersonalInfo.Watchlist; container.LocalPath = info.PersonalInfo.LocalPath; container.PersonalRating = info.PersonalInfo.PersonalRating; if (container.IsAdded == false) { newItems.Add(container); } else { existingItems.Add(container); } } } } foreach (TvShowContainer tvShowContainer in newItems) { App.Repository.TvShows.Add(tvShowContainer); } foreach (TvShowContainer tvShowContainer in existingItems) { App.Repository.TvShows.Update(tvShowContainer); } } else if (viewModel.MediaType == MediaType.Person) { foreach (MediaFileInfo info in viewModel.SelectedMediaFileInfoList) { if (cancellationToken.IsCancellationRequested) { break; } SearchBase selectedItem = info.SelectedMediaItem as SearchBase; if (selectedItem != null) { PersonContainer container = await App.Repository.GetPersonAsync(selectedItem.Id, cancellationToken); if (container != null) { container.Favorite = info.PersonalInfo.Favorite; container.LocalPath = info.PersonalInfo.LocalPath; if (container.IsAdded == false) { newItems.Add(container); } else { existingItems.Add(container); } } } } foreach (PersonContainer personContainer in newItems) { App.Repository.People.Add(personContainer); } foreach (PersonContainer personContainer in existingItems) { App.Repository.People.Update(personContainer); } } } finally { EndProgress(); BackgroundOperation.UnRegister(Properties.Resources.ImportWizard); } } }