public string ExtractSeriesName(InfoEntry ie)
        {
            reset();
            this.ie = ie;
            // Read plain filename
            string filename = System.IO.Path.GetFileNameWithoutExtension(ie.Filename);

            filename = NameCleanup.RemoveReleaseGroupTag(filename);
            folders  = Filepath.extractFoldernamesFromPath(ie.FilePath.Path);
            if (ie.InSeasonFolder && folders.Length > 2)
            {
                if (!Regex.IsMatch(folders[folders.Length - 2], pathBlacklist, RegexOptions.IgnoreCase))
                {
                    return(folders[folders.Length - 2]);
                }
            }
            extractNameFromSeasonsFolder();
            extractNameFromString(filename);
            if (folders.Length != 0)
            {
                extractNameFromString(folders[folders.Length - 1]);
            }
            fallbackFolderNames();
            name = NameCleanup.Postprocessing(name);
            if (name == null)
            {
                return("");
            }
            return(name);
        }
Exemple #2
0
        //NOTE: Need a feature to detect if the sequel name is already contained within the filename but was found somewhere else(eg directory) and added to the end again, e.g. "Hackers 2 Operation Takedown 2"
        public string ExtractMovieName(InfoEntry ie)
        {
            reset();
            this.ie = ie;
            name    = ie.FilePath.Name;
            folders = new List <string>(Filepath.extractFoldernamesFromPath(ie.FilePath.Path));

            //folderlevels are used to see which directory contains the video name, so we can set ie.extractednamelevel for path creation
            List <int> folderlevels = new List <int>();
            int        origcount    = folders.Count;

            if (Regex.IsMatch(name, filenameBlacklist, RegexOptions.IgnoreCase))
            {
                filenameBlacklisted = true;
                //must be atleast 1 then
                ie.ExtractedNameLevel = 1;
            }

            //Remove all illegal paths
            int j = 0;

            for (int i = 0; i < folders.Count; i++)
            {
                if (Regex.IsMatch(folders[i], pathBlacklist, RegexOptions.IgnoreCase))
                {
                    folders.RemoveAt(i);
                    i--;
                }
                else
                {
                    folderlevels.Add(origcount - j);
                }
                j++;
            }
            if (filenameBlacklisted && folders.Count == 0)
            {
                return("Not Recognized");
            }
            if (!filenameBlacklisted)
            {
                folders.Add(ie.FilePath.Name);
                folderlevels.Add(0);
            }


            //The idea here is to test if the current name might be a better name instead of the previous one
            //We go upwards and try to find part and sequel numbers, as well as movie name. Those might be from different folders, so we need to check all legit ones

            //Clean first name (sequel and part should still be -1
            name = "";
            for (int i = folders.Count - 1; i >= 0; i--)
            {
                string testname   = folders[i];
                int    testpart   = -1;
                int    testsequel = -1;

                //Test for sample
                if (testname.ToLower().Contains("sample"))
                {
                    name = "Sample";
                    return(name);
                }
                testname = NameCleanup.RemoveReleaseGroupTag(testname);

                int firsttag = testname.Length;
                //remove tags and store the first occurence of a tag
                //since we may miss a few tags, the string after the first occurence of a tag is removed later (not now since it may
                //contain additional information). Tags need to be removed before part and sequel detection, to avoid detecting things like 720p
                foreach (string s in MovieTagPatterns)
                {
                    Match m = Regex.Match(testname, s, RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        if (m.Index < firsttag)
                        {
                            firsttag = m.Index;
                        }
                        testname = testname.Substring(0, m.Index) + testname.Substring(m.Index + m.Length, testname.Length - (m.Index + m.Length));
                    }
                }

                testpart = ExtractPartNumber(ref testname, ref firsttag);
                if (testpart != -1)
                {
                    ie.IsMultiFileMovie = true;
                }

                testsequel = ExtractSequelNumber(ref testname, ref firsttag);

                //now after recognition of part and sequel numbers, remove the rest too
                testname = testname.Substring(0, firsttag);
                testname = NameCleanup.Postprocessing(testname);

                //Some counterchecks against previous result here
                if (testpart != -1 && part == -1)
                {
                    part = testpart;
                    ie.ExtractedNameLevel = folderlevels[i];
                }
                if (testsequel != -1 && sequelNumber == -1)
                {
                    sequelNumber = testsequel;
                }
                if (name == "" || Helper.InitialsMatch(testname, name))
                {
                    name = testname;
                }
            }

            if (sequelNumber != -1)
            {
                name += " " + sequelNumber;
            }
            if (part != -1)
            {
                name += " CD" + part;
            }
            return(name);
        }