예제 #1
0
        /// <summary>
        /// Process every user defined regex, if it's invalid, remove the regex
        /// </summary>
        /// <param name="regexElements">Regex elements define control</param>
        /// <param name="dirtyTags">Tags to where to map</param>
        private void ProcessRegex(List <Website.RegularExpression> regexElements, Mp3File itemToProcess)
        {
            List <Website.RegularExpression> invalidRegexElements = null;

            // Process all regex
            foreach (var regex in regexElements)
            {
                if (string.IsNullOrEmpty(regex.Regex))
                {
                    continue;
                }

                try
                {
                    if (regex.SelectMultiple)
                    {
                        var matches = Regex.Matches(completedPage, regex.Regex);
                        foreach (Match match in matches)
                        {
                            itemToProcess.AddDirtyTag(regex.TargetTag, match.Groups[1].Value, regex.Append);
                        }
                    }
                    else
                    {
                        var match = Regex.Match(completedPage, regex.Regex);
                        if (match.Success)
                        {
                            itemToProcess.AddDirtyTag(regex.TargetTag, match.Groups[1].Value, regex.Append);
                        }
                    }
                }
                catch // invalid regex
                {
                    if (invalidRegexElements == null)
                    {
                        invalidRegexElements = new List <Website.RegularExpression>();
                    }
                    invalidRegexElements.Add(regex);
                    continue;
                }
            }

            // Remove invalid regex
            if (invalidRegexElements != null)
            {
                invalidRegexElements.ForEach(x => regexElements.Remove(x));
            }
        }
예제 #2
0
        /// <summary>
        /// Does a known mapping from the foreign JSON object to dirty tags
        /// </summary>
        /// <param name="item">The mp3file reference to add dirty tags to</param>
        /// <param name="musicbrainzJson">The raw musicbrainz api response</param>
        private void MapMusicBrainzResponseToMp3(Mp3File item, JObject musicbrainzJson)
        {
            var artistInfoJson = musicbrainzJson["artist-credit"].FirstOrDefault();
            var albumInfoJson  = musicbrainzJson["releases"].FirstOrDefault();
            var discInfoJson   = albumInfoJson["media"].FirstOrDefault();

            item.AddDirtyTag("Artists", artistInfoJson.Value <string>("name"), false);
            item.AddDirtyTag("Title", musicbrainzJson.Value <string>("title"), false);
            item.AddDirtyTag("Album", albumInfoJson.Value <string>("title"), false);
            item.AddDirtyTag("Year", albumInfoJson.Value <string>("date"), false);
            item.AddDirtyTag("Genres", "", false);
            item.AddDirtyTag("Composers", artistInfoJson.Value <string>("name"), false);
            item.AddDirtyTag("PERFORMER", artistInfoJson.Value <string>("name"), false);
            item.AddDirtyTag("AlbumArtists", artistInfoJson.Value <string>("name"), false);
            item.AddDirtyTag("Track", discInfoJson.Value <string>("position"), false);
            item.AddDirtyTag("TrackCount", discInfoJson.Value <string>("track-count"), false);
            item.AddDirtyTag("Disc", "", false);
            item.AddDirtyTag("DiscCount", discInfoJson["discs"].Count().ToString(), false);
            item.AddDirtyTag("Comment", string.Empty, false);
        }