Esempio n. 1
0
 public Interpreter()
 {
     // Do the regex compilation early to minimize perf hit on first evaluation
     LabelRegex.Match("");
 }
Esempio n. 2
0
        public static async Task <List <MediaFileInfo> > Create(string path, bool useParentFolderName, MediaType mediaType)
        {
            List <MediaFileInfo> mediaFileInfoList = new List <MediaFileInfo>();

            await Task.Run(() =>
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(path);
                FileInfo[] files            = directoryInfo.GetFiles("*.*", SearchOption.AllDirectories);

                string[] extensions = mediaType == MediaType.Person ? FileHelper.ImageFiles : FileHelper.VideoFiles;
                files = files.Where(x => extensions.Contains(x.Extension.ToUpperInvariant())).ToArray();

                for (int i = 0; i < files.Length; i++)
                {
                    FileInfo file   = files[i];
                    string fileName = Path.GetFileNameWithoutExtension(file.FullName);

                    MediaFileInfo mediaFileInfo = ViewModelSource.Create <MediaFileInfo>();
                    mediaFileInfo.FileName      = fileName;
                    mediaFileInfo.FilePath      = file.FullName;
                    mediaFileInfo.FolderName    = file.Directory.Name;
                    mediaFileInfo.FolderPath    = file.Directory.FullName;
                    mediaFileInfo.MediaItemName = useParentFolderName ? mediaFileInfo.FolderName : mediaFileInfo.FileName;

                    List <Match> matchList = new List <Match>
                    {
                        YearRegex.Match(mediaFileInfo.MediaItemName),
                        DiscRegex.Match(mediaFileInfo.MediaItemName),
                        SeasonRegex.Match(mediaFileInfo.MediaItemName),
                        EpisodeRegex.Match(mediaFileInfo.MediaItemName),
                        SeasonEpisodeRegex.Match(mediaFileInfo.MediaItemName),
                        LabelRegex.Match(mediaFileInfo.MediaItemName),
                        SourceRegex.Match(mediaFileInfo.MediaItemName),
                        WholeWordRegex.Match(mediaFileInfo.MediaItemName),
                        ResolutionRegex.Match(mediaFileInfo.MediaItemName)
                    };

                    matchList.Sort((x, y) => x.Index.CompareTo(y.Index));
                    foreach (Match match in matchList)
                    {
                        if (match.Index > 3)
                        {
                            mediaFileInfo.MediaItemName = mediaFileInfo.MediaItemName.Remove(match.Index);
                            break;
                        }
                    }

                    mediaFileInfo.MediaItemName = Regex.Replace(mediaFileInfo.MediaItemName, @"[\W_]", " ");
                    mediaFileInfo.MediaItemName = Regex.Replace(mediaFileInfo.MediaItemName, @"\s+", " ");
                    mediaFileInfo.MediaItemName = mediaFileInfo.MediaItemName.Trim();

                    if (mediaFileInfoList.FirstOrDefault(x => x.MediaItemName == mediaFileInfo.MediaItemName) == null)
                    {
                        mediaFileInfoList.Add(mediaFileInfo);
                    }

                    mediaFileInfo.PersonalInfo           = new PersonalInfo();
                    mediaFileInfo.PersonalInfo.LocalPath = mediaFileInfo.FolderPath;
                }
            });

            return(mediaFileInfoList);
        }