private void AddVirtualEpisode(EpisodeRecord episode, Season season) { // tvdb has a lot of bad data? if (!IsValidEpisode(episode) || season == null) { return; } // Put as much metadata into it as possible DateTime.TryParse(episode.FirstAired, out var premiereDate); var newEpisode = new Episode { Name = episode.EpisodeName, IndexNumber = episode.AiredEpisodeNumber !.Value, ParentIndexNumber = episode.AiredSeason !.Value, Id = _libraryManager.GetNewItemId( season.Series.Id + episode.AiredSeason.Value.ToString(CultureInfo.InvariantCulture) + "Episode " + episode.AiredEpisodeNumber, typeof(Episode)), IsVirtualItem = true, SeasonId = season.Id, SeriesId = season.Series.Id, AirsBeforeEpisodeNumber = episode.AirsBeforeEpisode, AirsAfterSeasonNumber = episode.AirsAfterSeason, AirsBeforeSeasonNumber = episode.AirsBeforeSeason, Overview = episode.Overview, CommunityRating = (float?)episode.SiteRating, OfficialRating = episode.ContentRating, PremiereDate = premiereDate, SeriesName = season.Series.Name, SeriesPresentationUniqueKey = season.SeriesPresentationUniqueKey, SeasonName = season.Name, DateLastSaved = DateTime.UtcNow }; newEpisode.PresentationUniqueKey = newEpisode.GetPresentationUniqueKey(); newEpisode.SetProviderId(MetadataProvider.Tvdb, episode.Id.ToString(CultureInfo.InvariantCulture)); _logger.LogInformation( "Creating virtual episode {0} {1}x{2}", season.Series.Name, episode.AiredSeason, episode.AiredEpisodeNumber); season.AddChild(newEpisode, CancellationToken.None); }