public Actor(BaseItemPerson a) { this.Name = a.Name; this.Role = a.Role ?? (a.Type == PersonType.GuestStar ? "Guest Star" : ""); this.PersonId = new Guid(a.Id); this.PrimaryImageTag = a.HasPrimaryImage ? a.PrimaryImageTag : null; }
/// <summary> /// Attaches People DTO's to a DTOBaseItem /// </summary> /// <param name="dto">The dto.</param> /// <param name="item">The item.</param> /// <returns>Task.</returns> private async Task AttachPeople(BaseItemDto dto, BaseItem item) { // Ordering by person type to ensure actors and artists are at the front. // This is taking advantage of the fact that they both begin with A // This should be improved in the future var people = item.People.OrderBy(i => i.Type).ToList(); // Attach People by transforming them into BaseItemPerson (DTO) dto.People = new BaseItemPerson[people.Count]; var entities = await Task.WhenAll(people.Select(p => p.Name) .Distinct(StringComparer.OrdinalIgnoreCase).Select(c => Task.Run(async() => { try { return(await _libraryManager.GetPerson(c).ConfigureAwait(false)); } catch (IOException ex) { _logger.ErrorException("Error getting person {0}", ex, c); return(null); } }) )).ConfigureAwait(false); var dictionary = entities.Where(i => i != null) .DistinctBy(i => i.Name) .ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase); for (var i = 0; i < people.Count; i++) { var person = people[i]; var baseItemPerson = new BaseItemPerson { Name = person.Name, Role = person.Role, Type = person.Type }; Person entity; if (dictionary.TryGetValue(person.Name, out entity)) { var primaryImagePath = entity.PrimaryImagePath; if (!string.IsNullOrEmpty(primaryImagePath)) { baseItemPerson.PrimaryImageTag = GetImageCacheTag(entity, ImageType.Primary, primaryImagePath); } } dto.People[i] = baseItemPerson; } }
public MediaInfo() { Chapters = new ChapterInfo[] { }; Artists = Array.Empty <string>(); AlbumArtists = EmptyStringArray; Studios = Array.Empty <string>(); Genres = Array.Empty <string>(); People = new BaseItemPerson[] { }; ProviderIds = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); }
/// <summary> /// Attaches People DTO's to a DTOBaseItem /// </summary> /// <param name="dto">The dto.</param> /// <param name="item">The item.</param> /// <param name="libraryManager">The library manager.</param> /// <returns>Task.</returns> private async Task AttachPeople(BaseItemDto dto, BaseItem item) { if (item.People == null) { return; } // Attach People by transforming them into BaseItemPerson (DTO) dto.People = new BaseItemPerson[item.People.Count]; var entities = await Task.WhenAll(item.People.Select(c => Task.Run(async() => { try { return(await _libraryManager.GetPerson(c.Name).ConfigureAwait(false)); } catch (IOException ex) { _logger.ErrorException("Error getting person {0}", ex, c.Name); return(null); } }) )).ConfigureAwait(false); for (var i = 0; i < item.People.Count; i++) { var person = item.People[i]; var baseItemPerson = new BaseItemPerson { Name = person.Name, Role = person.Role, Type = person.Type }; var ibnObject = entities[i]; if (ibnObject != null) { var primaryImagePath = ibnObject.PrimaryImagePath; if (!string.IsNullOrEmpty(primaryImagePath)) { baseItemPerson.PrimaryImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(ibnObject, ImageType.Primary, primaryImagePath); } } dto.People[i] = baseItemPerson; } }
/// <summary> /// Attaches People DTO's to a DTOBaseItem /// </summary> /// <param name="dto">The dto.</param> /// <param name="item">The item.</param> /// <returns>Task.</returns> private void AttachPeople(BaseItemDto dto, BaseItem item) { // Ordering by person type to ensure actors and artists are at the front. // This is taking advantage of the fact that they both begin with A // This should be improved in the future var people = item.People.OrderBy(i => i.SortOrder ?? int.MaxValue).ThenBy(i => i.Type).ToList(); // Attach People by transforming them into BaseItemPerson (DTO) dto.People = new BaseItemPerson[people.Count]; var dictionary = people.Select(p => p.Name) .Distinct(StringComparer.OrdinalIgnoreCase).Select(c => { try { return(_libraryManager.GetPerson(c)); } catch (IOException ex) { _logger.ErrorException("Error getting person {0}", ex, c); return(null); } }).Where(i => i != null) .DistinctBy(i => i.Name) .ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase); for (var i = 0; i < people.Count; i++) { var person = people[i]; var baseItemPerson = new BaseItemPerson { Name = person.Name, Role = person.Role, Type = person.Type }; Person entity; if (dictionary.TryGetValue(person.Name, out entity)) { baseItemPerson.PrimaryImageTag = GetImageCacheTag(entity, ImageType.Primary); baseItemPerson.Id = entity.Id.ToString("N"); } dto.People[i] = baseItemPerson; } }
/// <summary> /// Gets the person image URL. /// </summary> /// <param name="item">The item.</param> /// <param name="options">The options.</param> /// <returns>System.String.</returns> /// <exception cref="System.ArgumentNullException">item</exception> public string GetPersonImageUrl(BaseItemPerson item, ImageOptions options) { if (item == null) { throw new ArgumentNullException("item"); } if (options == null) { throw new ArgumentNullException("options"); } options.Tag = item.PrimaryImageTag; return(GetImageUrl(item.Id, options)); }
/// <summary> /// Initializes a new instance of the ActorViewModel class. /// </summary> public ActorViewModel(IExtendedApiClient apiClient, INavigationService navigationService) { _apiClient = apiClient; _navigationService = navigationService; if (IsInDesignMode) { SelectedPerson = new BaseItemPerson { Name = "Jeff Goldblum" }; var list = new List <BaseItemDto> { new BaseItemDto { Id = "6536a66e10417d69105bae71d41a6e6f", Name = "Jurassic Park", SortName = "Jurassic Park", Overview = "Lots of dinosaurs eating people!", People = new[] { new BaseItemPerson { Name = "Steven Spielberg", Type = "Director" }, new BaseItemPerson { Name = "Sam Neill", Type = "Actor" }, new BaseItemPerson { Name = "Richard Attenborough", Type = "Actor" }, new BaseItemPerson { Name = "Laura Dern", Type = "Actor" } } } }; Films = Utils.GroupItemsByName(list).Result; } }
/// <summary> /// Attaches People DTO's to a DTOBaseItem /// </summary> /// <param name="dto">The dto.</param> /// <param name="item">The item.</param> /// <returns>Task.</returns> private void AttachPeople(BaseItemDto dto, BaseItem item) { // Ordering by person type to ensure actors and artists are at the front. // This is taking advantage of the fact that they both begin with A // This should be improved in the future var people = _libraryManager.GetPeople(item).OrderBy(i => i.SortOrder ?? int.MaxValue) .ThenBy(i => { if (i.IsType(PersonType.Actor)) { return(0); } if (i.IsType(PersonType.GuestStar)) { return(1); } if (i.IsType(PersonType.Director)) { return(2); } if (i.IsType(PersonType.Writer)) { return(3); } if (i.IsType(PersonType.Producer)) { return(4); } if (i.IsType(PersonType.Composer)) { return(4); } return(10); }) .ToList(); var list = new List <BaseItemPerson>(); var dictionary = people.Select(p => p.Name) .Distinct(StringComparer.OrdinalIgnoreCase).Select(c => { try { return(_libraryManager.GetPerson(c)); } catch (Exception ex) { _logger.LogError(ex, "Error getting person {Name}", c); return(null); } }).Where(i => i != null) .GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase) .Select(x => x.First()) .ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase); for (var i = 0; i < people.Count; i++) { var person = people[i]; var baseItemPerson = new BaseItemPerson { Name = person.Name, Role = person.Role, Type = person.Type }; if (dictionary.TryGetValue(person.Name, out Person entity)) { baseItemPerson.PrimaryImageTag = GetImageCacheTag(entity, ImageType.Primary); baseItemPerson.Id = entity.Id.ToString("N"); list.Add(baseItemPerson); } } dto.People = list.ToArray(); }
public void NavigateTo(BaseItemDto item) { App.SelectedItem = item; var type = item.Type.ToLower(); if (type.Contains("collectionfolder")) { type = "collectionfolder"; } if (type.StartsWith("genre")) { type = "genre"; } switch (type) { case "collectionfolder": case "genre": case "trailercollectionfolder": case "playlistsfolder": if (App.SpecificSettings.UseLibraryFolders) { HandleCollectionNavigation(item); } else { if (App.SpecificSettings.JustShowFolderView) { NavigateTo(Constants.Pages.FolderView + item.Id); } else { NavigateTo(Constants.Pages.CollectionView); } } break; case "userview": HandleCollectionNavigation(item); break; case "photoalbum": case "folder": case "boxset": NavigateTo(Constants.Pages.FolderView + item.Id); break; case "movie": NavigateTo(Constants.Pages.MovieView); break; case "series": NavigateTo(Constants.Pages.TvShowView); break; case "season": NavigateTo(Constants.Pages.SeasonView); break; case "episode": NavigateTo(Constants.Pages.EpisodeView); break; case "trailer": if (SimpleIoc.Default.GetInstance <TrailerViewModel>() != null) { Messenger.Default.Send(new NotificationMessage(Constants.Messages.ChangeTrailerMsg)); NavigateTo(Constants.Pages.TrailerView); } break; case "musicartist": case "artist": if (SimpleIoc.Default.GetInstance <MusicViewModel>() != null) { Messenger.Default.Send(new NotificationMessage(item, Constants.Messages.MusicArtistChangedMsg)); NavigateTo(Constants.Pages.ArtistView); } break; case "musicalbum": if (SimpleIoc.Default.GetInstance <MusicViewModel>() != null) { Messenger.Default.Send(new NotificationMessage(item, Constants.Messages.MusicAlbumChangedMsg)); NavigateTo(Constants.Pages.AlbumView); } break; case "channel": case "channelfolderitem": NavigateTo(Constants.Pages.Channels.ChannelView + item.Id); break; case "playlist": if (SimpleIoc.Default.GetInstance <ServerPlaylistsViewModel>() != null) { Messenger.Default.Send(new NotificationMessage(item, Constants.Messages.ServerPlaylistChangedMsg)); NavigateTo(Constants.Pages.Playlists.PlaylistView); } break; case "person": var actor = new BaseItemPerson { Name = item.Name, Id = item.Id, PrimaryImageTag = item.HasPrimaryImage ? item.ImageTags.FirstOrDefault(x => x.Key == ImageType.Primary).Value : string.Empty }; App.SelectedItem = actor; NavigateTo(Constants.Pages.ActorView); break; default: if (SimpleIoc.Default.GetInstance <GenericItemViewModel>() != null) { Messenger.Default.Send(new NotificationMessage(item, Constants.Messages.GenericItemChangedMsg)); NavigateTo(Constants.Pages.GenericItemView); } break; } }
public ItemPersonViewModel(BaseItemPerson person, IApiClient apiClient, IImageManager imageManager) { _person = person; _apiClient = apiClient; _imageManager = imageManager; }