public bool TryRead(string filename, out Tag tag) { if (filename == null) throw new ArgumentNullException("filename"); try { var file = new File(filename); LogWarnings(filename, file); var t = new Tag(); PopulateFromTag(file, t); PopulateFallbackValues(t); if (file.Properties != null) t.Duration = file.Properties.Duration; tag = t; return true; } catch (Exception e) { Log.Error(String.Format("Error reading M4A tag from {0}.", filename), e); tag = null; return false; } }
public void Clean(Tag tag) { if (tag == null) throw new ArgumentNullException("tag"); tag.Artist = Cleanup(tag.Artist); tag.Title = Cleanup(tag.Title); }
public Tag Read(string filename) { if (filename == null) throw new ArgumentNullException("filename"); var t = new Tag(); t.Title = Path.GetFileNameWithoutExtension(filename); t.Artist = TrackDefaults.UnknownArtist; t.Duration = GetDuration(filename); return t; }
void PopulateFromTag(File file, Tag tag) { //if (!file.TagTypes.HasFlag(TagTypes.Id3v2)) // return; tag.ImageData = GetImageData(file); // ID3v2 Tags Reference: http://id3.org/id3v2.4.0-frames tag.Artist = JoinPerformers(file.Tag.Performers); tag.Title = file.Tag.Title; tag.Year = ToStringOrDefault(file.Tag.Year); tag.Genre = file.Tag.JoinedGenres; tag.Publisher = file.Tag.Grouping; tag.Bpm = ToStringOrDefault(file.Tag.BeatsPerMinute); }
void PopulateFallbackValues(Tag tag) { tag.Artist = tag.Artist ?? TrackDefaults.UnknownArtist; tag.Title = tag.Title ?? TrackDefaults.UnknownTitle; }
Track CreateTrackFromTag(string filename, Tag tag) { foreach (var cleanup in cleanupFactory.GetCleanups()) cleanup.Clean(tag); string filenameKey; string filenameBpm; filenameParser.TryParse(filename, out filenameKey, out filenameBpm); var strKey = StringUtils.Coalesce(tag.InitialKey, filenameKey); var strBpm = StringUtils.Coalesce(tag.Bpm, filenameBpm); HarmonicKey key = keyParser.ParseHarmonicKey(strKey); double bpm; if (!Double.TryParse(strBpm, out bpm)) bpm = double.NaN; TrackImageData images = tag.ImageData != null ? imageResizer.Process(tag.ImageData) : null; var track = new Track(tag.Artist, tag.Title, key, filename, bpm, tag.Duration) { Label = tag.Publisher ?? "", Genre = tag.Genre ?? "", Year = tag.Year ?? "", Images = images }; return track; }