示例#1
0
        public AudioMetaData MetaDataFromFileInfo(FileInfo fileInfo)
        {
            var justFilename = CleanString(fileInfo.Name.Replace(fileInfo.Extension, ""));

            if (IsTrckTit2(justFilename))
            {
                var Release     = fileInfo.Directory.Name;
                var ReleaseYear = SafeParser.ToYear(Release.Substring(0, 4));
                if (ReleaseYear.HasValue)
                {
                    Release = Release.Substring(5, Release.Length - 5);
                }
                var artist = fileInfo.Directory.Parent.Name;

                var title             = justFilename.Substring(2, justFilename.Length - 2);
                var artistYearRelease = CleanString(string.Format("{0} {1} {2}", artist, ReleaseYear, Release));
                if (justFilename.StartsWith(artistYearRelease) || CleanString(justFilename.Replace("The ", ""))
                    .StartsWith(CleanString(artistYearRelease.Replace("The ", ""))))
                {
                    title = CleanString(CleanString(justFilename.Replace("The ", ""))
                                        .Replace(CleanString(artistYearRelease.Replace("The ", "")), ""));
                }
                else
                {
                    var regex = new Regex(@"[0-9]{2}-[\w\s,$/.'-`#&()!]+");
                    if (regex.IsMatch(title))
                    {
                        title = fileInfo.Name.Replace(fileInfo.Extension, "");
                        title = title.Substring(6, title.Length - 6);
                        title = Regex.Replace(title, @"(\B[A-Z]+?(?=[A-Z][^A-Z])|\B[A-Z]+?(?=[^A-Z]))", " $1");
                    }
                }

                var trackNumber = SafeParser.ToNumber <short>(title.Substring(0, 2));
                return(new AudioMetaData
                {
                    Artist = artist,
                    Release = Release,
                    Year = ReleaseYear,
                    TrackNumber = trackNumber,
                    Title = CleanString(title.Replace(trackNumber.ToString("D2") + " ", ""))
                });
            }

            return(new AudioMetaData());
        }
示例#2
0
 private AudioMetaData ParseFromFilename(AudioMetaData metaData, FileInfo fileInfo)
 {
     if (this.DoParseFromFileName)
     {
         var filename       = fileInfo.Name.Replace(fileInfo.Extension, "");
         var mdFromFilename = this.FileNameHelper.MetaDataFromFilename(filename);
         if (mdFromFilename.ValidWeight < 32)
         {
             var mdFromFileInfo = FileNameHelper.MetaDataFromFileInfo(fileInfo);
             if (mdFromFileInfo.ValidWeight > mdFromFilename.ValidWeight)
             {
                 mdFromFilename = mdFromFileInfo;
             }
         }
         if ((mdFromFilename.Year ?? 0) < 1)
         {
             mdFromFilename.Year = SafeParser.ToYear(fileInfo.Directory.Name.Substring(0, 4));
         }
         return(MergeAudioData(this.Configuration, metaData, mdFromFilename));
     }
     return(metaData);
 }