Пример #1
0
 private void TestStackInfo(FileStack stack, string name, int fileCount)
 {
     Assert.AreEqual(fileCount, stack.Files.Count);
     Assert.AreEqual(name, stack.Name);
 }
Пример #2
0
        public StackResult Resolve(IEnumerable<FileMetadata> files)
        {
            var result = new StackResult();

            var resolver = new VideoResolver(_options, _logger);

            var list = files
                .Where(i => i.IsFolder || (resolver.IsVideoFile(i.Id) || resolver.IsStubFile(i.Id)))
                .OrderBy(i => i.Id)
                .ToList();

            var expressions = _options.VideoFileStackingExpressions;

            for (var i = 0; i < list.Count; i++)
            {
                var offset = 0;

                var file1 = list[i];

                var expressionIndex = 0;
                while (expressionIndex < expressions.Count)
                {
                    var exp = expressions[expressionIndex];
                    var stack = new FileStack
                    {
                        Expression = exp
                    };

                    // (Title)(Volume)(Ignore)(Extension)
                    var match1 = FindMatch(file1, exp, offset);

                    if (match1.Success)
                    {
                        var title1 = match1.Groups[1].Value;
                        var volume1 = match1.Groups[2].Value;
                        var ignore1 = match1.Groups[3].Value;
                        var extension1 = match1.Groups[4].Value;

                        var j = i + 1;
                        while (j < list.Count)
                        {
                            var file2 = list[j];

                            if (file1.IsFolder != file2.IsFolder)
                            {
                                j++;
                                continue;
                            }

                            // (Title)(Volume)(Ignore)(Extension)
                            var match2 = FindMatch(file2, exp, offset);

                            if (match2.Success)
                            {
                                var title2 = match2.Groups[1].Value;
                                var volume2 = match2.Groups[2].Value;
                                var ignore2 = match2.Groups[3].Value;
                                var extension2 = match2.Groups[4].Value;

                                if (string.Equals(title1, title2, StringComparison.OrdinalIgnoreCase))
                                {
                                    if (!string.Equals(volume1, volume2, StringComparison.OrdinalIgnoreCase))
                                    {
                                        if (string.Equals(ignore1, ignore2, StringComparison.OrdinalIgnoreCase) &&
                                            string.Equals(extension1, extension2, StringComparison.OrdinalIgnoreCase))
                                        {
                                            if (stack.Files.Count == 0)
                                            {
                                                stack.Name = title1 + ignore1;
                                                stack.IsFolderStack = file1.IsFolder;
                                                //stack.Name = title1 + ignore1 + extension1;
                                                stack.Files.Add(file1.Id);
                                            }
                                            stack.Files.Add(file2.Id);
                                        }
                                        else 
                                        {
                                            // Sequel
                                            offset = 0;
                                            expressionIndex++;
                                            break;
                                        }
                                    }
                                    else if (!string.Equals(ignore1, ignore2, StringComparison.OrdinalIgnoreCase))
                                    {
                                        // False positive, try again with offset
                                        offset = match1.Groups[3].Index;
                                        break;
                                    }
                                    else
                                    {
                                        // Extension mismatch
                                        offset = 0;
                                        expressionIndex++;
                                        break;
                                    }
                                }
                                else
                                {
                                    // Title mismatch
                                    offset = 0;
                                    expressionIndex++;
                                    break;
                                }
                            }
                            else
                            {
                                // No match 2, next expression
                                offset = 0;
                                expressionIndex++;
                                break;
                            }

                            j++;
                        }

                        if (j == list.Count)
                        {
                            expressionIndex = expressions.Count;
                        }
                    }
                    else
                    {
                        // No match 1
                        offset = 0;
                        expressionIndex++;
                    }

                    if (stack.Files.Count > 1)
                    {
                        result.Stacks.Add(stack);
                        i += stack.Files.Count - 1;
                        break;
                    }
                }
            }

            return result;
        }
Пример #3
0
        public StackResult Resolve(IEnumerable <PortableFileInfo> files)
        {
            var result = new StackResult();

            var resolver = new VideoResolver(_options, _logger);

            var list = files
                       .Where(i => i.Type == FileInfoType.Directory || (resolver.IsVideoFile(i.FullName) || resolver.IsStubFile(i.FullName)))
                       .OrderBy(i => i.FullName)
                       .ToList();

            var expressions = _options.VideoFileStackingExpressions;

            for (var i = 0; i < list.Count; i++)
            {
                var extraFiles = new List <string>();
                var offset     = 0;

                var file1 = list[i];

                var expressionIndex = 0;
                while (expressionIndex < expressions.Count)
                {
                    var exp   = expressions[expressionIndex];
                    var stack = new FileStack
                    {
                        Expression = exp
                    };

                    // (Title)(Volume)(Ignore)(Extension)
                    var match1 = FindMatch(file1, exp, offset);

                    if (match1.Success)
                    {
                        var title1     = match1.Groups[1].Value;
                        var volume1    = match1.Groups[2].Value;
                        var ignore1    = match1.Groups[3].Value;
                        var extension1 = match1.Groups[4].Value;

                        var j = i + 1;
                        while (j < list.Count)
                        {
                            var file2 = list[j];

                            // (Title)(Volume)(Ignore)(Extension)
                            var match2 = FindMatch(file2, exp, offset);

                            if (match2.Success)
                            {
                                var title2     = match2.Groups[1].Value;
                                var volume2    = match2.Groups[2].Value;
                                var ignore2    = match2.Groups[3].Value;
                                var extension2 = match2.Groups[4].Value;

                                if (string.Equals(title1, title2, StringComparison.OrdinalIgnoreCase))
                                {
                                    if (!string.Equals(volume1, volume2, StringComparison.OrdinalIgnoreCase))
                                    {
                                        if (string.Equals(ignore1, ignore2, StringComparison.OrdinalIgnoreCase) &&
                                            string.Equals(extension1, extension2, StringComparison.OrdinalIgnoreCase))
                                        {
                                            if (stack.Files.Count == 0)
                                            {
                                                stack.Name = title1 + ignore1;
                                                //stack.Name = title1 + ignore1 + extension1;
                                                stack.Files.Add(file1.FullName);
                                            }
                                            stack.Files.Add(file2.FullName);
                                        }
                                        else
                                        {
                                            // Sequel
                                            offset = 0;
                                            expressionIndex++;
                                            break;
                                        }
                                    }
                                    else if (!string.Equals(ignore1, ignore2, StringComparison.OrdinalIgnoreCase))
                                    {
                                        // False positive, try again with offset
                                        offset = match1.Groups[3].Index;
                                        break;
                                    }
                                    else
                                    {
                                        // Extension mismatch
                                        offset = 0;
                                        expressionIndex++;
                                        break;
                                    }
                                }
                                else
                                {
                                    // Title mismatch
                                    offset = 0;
                                    expressionIndex++;
                                    break;
                                }
                            }
                            else
                            {
                                // No match 2, next expression
                                offset = 0;
                                expressionIndex++;
                                break;
                            }

                            j++;
                        }

                        if (j == list.Count)
                        {
                            expressionIndex = expressions.Count;
                        }
                    }
                    else
                    {
                        // No match 1
                        offset = 0;
                        expressionIndex++;
                    }

                    if (stack.Files.Count > 1)
                    {
                        result.Stacks.Add(stack);
                        i += stack.Files.Count - 1;
                        break;
                    }
                }
            }

            return(result);
        }