根据文件/文件夹名称将剧集分类到基于动漫的类别中

本文关键字:于动漫 动漫 分类 文件夹 文件 | 更新日期: 2023-09-27 18:28:02

我需要分析许多远程来源,并从每个特定的动漫标题中选择最好的剧集文件。决定因素主要是视频质量和文件大小。

我目前的解决方案是将一个源中的所有可用文件排序为基于动画标题的类别,然后在分析所有源后标记所有重复文件但是不同的文件名和拼写错误导致了令人不满意的误报数量

所有的源都有大量的文件,其中大部分被隔离到适当的动漫标题(但不是全部)中。我试图将所有文件分类到动漫标题列表中(我从动漫新闻网得到)。对于一个特定的文件,我将文件名拆分为基于单词的关键字,并在标题列表中查找与每个条目的匹配项。我会为匹配的文件打分,如果文件夹名称也与同一类别匹配,则会进一步提高分数。

foreach (FileInfo file in allFiles)
{
    string[] subStrings = file.Name.Split(removables, StringSplitOptions.RemoveEmptyEntries);
    // score holds a value for each title, highest score indicates closer match
    int[] score = new int[titles.Count];
    bool hasAScore = false;
    // list's length - 1 to avoid extensions from being checked
    for (int i = 0; i < titles.Count; i++)
    {
        for (int j = 0; j < subStrings.Length - 1; j++)
        {
            // @'b defines the match to be specific to whole words
            if (Regex.IsMatch(titles[i], @"'b" + subStrings[j] + @"'b", RegexOptions.IgnoreCase))
            {
                foreach (string s in file.Directory.Name.Split(removables, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (Regex.IsMatch(titles[i], @"'b" + s + @"'b", RegexOptions.IgnoreCase))
                    {
                        score[i]++;
                    }
                }               
                score[i]++;
                hasAScore = true;
                // Console.WriteLine("Found match with title '{0}' with string '{1}' from file '{2}'", titles[j], subStrings[i], file.Name);
            }
        }
    }
    if (hasAScore)
    {
        // Find the highest score in the list and use it's title value as the title of the Category
        string titleName = titles[Array.IndexOf(score, score.Max())];
        bool exists = false;
        // Check through all the categories if it already exists, otherwise add a new one
        // TODO perhaps check this in the class's constructor
        foreach (Category c in categories)
        {
            if (c.Name == titleName)
            {
                c.AddChildren(file, titleName);
                exists = true;
                break;
            }
        }
        if (!exists)
        {
            categories.Add(new Category(file, titleName));
        }
    }
    else
    {
        // Files without a score were not matched with any existing category
        notSorted++;
    }
}
return categories;
}

这导致了很多误报,因为数据库中的一些标题的名称较长,动词较小,这会提高分数。我检查了文件名和匹配标题的比例,但这对排序也没有多大帮助。

// if the percentage of word matches and total words in the title is > 80% (arbitrary value)
// boost the score
int titleWordCount = titles[i].Split(removables, StringSplitOptions.RemoveEmptyEntries).Length;
if ((100 * (score[i])/ (2 * titleWordCount)) > 80)
{
    score[i] += 2;
}

我试着只查看动漫电视节目(并避免电影、OVA发行),但结果仍然不令人满意。

大多数文件要么从Torrent下载,要么从编码器网站下载,导致文件名复杂,包括文件质量和编码器签名。

例如:

ShingekinoKyojinOVA-01(480p)[Hatsuyuki-Kaitou][D8E8CC75].mkv -- Category "Shingeki no Kyojin"
(Hi10)_Gosick_-_22_The_Christmas_Carol_Adorns_the_Happiness_by_the_Window_(BD_720p)_(Broken).mkv -- Category "Gosick"
[AnimeKens.com]_[sofcj-raws]_SnK-Oad_1_[SD-480].mkv -- Category "Shingeki no Kyojin"
Commie_Steins Gate 01 Prologue to the Beginning and End.mkv -- Category "Steins Gate"
Commie_Steins_Gate_02_BD_720p_AnimeKens.com.mkv -- Category "Steins Gate"

关于我该如何解决这个问题,有什么想法吗?有解决这类问题的开源库吗?

或者我应该实现一个机器学习模块来根据文件名预测标题?但是我不会有固定数量的输入变量。

请帮忙,如果这是问这个问题的合适地方。如果没有,请给我指正确的方向。感谢

根据文件/文件夹名称将剧集分类到基于动漫的类别中

许多年前,我不得不想出一些代码来匹配目录数据库中不同版本的书籍。一开始,不太复杂。

然后我们深入研究了实际数据。标题发生了变化(可能从"X的奇妙指南"变成了"X的新奇妙指南")。作家们从集体创作的作品中来来往往。发布服务器已更改。一本书从一个版本换到另一个版本有很多不同的方式,以至于任何完全自动化的解决方案都会产生太多的误报和误报,无论我们尝试了什么(缺少完整的映射列表,如果我们有……)

所以我们让一个人进入循环。给了他们一份候选匹配的名单,我们猜测他们可能是对的。按照排序,最好的比赛先来,然后再往下。起初,每个人都认为这对某人来说是一项糟糕的工作,但当它开始时,事实证明它既快速又简单。

在你的情况下,我会这么做。这方面的完美自动化解决方案近乎于狙击手狩猎;很难接近可靠,而且会让你沮丧,因为人们在可靠地将头衔纳入交易中是多么糟糕。如果可能的话,运行你正在做的那种计算,然后把候选匹配项放在一个人面前。根据我的经验,更快、更便宜、更好。