Пример #1
0
        /// <summary>
        /// Finds similar files by looking at the file path and comparing it to a showname
        /// </summary>
        /// <param name="Basepath">basepath of the show</param>
        /// <param name="showname">name of the show to filter</param>
        /// <param name="source">source files</param>
        /// <returns>a list of matches</returns>
        public List <MediaFile> FindSimilarByName(string showname)
        {
            List <MediaFile> matches = new List <MediaFile>();

            showname = showname.ToLower();
            //whatever, just check path and file path if it contains the showname
            foreach (MediaFile mediaFile in this.mediaFiles)
            {
                string lowerCaseFilename = mediaFile.Filename.ToLower();

                //try to extract the name from a shortcut, i.e. sga for Stargate Atlantis
                string noWordCharPattern = "[^\\w]";
                Match  findWhitespaces   = Regex.Match(lowerCaseFilename, noWordCharPattern, RegexOptions.IgnoreCase);
                if (findWhitespaces != null && findWhitespaces.Success)
                {
                    string firstWord = lowerCaseFilename.Substring(0, findWhitespaces.Index);
                    if (firstWord.Length > 0 && Helper.ContainsLetters(firstWord, showname))
                    {
                        //FIXME: this should probably be removed, because I can think of a thousand times where this will break
                        matches.Add(mediaFile);
                        continue;
                    }
                }

                //now check if whole showname is in the file path
                string CleanupRegex = Helper.ReadProperty(ConfigKeyConstants.REGEX_SHOWNAME_CLEANUP_KEY);
                lowerCaseFilename = Regex.Replace(lowerCaseFilename, CleanupRegex, " ");
                if (lowerCaseFilename.Contains(showname))
                {
                    matches.Add(mediaFile);
                    continue;
                }

                string[] parentFolders = Helper.getParentFolderNames(mediaFile.FilePath.Path);
                //or in some top folder
                foreach (string str in parentFolders)
                {
                    lowerCaseFilename = str.ToLower();
                    lowerCaseFilename = Regex.Replace(lowerCaseFilename, CleanupRegex, " ");
                    if (lowerCaseFilename.Contains(showname))
                    {
                        matches.Add(mediaFile);
                        break;
                    }
                }
            }
            return(matches);
        }
Пример #2
0
        /// <summary>
        /// Finds similar files by looking at the filename and comparing it to a showname
        /// </summary>
        /// <param name="Basepath">basepath of the show</param>
        /// <param name="Showname">name of the show to filter</param>
        /// <param name="source">source files</param>
        /// <returns>a list of matches</returns>
        public List <InfoEntry> FindSimilarByName(string Showname)
        {
            List <InfoEntry> matches = new List <InfoEntry>();

            Showname = Showname.ToLower();
            //whatever, just check path and filename if it contains the showname
            foreach (InfoEntry ie in this.episodes)
            {
                string[] folders   = Helper.splitFilePath(ie.FilePath.Path);
                string   processed = ie.Filename.ToLower();

                //try to extract the name from a shortcut, i.e. sga for Stargate Atlantis
                string pattern = "[^\\w]";
                Match  m       = Regex.Match(processed, pattern, RegexOptions.IgnoreCase);
                if (m != null && m.Success)
                {
                    string abbreviation = processed.Substring(0, m.Index);
                    if (abbreviation.Length > 0 && Helper.ContainsLetters(abbreviation, Showname))
                    {
                        matches.Add(ie);
                        continue;
                    }
                }

                //now check if whole showname is in the filename
                string CleanupRegex = Helper.ReadProperty(Config.CleanupRegex);
                processed = Regex.Replace(processed, CleanupRegex, " ");
                if (processed.Contains(Showname))
                {
                    matches.Add(ie);
                    continue;
                }

                //or in some top folder
                foreach (string str in folders)
                {
                    processed = str.ToLower();
                    processed = Regex.Replace(processed, CleanupRegex, " ");
                    if (processed.Contains(Showname))
                    {
                        matches.Add(ie);
                        break;
                    }
                }
            }
            return(matches);
        }