private IEnumerable<IntroInfo> GetResult(BaseItem item, IEnumerable<ItemWithTrailer> candidates, CinemaModeConfiguration config, int? ratingLevel) { var customIntros = !string.IsNullOrWhiteSpace(config.CustomIntroPath) ? GetCustomIntros(item) : new List<IntroInfo>(); var trailerLimit = config.TrailerLimit; // Avoid implicitly captured closure return candidates.Where(i => { if (config.EnableIntrosParentalControl && !FilterByParentalRating(ratingLevel, i.Item)) { return false; } if (!config.EnableIntrosForWatchedContent && i.IsPlayed) { return false; } return !IsDuplicate(item, i.Item); }) .OrderByDescending(i => i.Score) .ThenBy(i => Guid.NewGuid()) .ThenByDescending(i => (i.IsPlayed ? 0 : 1)) .Select(i => i.IntroInfo) .Take(trailerLimit) .Concat(customIntros.Take(1)); }
private IEnumerable<string> GetCustomIntroFiles(CinemaModeConfiguration options = null) { options = options ?? GetOptions(); if (string.IsNullOrWhiteSpace(options.CustomIntroPath)) { return new List<string>(); } return _fileSystem.GetFilePaths(options.CustomIntroPath, true) .Where(_libraryManager.IsVideoFile); }
private IEnumerable<string> GetCustomIntroFiles(CinemaModeConfiguration options = null) { options = options ?? GetOptions(); if (string.IsNullOrWhiteSpace(options.CustomIntroPath)) { return new List<string>(); } return Directory.EnumerateFiles(options.CustomIntroPath, "*", SearchOption.AllDirectories) .Where(_libraryManager.IsVideoFile); }
private IEnumerable<string> GetCustomIntroFiles(CinemaModeConfiguration options, bool enableCustomIntros, bool enableMediaInfoIntros) { var list = new List<string>(); if (enableCustomIntros && !string.IsNullOrWhiteSpace(options.CustomIntroPath)) { list.AddRange(_fileSystem.GetFilePaths(options.CustomIntroPath, true) .Where(_libraryManager.IsVideoFile)); } if (enableMediaInfoIntros && !string.IsNullOrWhiteSpace(options.MediaInfoIntroPath)) { list.AddRange(_fileSystem.GetFilePaths(options.MediaInfoIntroPath, true) .Where(_libraryManager.IsVideoFile)); } return list.Distinct(StringComparer.OrdinalIgnoreCase); }
private IEnumerable<IntroInfo> GetMediaInfoIntros(CinemaModeConfiguration options, BaseItem item) { try { var hasMediaSources = item as IHasMediaSources; if (hasMediaSources == null) { return new List<IntroInfo>(); } var mediaSource = _mediaSourceManager.GetStaticMediaSources(hasMediaSources, false) .FirstOrDefault(); if (mediaSource == null) { return new List<IntroInfo>(); } var videoStream = mediaSource.MediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video); var audioStream = mediaSource.MediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio); var allIntros = GetCustomIntroFiles(options, false, true) .OrderBy(i => Guid.NewGuid()) .Select(i => new IntroInfo { Path = i }).ToList(); var returnResult = new List<IntroInfo>(); if (videoStream != null) { returnResult.AddRange(GetMediaInfoIntrosByVideoStream(allIntros, videoStream).Take(1)); } if (audioStream != null) { returnResult.AddRange(GetMediaInfoIntrosByAudioStream(allIntros, audioStream).Take(1)); } returnResult.AddRange(GetMediaInfoIntrosByTags(allIntros, item.Tags).Take(1)); return returnResult.DistinctBy(i => i.Path, StringComparer.OrdinalIgnoreCase); } catch (IOException) { return new List<IntroInfo>(); } }
private List<IntroInfo> GetCustomIntros(CinemaModeConfiguration options) { try { return GetCustomIntroFiles(options, true, false) .OrderBy(i => Guid.NewGuid()) .Select(i => new IntroInfo { Path = i }).ToList(); } catch (IOException) { return new List<IntroInfo>(); } }
private IEnumerable<IntroInfo> GetResult(BaseItem item, IEnumerable<ItemWithTrailer> candidates, CinemaModeConfiguration config) { var customIntros = !string.IsNullOrWhiteSpace(config.CustomIntroPath) ? GetCustomIntros(config) : new List<IntroInfo>(); var mediaInfoIntros = !string.IsNullOrWhiteSpace(config.MediaInfoIntroPath) ? GetMediaInfoIntros(config, item) : new List<IntroInfo>(); // Avoid implicitly captured closure return candidates.Select(i => i.IntroInfo) .Concat(customIntros.Take(1)) .Concat(mediaInfoIntros); }