Ejemplo n.º 1
0
        public void ScriptNamingScheme_With_IncludeBaseFolderName_And_Prefix_Set_ShoudUsePrefixBeforeFolderName()
        {
            var scripts = new List <ScriptBatch>()
            {
                new ScriptBatch(ScriptProviderHelper.GetFolder(GetBasePath(), "Naming"), false, true, 0, Constants.Default.Encoding)
            };

            var namingOptions = new NamingOptions(false, includeBaseFolderName: true, "prefix_");

            var upgradeEngineBuilder = DeployChanges.To
                                       .SqlDatabase("testconn")
                                       .OverrideConnectionFactory(testConnectionFactory)
                                       .LogTo(Logger).Some <UpgradeEngineBuilder, Error>()
                                       .SelectScripts(scripts, namingOptions);

            upgradeEngineBuilder.MatchSome(x =>
            {
                x.Build().PerformUpgrade();
            });

            var executedScripts = Logger.GetExecutedScripts();

            executedScripts[0].Should().Be("prefix_Naming.SubFolder.001.sql");
        }
Ejemplo n.º 2
0
        private static bool IsEligibleForMultiVersion(ReadOnlySpan <char> folderName, string testFilePath, NamingOptions namingOptions)
        {
            var testFilename = Path.GetFileNameWithoutExtension(testFilePath.AsSpan());

            if (!testFilename.StartsWith(folderName, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            // Remove the folder name before cleaning as we don't care about cleaning that part
            if (folderName.Length <= testFilename.Length)
            {
                testFilename = testFilename[folderName.Length..].Trim();
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AudioBookListResolver"/> class.
 /// </summary>
 /// <param name="options">Naming options passed along to <see cref="AudioBookResolver"/> and <see cref="AudioBookNameParser"/>.</param>
 public AudioBookListResolver(NamingOptions options)
 {
     _options = options;
 }
Ejemplo n.º 4
0
 public CleanDateTimeParser(NamingOptions options, IRegexProvider iRegexProvider)
 {
     _options        = options;
     _iRegexProvider = iRegexProvider;
 }
Ejemplo n.º 5
0
 public EpisodeResolver(NamingOptions options, ILogger logger)
     : this(options, logger, new RegexProvider())
 {
 }
Ejemplo n.º 6
0
        private VideoListResolver GetResolver()
        {
            var options = new NamingOptions();

            return(new VideoListResolver(options));
        }
Ejemplo n.º 7
0
 public VideoResolver(NamingOptions options)
 {
     _options = options;
 }
Ejemplo n.º 8
0
 public EpisodePathParser(NamingOptions options)
 {
     _options = options;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Tries to get name and year from raw name.
 /// </summary>
 /// <param name="name">Raw name.</param>
 /// <param name="namingOptions">The naming options.</param>
 /// <returns>Returns <see cref="CleanDateTimeResult"/> with name and optional year.</returns>
 public static CleanDateTimeResult CleanDateTime(string name, NamingOptions namingOptions)
 {
     return(CleanDateTimeParser.Clean(name, namingOptions.CleanDateTimeRegexes));
 }
Ejemplo n.º 10
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));
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Determines if path is video file stub based on extension.
        /// </summary>
        /// <param name="path">Path to file.</param>
        /// <param name="namingOptions">The naming options.</param>
        /// <returns>True if is video file stub.</returns>
        public static bool IsStubFile(string path, NamingOptions namingOptions)
        {
            var extension = Path.GetExtension(path.AsSpan());

            return(namingOptions.StubFileExtensions.Contains(extension, StringComparison.OrdinalIgnoreCase));
        }
Ejemplo n.º 12
0
 public AudioBookFilePathParser(NamingOptions options)
 {
     _options = options;
 }
Ejemplo n.º 13
0
 public EpisodeResolver(NamingOptions options)
     : this(options, new RegexProvider())
 {
 }
Ejemplo n.º 14
0
 public GenericVideoResolver(NamingOptions namingOptions)
     : base(namingOptions)
 {
 }
Ejemplo n.º 15
0
 public static string GetNiceTypeName(System.Type type)
 {
     var options = new NamingOptions();
     options.NameOverrideFunc = GetCSharpTypeAlias;
     return GetNiceTypeName(type, options);
 }
Ejemplo n.º 16
0
        public static string GetNiceTypeName(System.Type type, NamingOptions options)
        {
            if (options != null && options.NameOverrideFunc !=null)
            {
                string s = options.NameOverrideFunc(type);
                if (s != null)
                {
                    return s;
                }
            }

            if (IsNullableType(type))
            {
                var actualtype = type.GetGenericArguments()[0];
                return GetNiceTypeName(actualtype, options) + "?";
            }

            if (type.IsArray)
            {
                var at = type.GetElementType();
                return string.Format("{0}[]", GetNiceTypeName(at, options));
            }

            if (type.IsGenericType)
            {
                var sb = new System.Text.StringBuilder();
                var tokens = type.Name.Split('`');

                sb.Append(tokens[0]);
                var gas = type.GetGenericArguments();
                var ga_names = gas.Select(i => GetNiceTypeName(i, options));

                sb.Append("<");
                Join(sb, ", ", ga_names);
                sb.Append(">");
                return sb.ToString();
            }

            return type.Name;
        }
Ejemplo n.º 17
0
 public EpisodeResolver(NamingOptions options)
 {
     _options = options;
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Resolves the directory.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="namingOptions">The naming options.</param>
 /// <param name="parseName">Whether to parse the name or use the filename.</param>
 /// <returns>VideoFileInfo.</returns>
 public static VideoFileInfo?ResolveDirectory(string?path, NamingOptions namingOptions, bool parseName = true)
 {
     return(Resolve(path, true, namingOptions, parseName));
 }
Ejemplo n.º 19
0
 public VideoResolver(NamingOptions options, ILogger logger, IRegexProvider regexProvider)
 {
     _options       = options;
     _logger        = logger;
     _regexProvider = regexProvider;
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Resolves the file.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="namingOptions">The naming options.</param>
 /// <returns>VideoFileInfo.</returns>
 public static VideoFileInfo?ResolveFile(string?path, NamingOptions namingOptions)
 {
     return(Resolve(path, false, namingOptions));
 }
Ejemplo n.º 21
0
        private AudioBookListResolver GetResolver()
        {
            var options = new NamingOptions();

            return(new AudioBookListResolver(options));
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Resolves the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="isDirectory">if set to <c>true</c> [is folder].</param>
        /// <param name="namingOptions">The naming options.</param>
        /// <param name="parseName">Whether or not the name should be parsed for info.</param>
        /// <returns>VideoFileInfo.</returns>
        /// <exception cref="ArgumentNullException"><c>path</c> is <c>null</c>.</exception>
        public static VideoFileInfo?Resolve(string?path, bool isDirectory, NamingOptions namingOptions, bool parseName = true)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            bool isStub = false;
            ReadOnlySpan <char> container = ReadOnlySpan <char> .Empty;
            string?stubType = null;

            if (!isDirectory)
            {
                var extension = Path.GetExtension(path.AsSpan());

                // Check supported extensions
                if (!namingOptions.VideoFileExtensions.Contains(extension, StringComparison.OrdinalIgnoreCase))
                {
                    // It's not supported. Check stub extensions
                    if (!StubResolver.TryResolveFile(path, namingOptions, out stubType))
                    {
                        return(null);
                    }

                    isStub = true;
                }

                container = extension.TrimStart('.');
            }

            var format3DResult = Format3DParser.Parse(path, namingOptions);

            var extraResult = ExtraResolver.GetExtraInfo(path, namingOptions);

            var name = Path.GetFileNameWithoutExtension(path);

            int?year = null;

            if (parseName)
            {
                var cleanDateTimeResult = CleanDateTime(name, namingOptions);
                name = cleanDateTimeResult.Name;
                year = cleanDateTimeResult.Year;

                if (extraResult.ExtraType == null &&
                    TryCleanString(name, namingOptions, out var newName))
                {
                    name = newName;
                }
            }

            return(new VideoFileInfo(
                       path: path,
                       container: container.IsEmpty ? null : container.ToString(),
                       isStub: isStub,
                       name: name,
                       year: year,
                       stubType: stubType,
                       is3D: format3DResult.Is3D,
                       format3D: format3DResult.Format3D,
                       extraType: extraResult.ExtraType,
                       isDirectory: isDirectory,
                       extraRule: extraResult.Rule));
        }
Ejemplo n.º 23
0
 public CleanDateTimeParser(NamingOptions options)
 {
     _options = options;
 }
 public ProductContext(DbContextOptions options, EnumLookupOptions enumLookupOptions, NamingOptions namingOptions)
     : base(options)
 {
     EnumLookupOptions = enumLookupOptions;
     NamingOptions     = namingOptions;
 }
Ejemplo n.º 25
0
 public EpisodeResolver(NamingOptions options, ILogger logger, IRegexProvider iRegexProvider)
 {
     _options        = options;
     _logger         = logger;
     _iRegexProvider = iRegexProvider;
 }
Ejemplo n.º 26
0
 public StubResolver(NamingOptions options)
 {
     _options = options;
 }
Ejemplo n.º 27
0
 public AudioFileParser(NamingOptions options)
 {
     _options = options;
 }
Ejemplo n.º 28
0
 public EpisodePathParser(NamingOptions options, IRegexProvider iRegexProvider)
 {
     _options        = options;
     _iRegexProvider = iRegexProvider;
 }
Ejemplo n.º 29
0
        private static List <VideoInfo> GetVideosGroupedByVersion(List <VideoInfo> videos, NamingOptions namingOptions)
        {
            if (videos.Count == 0)
            {
                return(videos);
            }

            var folderName = Path.GetFileName(Path.GetDirectoryName(videos[0].Files[0].Path.AsSpan()));

            if (folderName.Length <= 1 || !HaveSameYear(videos))
            {
                return(videos);
            }

            // Cannot use Span inside local functions and delegates thus we cannot use LINQ here nor merge with the above [if]
            for (var i = 0; i < videos.Count; i++)
            {
                var video = videos[i];
                if (!IsEligibleForMultiVersion(folderName, video.Files[0].Path, namingOptions))
                {
                    return(videos);
                }
            }

            // The list is created and overwritten in the caller, so we are allowed to do in-place sorting
            videos.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal));

            var list = new List <VideoInfo>
            {
                videos[0]
            };

            var alternateVersionsLen = videos.Count - 1;
            var alternateVersions    = new VideoFileInfo[alternateVersionsLen];
            var extras = new List <VideoFileInfo>(list[0].Extras);

            for (int i = 0; i < alternateVersionsLen; i++)
            {
                var video = videos[i + 1];
                alternateVersions[i] = video.Files[0];
                extras.AddRange(video.Extras);
            }

            list[0].AlternateVersions = alternateVersions;
            list[0].Name   = folderName.ToString();
            list[0].Extras = extras;

            return(list);
        }
Ejemplo n.º 30
0
 public VideoListResolver(NamingOptions options)
     : this(options, new RegexProvider())
 {
 }
Ejemplo n.º 31
0
        /// <summary>
        /// Resolves alternative versions and extras from list of video files.
        /// </summary>
        /// <param name="files">List of related video files.</param>
        /// <param name="namingOptions">The naming options.</param>
        /// <param name="supportMultiVersion">Indication we should consider multi-versions of content.</param>
        /// <returns>Returns enumerable of <see cref="VideoInfo"/> which groups files together when related.</returns>
        public static IEnumerable <VideoInfo> Resolve(IEnumerable <FileSystemMetadata> files, NamingOptions namingOptions, bool supportMultiVersion = true)
        {
            var videoInfos = files
                             .Select(i => VideoResolver.Resolve(i.FullName, i.IsDirectory, namingOptions))
                             .OfType <VideoFileInfo>()
                             .ToList();

            // Filter out all extras, otherwise they could cause stacks to not be resolved
            // See the unit test TestStackedWithTrailer
            var nonExtras = videoInfos
                            .Where(i => i.ExtraType == null)
                            .Select(i => new FileSystemMetadata {
                FullName = i.Path, IsDirectory = i.IsDirectory
            });

            var stackResult = new StackResolver(namingOptions)
                              .Resolve(nonExtras).ToList();

            var remainingFiles = videoInfos
                                 .Where(i => !stackResult.Any(s => i.Path != null && s.ContainsFile(i.Path, i.IsDirectory)))
                                 .ToList();

            var list = new List <VideoInfo>();

            foreach (var stack in stackResult)
            {
                var info = new VideoInfo(stack.Name)
                {
                    Files = stack.Files.Select(i => VideoResolver.Resolve(i, stack.IsDirectoryStack, namingOptions))
                            .OfType <VideoFileInfo>()
                            .ToList()
                };

                info.Year = info.Files[0].Year;

                var extras = ExtractExtras(remainingFiles, stack.Name, Path.GetFileNameWithoutExtension(stack.Files[0].AsSpan()), namingOptions.VideoFlagDelimiters);

                if (extras.Count > 0)
                {
                    info.Extras = extras;
                }

                list.Add(info);
            }

            var standaloneMedia = remainingFiles
                                  .Where(i => i.ExtraType == null)
                                  .ToList();

            foreach (var media in standaloneMedia)
            {
                var info = new VideoInfo(media.Name)
                {
                    Files = new[] { media }
                };

                info.Year = info.Files[0].Year;

                remainingFiles.Remove(media);
                var extras = ExtractExtras(remainingFiles, media.FileNameWithoutExtension, namingOptions.VideoFlagDelimiters);

                info.Extras = extras;

                list.Add(info);
            }

            if (supportMultiVersion)
            {
                list = GetVideosGroupedByVersion(list, namingOptions);
            }

            // If there's only one resolved video, use the folder name as well to find extras
            if (list.Count == 1)
            {
                var info       = list[0];
                var videoPath  = list[0].Files[0].Path;
                var parentPath = Path.GetDirectoryName(videoPath.AsSpan());

                if (!parentPath.IsEmpty)
                {
                    var folderName = Path.GetFileName(parentPath);
                    if (!folderName.IsEmpty)
                    {
                        var extras = ExtractExtras(remainingFiles, folderName, namingOptions.VideoFlagDelimiters);
                        extras.AddRange(info.Extras);
                        info.Extras = extras;
                    }
                }

                // Add the extras that are just based on file name as well
                var extrasByFileName = remainingFiles
                                       .Where(i => i.ExtraRule != null && i.ExtraRule.RuleType == ExtraRuleType.Filename)
                                       .ToList();

                remainingFiles = remainingFiles
                                 .Except(extrasByFileName)
                                 .ToList();

                extrasByFileName.AddRange(info.Extras);
                info.Extras = extrasByFileName;
            }

            // If there's only one video, accept all trailers
            // Be lenient because people use all kinds of mishmash conventions with trailers.
            if (list.Count == 1)
            {
                var trailers = remainingFiles
                               .Where(i => i.ExtraType == ExtraType.Trailer)
                               .ToList();

                trailers.AddRange(list[0].Extras);
                list[0].Extras = trailers;

                remainingFiles = remainingFiles
                                 .Except(trailers)
                                 .ToList();
            }

            // Whatever files are left, just add them
            list.AddRange(remainingFiles.Select(i => new VideoInfo(i.Name)
            {
                Files = new[] { i },
                Year  = i.Year
            }));

            return(list);
        }
Ejemplo n.º 32
0
 public VideoListResolver(NamingOptions options, IRegexProvider regexProvider)
 {
     _options       = options;
     _regexProvider = regexProvider;
 }