public BaseItem GetItem(BaseItemDto mb3Item, string itemType) { var item = InstantiateItem(itemType, mb3Item); if (item != null) { item.Name = mb3Item.Name; //Logger.ReportVerbose("Item {0} is {1}", item.Name, item.GetType().Name); item.Path = mb3Item.Path; item.DateCreated = (mb3Item.DateCreated ?? DateTime.MinValue).ToLocalTime(); item.DisplayMediaType = mb3Item.DisplayMediaType; item.Overview = mb3Item.Overview; item.SortName = mb3Item.SortName; item.TagLine = mb3Item.Taglines != null && mb3Item.Taglines.Count > 0 ? mb3Item.Taglines[0] : null; item.UserData = mb3Item.UserData; item.PremierDate = mb3Item.PremiereDate ?? DateTime.MinValue; item.FirstAired = mb3Item.PremiereDate != null?mb3Item.PremiereDate.Value.ToLocalTime().ToString("ddd d MMM, yyyy") : null; item.EndDate = mb3Item.EndDate ?? DateTime.MinValue; item.ProductionYear = mb3Item.ProductionYear ?? item.PremierDate.Year; item.ProductionLocations = mb3Item.ProductionLocations; //Logger.ReportInfo("*********** Premier Date for {0} is {1}",item.Name,item.PremierDate); item.ApiParentId = mb3Item.ParentId; //if (item.ApiParentId == null) Logger.ReportVerbose("Parent Id is null for {0}",item.Name); item.LocationType = mb3Item.LocationType; // recursive media count item.ApiRecursiveItemCount = mb3Item.RecursiveItemCount; item.ApiItemCount = mb3Item.ChildCount; // disc status item.IsOffline = mb3Item.LocationType == LocationType.Offline; item.IsExternalDisc = mb3Item.IsPlaceHolder ?? false; // playback access item.PlaybackAllowed = (mb3Item.PlayAccess == PlayAccess.Full) && !(mb3Item.IsPlaceHolder ?? false); // delete access item.CanDelete = mb3Item.CanDelete ?? false; //Ratings item.CriticRating = mb3Item.CriticRating; item.CriticRatingSummary = mb3Item.CriticRatingSummary; item.MetaScore = mb3Item.Metascore; //SpecialFeatures item.SpecialFeatureCount = mb3Item.SpecialFeatureCount ?? 0; //Counts item.MovieCount = mb3Item.MovieCount ?? 0; item.SeriesCount = mb3Item.SeriesCount ?? 0; item.EpisodeCount = mb3Item.EpisodeCount ?? 0; item.TrailerCount = mb3Item.LocalTrailerCount ?? 0; item.GameCount = mb3Item.GameCount ?? 0; item.SongCount = mb3Item.SongCount ?? 0; item.AlbumCount = mb3Item.AlbumCount ?? 0; item.MusicVideoCount = mb3Item.MusicVideoCount ?? 0; var runTimeTicks = mb3Item.RunTimeTicks; item.RuntimeTicks = runTimeTicks ?? 0; var index = item as IndexFolder; if (index != null) { index.Id = mb3Item.Id.GetMD5(); index.IndexId = mb3Item.Id; } else { item.Id = new Guid(mb3Item.Id); } if (mb3Item.ImageTags != null) { foreach (var tag in mb3Item.ImageTags) { switch (tag.Key) { case ImageType.Primary: if (mb3Item.HasPrimaryImage) { item.PrimaryImagePath = GetImageUrl(item, new ImageOptions { ImageType = tag.Key, Tag = tag.Value, Quality = Kernel.Instance.CommonConfigData.JpgImageQuality, MaxWidth = Kernel.Instance.CommonConfigData.MaxPrimaryWidth, CropWhitespace = false }); } break; case ImageType.Logo: if (mb3Item.HasLogo) { item.LogoImagePath = GetImageUrl(item, new ImageOptions { ImageType = tag.Key, Tag = tag.Value, Quality = Kernel.Instance.CommonConfigData.JpgImageQuality, MaxWidth = Kernel.Instance.CommonConfigData.MaxLogoWidth, CropWhitespace = false }); } break; case ImageType.Art: if (mb3Item.HasArtImage) { item.ArtImagePath = GetImageUrl(item, new ImageOptions { ImageType = tag.Key, Tag = tag.Value, Quality = Kernel.Instance.CommonConfigData.JpgImageQuality, MaxWidth = Kernel.Instance.CommonConfigData.MaxArtWidth, CropWhitespace = false }); } break; case ImageType.Banner: if (mb3Item.HasBanner) { item.BannerImagePath = GetImageUrl(item, new ImageOptions { ImageType = tag.Key, Tag = tag.Value, Quality = Kernel.Instance.CommonConfigData.JpgImageQuality, MaxWidth = Kernel.Instance.CommonConfigData.MaxBannerWidth, CropWhitespace = false }); } break; case ImageType.Thumb: if (mb3Item.HasThumb) { item.ThumbnailImagePath = GetImageUrl(item, new ImageOptions { ImageType = tag.Key, Tag = tag.Value, Quality = Kernel.Instance.CommonConfigData.JpgImageQuality, MaxWidth = Kernel.Instance.CommonConfigData.MaxThumbWidth, CropWhitespace = false }); } break; case ImageType.Disc: if (mb3Item.HasDiscImage) { item.DiscImagePath = GetImageUrl(item, new ImageOptions { ImageType = tag.Key, Tag = tag.Value, Quality = Kernel.Instance.CommonConfigData.JpgImageQuality, MaxWidth = Kernel.Instance.CommonConfigData.MaxDiscWidth, CropWhitespace = false }); } break; } } } if (mb3Item.BackdropImageTags != null && mb3Item.BackdropCount > 0) { var ndx = 0; item.BackdropImagePaths = new List <string>(); foreach (var bd in mb3Item.BackdropImageTags) { item.BackdropImagePaths.Add(Kernel.ApiClient.GetImageUrl(mb3Item.Id, new ImageOptions { ImageType = ImageType.Backdrop, Quality = Kernel.Instance.CommonConfigData.JpgImageQuality, MaxWidth = Kernel.Instance.CommonConfigData.MaxBackgroundWidth, Tag = bd, ImageIndex = ndx })); ndx++; } } var folder = item as Folder; if (folder != null) { // Collection Type folder.CollectionType = mb3Item.CollectionType; // Fill in display prefs folder.DisplayPreferencesId = mb3Item.DisplayPreferencesId ?? mb3Item.Id; // cumulative runtime if (mb3Item.CumulativeRunTimeTicks != null) { folder.RunTime = (int)(mb3Item.CumulativeRunTimeTicks / TimeSpan.TicksPerMinute); } // unwatched count if (mb3Item.UserData != null && mb3Item.UserData.UnplayedItemCount.HasValue) { folder.UnwatchedCount = mb3Item.UserData.UnplayedItemCount.Value; } // it is just too slow to try and gather these as channels are dynamic and potentially large else if (mb3Item.Type == "Channel" || mb3Item.Type == "ChannelFolder") { folder.UnwatchedCount = 0; } // we want our created date to be the date of last item we contain folder.DateCreated = mb3Item.DateLastMediaAdded ?? folder.DateCreated; } var video = item as Video; if (video != null && video.Path != null) { video.ContainsTrailers = mb3Item.LocalTrailerCount > 0; if (mb3Item.Video3DFormat != null) { video.VideoFormat = mb3Item.Video3DFormat == Video3DFormat.FullSideBySide || mb3Item.Video3DFormat == Video3DFormat.HalfSideBySide ? "Sbs3D" : "Digital3D"; video.Is3D = true; } else { video.VideoFormat = "Standard"; } // Chapters if (mb3Item.Chapters != null) { var ndx = 0; video.Chapters = mb3Item.Chapters.Select(c => new Chapter { ApiParentId = mb3Item.Id, PositionTicks = c.StartPositionTicks, Name = c.Name, PrimaryImagePath = c.HasImage ? GetImageUrl(video, new ImageOptions { Tag = c.ImageTag, ImageType = ImageType.Chapter, ImageIndex = ndx++ }) : null }).ToList(); } } var media = item as Media; if (media != null) { media.PartCount = mb3Item.PartCount ?? 1; media.MediaSources = mb3Item.MediaSources; if (mb3Item.MediaType == Model.Entities.MediaType.Video) { if (mb3Item.VideoType == VideoType.VideoFile && media.Path != null) { media.MediaType = MediaTypeResolver.DetermineType(media.Path); } else { switch (mb3Item.VideoType) { case VideoType.BluRay: media.MediaType = MediaType.BluRay; break; case VideoType.Dvd: media.MediaType = MediaType.DVD; break; case VideoType.Iso: media.MediaType = MediaType.ISO; break; default: media.MediaType = MediaType.Unknown; break; } } } else { media.MediaType = MediaTypeResolver.DetermineType(media.Path); } if (mb3Item.MediaStreams != null) { var vidStream = mb3Item.MediaStreams.FirstOrDefault(s => s.Type == MediaStreamType.Video); var audStream = mb3Item.MediaStreams.FirstOrDefault(s => s.Type == MediaStreamType.Audio && s.IsDefault) ?? mb3Item.MediaStreams.FirstOrDefault(s => s.Type == MediaStreamType.Audio); var subtStreams = mb3Item.MediaStreams.Where(s => s.Type == MediaStreamType.Subtitle && !string.IsNullOrEmpty(s.Language)).Select(s => s.IsForced ? s.Language.ToUpper() : s.Language).ToArray(); media.MediaStreams = mb3Item.MediaStreams; media.AspectRatio = !string.IsNullOrEmpty(mb3Item.AspectRatio) ? mb3Item.AspectRatio : null; media.SubTitle = subtStreams.Any() ? string.Join(", ", subtStreams) : null; media.MediaInfo = new MediaInfoData { OverrideData = new MediaInfoData.MIData { AudioStreamCount = mb3Item.MediaStreams.Count(s => s.Type == MediaStreamType.Audio), AudioBitRate = audStream != null ? audStream.BitRate ?? 0 : 0, AudioChannelCount = audStream != null?TranslateAudioChannels(audStream.Channels ?? 0) : "", AudioFormat = audStream != null ? audStream.Codec == "dca" ? audStream.Profile : audStream.Codec : "", VideoBitRate = vidStream != null ? vidStream.BitRate ?? 0 : 0, VideoCodec = vidStream != null ? vidStream.Codec : "", VideoFPS = vidStream != null?vidStream.AverageFrameRate.ToString() : "", Width = vidStream != null ? vidStream.Width ?? 0 : 0, Height = vidStream != null ? vidStream.Height ?? 0 : 0, Subtitles = subtStreams.Any() ? string.Join(", ", subtStreams) : null, RunTime = runTimeTicks != null?ConvertTicksToMinutes(runTimeTicks) : 0 } }; } if (mb3Item.UserData != null) { media.PlaybackStatus = PlaybackStatusFactory.Instance.Create(media.Id); media.PlaybackStatus.PositionTicks = mb3Item.UserData.PlaybackPositionTicks; media.PlaybackStatus.PlayCount = mb3Item.UserData.PlayCount; media.PlaybackStatus.WasPlayed = mb3Item.UserData.Played || mb3Item.LocationType == LocationType.Virtual; media.PlaybackStatus.LastPlayed = (mb3Item.UserData.LastPlayedDate ?? DateTime.MinValue).ToLocalTime(); } } var show = item as IShow; if (show != null) { show.MpaaRating = mb3Item.OfficialRating; show.ImdbRating = mb3Item.CommunityRating; show.RunningTime = runTimeTicks != null ? (int?)ConvertTicksToMinutes(runTimeTicks) : null; if (mb3Item.Genres != null) { show.Genres = new List <string>(mb3Item.Genres); } if (mb3Item.People != null) { show.Actors = new List <Actor>(mb3Item.People.Where(p => p.Type == PersonType.Actor || p.Type == PersonType.GuestStar).Select(a => new Actor(a))); show.Directors = new List <string>(mb3Item.People.Where(p => p.Type == PersonType.Director).Select(a => a.Name)); } if (mb3Item.Studios != null) { show.Studios = new List <string>(mb3Item.Studios.Select(s => s.Name)); foreach (var studio in mb3Item.Studios.Where(s => s != null)) { Studio.AddToCache(studio); } } } var episode = item as Episode; if (episode != null) { var indexDisplay = mb3Item.IndexNumber != null && mb3Item.IndexNumber > 0 ? mb3Item.IndexNumber + (mb3Item.IndexNumberEnd != null ? "-" + mb3Item.IndexNumberEnd : "") + " - " : ""; episode.Name = indexDisplay != "" ? indexDisplay + episode.Name : episode.Name; episode.EpisodeNumber = mb3Item.IndexNumber != null?mb3Item.IndexNumber.Value.ToString("#00") : null; episode.SeasonNumber = mb3Item.ParentIndexNumber != null?mb3Item.ParentIndexNumber.Value.ToString("#00") : null; episode.SeriesId = mb3Item.SeriesId; episode.SeasonId = mb3Item.SeasonId; if (mb3Item.AirsAfterSeasonNumber != null) { episode.SortName = mb3Item.AirsAfterSeasonNumber.Value.ToString("000") + "-999999" + mb3Item.SortName; } else if (mb3Item.AirsBeforeSeasonNumber != null && mb3Item.AirsBeforeEpisodeNumber != null) { episode.SortName = mb3Item.AirsBeforeSeasonNumber.Value.ToString("000") + "-" + ((int)(mb3Item.AirsBeforeEpisodeNumber - 1)).ToString("0000") + ".5" + mb3Item.SortName; } } var season = item as Season; if (season != null) { season.SeasonNumber = (mb3Item.IndexNumber ?? 0).ToString("000"); } else { var series = item as Series; if (series != null) { series.Status = mb3Item.Status; series.AirTime = mb3Item.AirTime; series.ImdbRating = mb3Item.CommunityRating; series.CriticRating = mb3Item.CriticRating; series.AirDay = mb3Item.AirDays != null?mb3Item.AirDays.FirstOrDefault().ToString() : null; } } var song = item as Song; if (song != null) { song.Album = mb3Item.Album; song.AlbumArtist = mb3Item.AlbumArtist; song.AlbumId = mb3Item.AlbumId; song.Artist = mb3Item.Artists.FirstOrDefault(); song.CriticRating = mb3Item.CommunityRating; } var album = item as MusicAlbum; if (album != null) { album.AlbumArtist = mb3Item.AlbumArtist ?? mb3Item.Artists.FirstOrDefault(); } var photo = item as Photo; if (photo != null) { if (mb3Item.HasPrimaryImage) { //Make the photo itself also the backdrop so it can preview large and play back at full-res item.BackdropImagePaths = new List <string> { Kernel.ApiClient.GetImageUrl(mb3Item.Id, new ImageOptions { ImageType = ImageType.Primary, Quality = Kernel.Instance.CommonConfigData.JpgImageQuality, MaxWidth = Kernel.Instance.CommonConfigData.MaxBackgroundWidth, Tag = mb3Item.ImageTags[ImageType.Primary] }) }; } if (string.IsNullOrEmpty(photo.Overview)) { if (photo.DateTaken != DateTime.MinValue || !string.IsNullOrEmpty(mb3Item.CameraMake) || !string.IsNullOrEmpty(mb3Item.CameraModel)) { photo.Overview = string.Format("Taken {0} with a {1} {2}\n", photo.DateTaken > DateTime.MinValue ? photo.DateTaken.ToShortTimeString() : "", mb3Item.CameraMake, mb3Item.CameraModel); } photo.Overview += string.Format("Original Resolution {0}x{1}", mb3Item.Width, mb3Item.Height); if (mb3Item.ShutterSpeed != null) { photo.Overview += string.Format(" Shutter Speed {0}\n", mb3Item.ShutterSpeed); } } } // Finally, any custom values item.FillCustomValues(mb3Item); } else { Logger.ReportWarning("Ignoring invalid item " + itemType + ". Would not instantiate in current environment."); } return(item); }