public static TagDetails LoadTags(string filename) { var extension = Path.GetExtension(filename); if (extension == null) { return(null); } if (extension.ToLower() != ".mp3") { return(null); } lock (_tagDetails) { if (_tagDetails.ContainsKey(filename)) { return(_tagDetails[filename]); } } var tags = BassTags.BASS_TAG_GetFromFile(filename); if (tags == null) { throw new Exception("Cannot load tags for file " + filename); } var tagDetails = new TagDetails { Title = tags.title, Artist = tags.artist, Album = tags.album, AlbumArtist = tags.albumartist, Genre = tags.genre, Gain = tags.replaygain_track_peak }; var key = tags.NativeTag("InitialKey"); if (key != "") { tagDetails.Key = key; } decimal bpm; if (decimal.TryParse(tags.bpm, out bpm)) { tagDetails.Bpm = BpmHelper.NormaliseBpm(bpm); } var duration = TimeSpan.FromSeconds(tags.duration); if (duration.TotalMilliseconds != 0) { tagDetails.Length = (decimal)duration.TotalMilliseconds / 1000; } int trackNumber; var trackNumberTag = (tags.track + "/").Split('/')[0].Trim(); if (int.TryParse(trackNumberTag, out trackNumber)) { tagDetails.TrackNumber = trackNumber; } if (tagDetails.AlbumArtist == "") { tagDetails.AlbumArtist = tagDetails.Artist; } if (tagDetails.Title.Contains("/")) { var data = tagDetails.Title.Split('/').ToList(); tagDetails.Artist = data[0].Trim(); tagDetails.Title = data[1].Trim(); } lock (_tagDetails) { if (!_tagDetails.ContainsKey(filename)) { _tagDetails.Add(filename, tagDetails); } } return(tagDetails); }
/// <summary> /// Loads any attributes stored in a the track comment tag. /// </summary> /// <param name="track">The track.</param> public static void LoadExtendedAttributes(Track track) { if (track == null) { return; } if (track.Artist == "" || track.Title == "") { return; } // DebugHelper.WriteLine("Loading Extended Attributes " + track.Description); var attributes = GetExtendedAttributes(track.Description); if (attributes.ContainsKey("FadeIn")) { track.FadeInStart = track.SecondsToSamples(ConversionHelper.ToDouble(attributes["FadeIn"])); } if (attributes.ContainsKey("FadeOut")) { track.FadeOutStart = track.SecondsToSamples(ConversionHelper.ToDouble(attributes["FadeOut"])); } if (attributes.ContainsKey("BPMAdjust")) { track.BpmAdjustmentRatio = ConversionHelper.ToDecimal(attributes["BPMAdjust"]); } if (attributes.ContainsKey("FadeInLengthInSeconds")) { track.FadeInEnd = track.FadeInStart + track.SecondsToSamples(ConversionHelper.ToDouble(attributes["FadeInLengthInSeconds"])); } if (attributes.ContainsKey("FadeOutLengthInSeconds")) { track.FadeOutEnd = track.FadeOutStart + track.SecondsToSamples(ConversionHelper.ToDouble(attributes["FadeOutLengthInSeconds"])); } if (attributes.ContainsKey("PreFadeInStartVolume")) { track.PreFadeInStartVolume = ConversionHelper.ToFloat(attributes["PreFadeInStartVolume"]) / 100; track.UsePreFadeIn = true; } if (attributes.ContainsKey("PreFadeInPosition")) { track.PreFadeInStart = track.SecondsToSamples(ConversionHelper.ToDouble(attributes["PreFadeInPosition"])); track.UsePreFadeIn = true; } if (attributes.ContainsKey("PreFadeInStart")) { track.PreFadeInStart = track.SecondsToSamples(ConversionHelper.ToDouble(attributes["PreFadeInStart"])); track.UsePreFadeIn = true; } if (attributes.ContainsKey("StartBPM")) { track.StartBpm = BpmHelper.NormaliseBpm(ConversionHelper.ToDecimal(attributes["StartBPM"])); } if (attributes.ContainsKey("EndBPM")) { track.EndBpm = BpmHelper.NormaliseBpm(ConversionHelper.ToDecimal(attributes["EndBPM"])); } if (attributes.ContainsKey("Duration")) { if (track.Length == 0) { track.Length = (long)(ConversionHelper.ToDouble(attributes["Duration"]) * 1000); } } if (attributes.ContainsKey("PowerDown")) { track.PowerDownOnEnd = ConversionHelper.ToBoolean(attributes["PowerDown"]); track.PowerDownOnEndOriginal = track.PowerDownOnEnd; } if (attributes.ContainsKey("StartLoopCount")) { track.StartLoopCount = ConversionHelper.ToInt(attributes["StartLoopCount"]); } if (attributes.ContainsKey("EndLoopCount")) { track.EndLoopCount = ConversionHelper.ToInt(attributes["EndLoopCount"]); } if (attributes.ContainsKey("SkipStart")) { track.SkipStart = track.SecondsToSamples(ConversionHelper.ToDouble(attributes["SkipStart"])); } if (attributes.ContainsKey("SkipLengthInSeconds")) { track.SkipEnd = track.SkipStart + track.SecondsToSamples(ConversionHelper.ToDouble(attributes["SkipLengthInSeconds"])); } if (attributes.ContainsKey("Rank")) { track.Rank = ConversionHelper.ToInt(attributes["Rank"], 1); } if (attributes.ContainsKey("Key")) { track.Key = attributes["Key"]; } }