/// <inheritdoc /> public bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem parent) { // Don't ignore application folders if (fileInfo.FullName.Contains(_serverApplicationPaths.RootFolderPath, StringComparison.InvariantCulture)) { return(false); } // Don't ignore top level folders if (fileInfo.IsDirectory && parent is AggregateFolder) { return(false); } if (IgnorePatterns.ShouldIgnore(fileInfo.FullName)) { return(true); } var filename = fileInfo.Name; if (fileInfo.IsDirectory) { if (parent != null) { // Ignore trailer folders but allow it at the collection level if (string.Equals(filename, BaseItem.TrailersFolderName, StringComparison.OrdinalIgnoreCase) && !(parent is AggregateFolder) && !(parent is UserRootFolder)) { return(true); } if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase)) { return(true); } if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase)) { return(true); } } } else { if (parent != null) { // Don't resolve these into audio files if (Path.GetFileNameWithoutExtension(filename.AsSpan()).Equals(BaseItem.ThemeSongFileName, StringComparison.Ordinal) && AudioFileParser.IsAudioFile(filename, _namingOptions)) { return(true); } } } return(false); }
private ExtraResult GetExtraInfo(string path, ExtraRule rule) { var result = new ExtraResult(); if (rule.MediaType == MediaType.Audio) { if (!AudioFileParser.IsAudioFile(path, _options)) { return(result); } } else if (rule.MediaType == MediaType.Video) { if (!new VideoResolver(_options).IsVideoFile(path)) { return(result); } } else { return(result); } if (rule.RuleType == ExtraRuleType.Filename) { var filename = Path.GetFileNameWithoutExtension(path); if (string.Equals(filename, rule.Token, StringComparison.OrdinalIgnoreCase)) { result.ExtraType = rule.ExtraType; result.Rule = rule; } } else if (rule.RuleType == ExtraRuleType.Suffix) { var filename = Path.GetFileNameWithoutExtension(path); if (filename.IndexOf(rule.Token, StringComparison.OrdinalIgnoreCase) > 0) { result.ExtraType = rule.ExtraType; result.Rule = rule; } } else if (rule.RuleType == ExtraRuleType.Regex) { var filename = Path.GetFileName(path); var regex = new Regex(rule.Token, RegexOptions.IgnoreCase); if (regex.IsMatch(filename)) { result.ExtraType = rule.ExtraType; result.Rule = rule; } } return(result); }
/// <summary> /// Returns the external audio file paths for the given video. /// </summary> /// <param name="video">The video to get the external audio file paths from.</param> /// <param name="directoryService">The directory service to search for files.</param> /// <param name="clearCache">True if the directory service cache should be cleared before searching.</param> /// <returns>A list of external audio file paths.</returns> public IEnumerable <string> GetExternalAudioFiles( Video video, IDirectoryService directoryService, bool clearCache) { if (!video.IsFileProtocol) { yield break; } // Check if video folder exists string folder = video.ContainingFolderPath; if (!Directory.Exists(folder)) { yield break; } string videoFileNameWithoutExtension = Path.GetFileNameWithoutExtension(video.Path); var files = directoryService.GetFilePaths(folder, clearCache, true); for (int i = 0; i < files.Count; i++) { string file = files[i]; if (string.Equals(video.Path, file, StringComparison.OrdinalIgnoreCase) || !AudioFileParser.IsAudioFile(file, _namingOptions) || Path.GetExtension(file.AsSpan()).Equals(".strm", StringComparison.OrdinalIgnoreCase)) { continue; } string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file); // The audio filename must either be equal to the video filename or start with the video filename followed by a dot if (videoFileNameWithoutExtension.Equals(fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase) || (fileNameWithoutExtension.Length > videoFileNameWithoutExtension.Length && fileNameWithoutExtension[videoFileNameWithoutExtension.Length] == '.' && fileNameWithoutExtension.StartsWith(videoFileNameWithoutExtension, StringComparison.OrdinalIgnoreCase))) { yield return(file); } } }
/// <summary> /// Attempts to resolve if file is extra. /// </summary> /// <param name="path">Path to file.</param> /// <param name="namingOptions">The naming options.</param> /// <returns>Returns <see cref="ExtraResult"/> object.</returns> public static ExtraResult GetExtraInfo(string path, NamingOptions namingOptions) { var result = new ExtraResult(); for (var i = 0; i < namingOptions.VideoExtraRules.Length; i++) { var rule = namingOptions.VideoExtraRules[i]; if ((rule.MediaType == MediaType.Audio && !AudioFileParser.IsAudioFile(path, namingOptions)) || (rule.MediaType == MediaType.Video && !VideoResolver.IsVideoFile(path, namingOptions))) { continue; } var pathSpan = path.AsSpan(); if (rule.RuleType == ExtraRuleType.Filename) { var filename = Path.GetFileNameWithoutExtension(pathSpan); if (filename.Equals(rule.Token, StringComparison.OrdinalIgnoreCase)) { result.ExtraType = rule.ExtraType; result.Rule = rule; } } else if (rule.RuleType == ExtraRuleType.Suffix) { // Trim the digits from the end of the filename so we can recognize things like -trailer2 var filename = Path.GetFileNameWithoutExtension(pathSpan).TrimEnd(_digits); if (filename.EndsWith(rule.Token, StringComparison.OrdinalIgnoreCase)) { result.ExtraType = rule.ExtraType; result.Rule = rule; } } else if (rule.RuleType == ExtraRuleType.Regex) { var filename = Path.GetFileName(path); var isMatch = Regex.IsMatch(filename, rule.Token, RegexOptions.IgnoreCase | RegexOptions.Compiled); if (isMatch) { result.ExtraType = rule.ExtraType; result.Rule = rule; } } else if (rule.RuleType == ExtraRuleType.DirectoryName) { var directoryName = Path.GetFileName(Path.GetDirectoryName(pathSpan)); if (directoryName.Equals(rule.Token, StringComparison.OrdinalIgnoreCase)) { result.ExtraType = rule.ExtraType; result.Rule = rule; } } if (result.ExtraType != null) { return(result); } } return(result); }
/// <summary> /// Attempts to resolve if file is extra. /// </summary> /// <param name="path">Path to file.</param> /// <returns>Returns <see cref="ExtraResult"/> object.</returns> public ExtraResult GetExtraInfo(string path) { var result = new ExtraResult(); for (var i = 0; i < _options.VideoExtraRules.Length; i++) { var rule = _options.VideoExtraRules[i]; if (rule.MediaType == MediaType.Audio) { if (!AudioFileParser.IsAudioFile(path, _options)) { continue; } } else if (rule.MediaType == MediaType.Video) { if (!new VideoResolver(_options).IsVideoFile(path)) { continue; } } var pathSpan = path.AsSpan(); if (rule.RuleType == ExtraRuleType.Filename) { var filename = Path.GetFileNameWithoutExtension(pathSpan); if (filename.Equals(rule.Token, StringComparison.OrdinalIgnoreCase)) { result.ExtraType = rule.ExtraType; result.Rule = rule; } } else if (rule.RuleType == ExtraRuleType.Suffix) { var filename = Path.GetFileNameWithoutExtension(pathSpan); if (filename.Contains(rule.Token, StringComparison.OrdinalIgnoreCase)) { result.ExtraType = rule.ExtraType; result.Rule = rule; } } else if (rule.RuleType == ExtraRuleType.Regex) { var filename = Path.GetFileName(path); var regex = new Regex(rule.Token, RegexOptions.IgnoreCase); if (regex.IsMatch(filename)) { result.ExtraType = rule.ExtraType; result.Rule = rule; } } else if (rule.RuleType == ExtraRuleType.DirectoryName) { var directoryName = Path.GetFileName(Path.GetDirectoryName(pathSpan)); if (directoryName.Equals(rule.Token, StringComparison.OrdinalIgnoreCase)) { result.ExtraType = rule.ExtraType; result.Rule = rule; } } if (result.ExtraType != null) { return(result); } } return(result); }
private bool ContainsMusic( IEnumerable <FileSystemMetadata> list, bool allowSubfolders, IDirectoryService directoryService) { // check for audio files before digging down into directories var foundAudioFile = list.Any(fileSystemInfo => !fileSystemInfo.IsDirectory && AudioFileParser.IsAudioFile(fileSystemInfo.FullName, _namingOptions)); if (foundAudioFile) { // at least one audio file exists return(true); } if (!allowSubfolders) { // not music since no audio file exists and we're not looking into subfolders return(false); } var discSubfolderCount = 0; var parser = new AlbumParser(_namingOptions); var directories = list.Where(fileSystemInfo => fileSystemInfo.IsDirectory); var result = Parallel.ForEach(directories, (fileSystemInfo, state) => { var path = fileSystemInfo.FullName; var hasMusic = ContainsMusic(directoryService.GetFileSystemEntries(path), false, directoryService); if (hasMusic) { if (parser.IsMultiPart(path)) { _logger.LogDebug("Found multi-disc folder: {Path}", path); Interlocked.Increment(ref discSubfolderCount); } else { // If there are folders underneath with music that are not multidisc, then this can't be a multi-disc album state.Stop(); } } }); if (!result.IsCompleted) { return(false); } return(discSubfolderCount > 0); }
protected override MediaBrowser.Controller.Entities.Audio.Audio Resolve(ItemResolveArgs args) { // Return audio if the path is a file and has a matching extension var collectionType = args.GetCollectionType(); var isBooksCollectionType = string.Equals(collectionType, CollectionType.Books, StringComparison.OrdinalIgnoreCase); if (args.IsDirectory) { if (!isBooksCollectionType) { return(null); } return(FindAudioBook(args, false)); } if (AudioFileParser.IsAudioFile(args.Path, _namingOptions)) { var extension = Path.GetExtension(args.Path); if (string.Equals(extension, ".cue", StringComparison.OrdinalIgnoreCase)) { // if audio file exists of same name, return null return(null); } var isMixedCollectionType = string.IsNullOrEmpty(collectionType); // For conflicting extensions, give priority to videos if (isMixedCollectionType && VideoResolver.IsVideoFile(args.Path, _namingOptions)) { return(null); } MediaBrowser.Controller.Entities.Audio.Audio item = null; var isMusicCollectionType = string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase); // Use regular audio type for mixed libraries, owned items and music if (isMixedCollectionType || args.Parent == null || isMusicCollectionType) { item = new MediaBrowser.Controller.Entities.Audio.Audio(); } else if (isBooksCollectionType) { item = new AudioBook(); } if (item != null) { item.IsShortcut = string.Equals(extension, ".strm", StringComparison.OrdinalIgnoreCase); item.IsInMixedFolder = true; } return(item); } return(null); }