Example #1
0
        private bool IsEligibleForMultiVersion(string folderName, string testFilePath)
        {
            string testFilename = Path.GetFileNameWithoutExtension(testFilePath);

            if (testFilename.StartsWith(folderName, StringComparison.OrdinalIgnoreCase))
            {
                // Remove the folder name before cleaning as we don't care about cleaning that part
                if (folderName.Length <= testFilename.Length)
                {
                    testFilename = testFilename.Substring(folderName.Length).Trim();
                }

                if (CleanStringParser.TryClean(testFilename, _options.CleanStringRegexes, out var cleanName))
                {
                    testFilename = cleanName.Trim().ToString();
                }

                // The CleanStringParser should have removed common keywords etc.
                return(string.IsNullOrEmpty(testFilename) ||
                       testFilename[0] == '-' ||
                       testFilename[0] == '_' ||
                       Regex.IsMatch(testFilename, @"^\[([^]]*)\]"));
            }

            return(false);
        }
Example #2
0
        public CleanDateTimeResult Clean(string name)
        {
            var originalName = name;

            try
            {
                var extension = Path.GetExtension(name) ?? string.Empty;
                // Check supported extensions
                if (!_options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase) &&
                    !_options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
                {
                    // Dummy up a file extension because the expressions will fail without one
                    // This is tricky because we can't just check Path.GetExtension for empty
                    // If the input is "St. Vincent (2014)", it will produce ". Vincent (2014)" as the extension
                    name += ".mkv";
                }
            }
            catch (ArgumentException)
            {
            }

            var result = _options.CleanDateTimeRegexes.Select(i => Clean(name, i))
                         .FirstOrDefault(i => i.HasChanged) ??
                         new CleanDateTimeResult {
                Name = originalName
            };

            if (result.HasChanged)
            {
                return(result);
            }

            // Make a second pass, running clean string first
            var cleanStringResult = new CleanStringParser().Clean(name, _options.CleanStringRegexes);

            if (!cleanStringResult.HasChanged)
            {
                return(result);
            }

            return(_options.CleanDateTimeRegexes.Select(i => Clean(cleanStringResult.Name, i))
                   .FirstOrDefault(i => i.HasChanged) ??
                   result);
        }
Example #3
0
        private bool IsEligibleForMultiVersion(string folderName, string?testFilename)
        {
            testFilename = Path.GetFileNameWithoutExtension(testFilename) ?? string.Empty;

            if (testFilename.StartsWith(folderName, StringComparison.OrdinalIgnoreCase))
            {
                if (CleanStringParser.TryClean(testFilename, _options.CleanStringRegexes, out var cleanName))
                {
                    testFilename = cleanName.ToString();
                }

                testFilename = testFilename.Substring(folderName.Length).Trim();
                return(string.IsNullOrEmpty(testFilename) ||
                       testFilename[0].Equals('-') ||
                       testFilename[0].Equals('_') ||
                       string.IsNullOrWhiteSpace(Regex.Replace(testFilename, @"\[([^]]*)\]", string.Empty)));
            }

            return(false);
        }
Example #4
0
 /// <summary>
 /// Tries to clean name of clutter.
 /// </summary>
 /// <param name="name">Raw name.</param>
 /// <param name="namingOptions">The naming options.</param>
 /// <param name="newName">Clean name.</param>
 /// <returns>True if cleaning of name was successful.</returns>
 public static bool TryCleanString([NotNullWhen(true)] string?name, NamingOptions namingOptions, out string newName)
 {
     return(CleanStringParser.TryClean(name, namingOptions.CleanStringRegexes, out newName));
 }
Example #5
0
 /// <summary>
 /// Tries to clean name of clutter.
 /// </summary>
 /// <param name="name">Raw name.</param>
 /// <param name="newName">Clean name.</param>
 /// <returns>True if cleaning of name was successful.</returns>
 public bool TryCleanString([NotNullWhen(true)] string?name, out ReadOnlySpan <char> newName)
 {
     return(CleanStringParser.TryClean(name, _options.CleanStringRegexes, out newName));
 }
Example #6
0
 public bool TryCleanString(string name, out ReadOnlySpan <char> newName)
 {
     return(CleanStringParser.TryClean(name, _options.CleanStringRegexes, out newName));
 }