static internal MetadataDto Read(string filePath) { lock (_lock) { var file = new FileInfo(filePath); if (file.Exists) { var result = new MetadataDto(filePath); using (var stream = file.OpenRead()) { var document = new XmlDocument(); document.Load(stream); foreach (XmlNode node in document.SelectSingleNode("/AudioMetadata/SourceFile/IDTags").ChildNodes) { var name = node.Attributes["name"].Value; if (Map.ContainsKey(name)) { Map[name].Invoke(result, node.InnerText); } } } return(result); } else { return(null); } } }
static internal void Write(MetadataDto dto) { lock (_lock) { using (var stream = new FileStream(dto.Id, FileMode.Create, FileAccess.Write, FileShare.None)) using (var writer = new XmlTextWriter(stream, Encoding.UTF8)) { writer.Formatting = Formatting.Indented; writer.Indentation = 1; writer.IndentChar = '\t'; writer.WriteStartDocument(); writer.WriteStartElement("AudioMetadata"); writer.WriteStartElement("SourceFile"); writer.WriteStartElement("IDTags"); writer.WriteMandatoryElement(dto.Artist, ARTIST); writer.WriteMandatoryElement(dto.Title, TITLE); writer.WriteMandatoryElement(dto.Album, ALBUM); writer.WriteMandatoryElement(dto.Track, TRACK); writer.WriteMandatoryElement(dto.Year, YEAR); writer.WriteMandatoryElement(dto.Genre, GENRE); writer.WriteOptionalElement(dto.AccurateRipDiscId, ACCURATERIPDISCID); writer.WriteOptionalElement(dto.AlbumArtist, ALBUM_ARTIST); writer.WriteOptionalElement(dto.Compilation.HasValue && dto.Compilation.Value == 0 ? null : dto.Compilation, COMPILATION); writer.WriteOptionalElement(dto.Disc, DISC); writer.WriteEndDocument(); } } }
internal static void Write(MetadataDto dto) { lock (_lock) { using (var stream = new FileStream(dto.Id, FileMode.Create, FileAccess.Write, FileShare.None)) using (var writer = new XmlTextWriter(stream, Encoding.UTF8)) { writer.Formatting = Formatting.Indented; writer.Indentation = 1; writer.IndentChar = '\t'; writer.WriteStartDocument(); writer.WriteStartElement("AudioMetadata"); writer.WriteStartElement("SourceFile"); writer.WriteStartElement("IDTags"); writer.WriteMandatoryElement(dto.Artist, ARTIST); writer.WriteMandatoryElement(dto.Title, TITLE); writer.WriteMandatoryElement(dto.Album, ALBUM); writer.WriteMandatoryElement(dto.Track, TRACK); writer.WriteMandatoryElement(dto.Year, YEAR); writer.WriteMandatoryElement(dto.Genre, GENRE); writer.WriteOptionalElement(dto.AccurateRipDiscId, ACCURATERIPDISCID); writer.WriteOptionalElement(dto.AlbumArtist, ALBUM_ARTIST); writer.WriteOptionalElement(dto.Compilation.HasValue && dto.Compilation.Value == 0 ? null : dto.Compilation, COMPILATION); writer.WriteOptionalElement(dto.Disc, DISC); writer.WriteEndDocument(); } } }
internal static MetadataDto Read(string filePath) { lock (_lock) { var file = new FileInfo(filePath); if (file.Exists) { var result = new MetadataDto(filePath); using (var stream = file.OpenRead()) { var document = new XmlDocument(); document.Load(stream); foreach (XmlNode node in document.SelectSingleNode("/AudioMetadata/SourceFile/IDTags").ChildNodes) { var name = node.Attributes["name"].Value; if (Map.ContainsKey(name)) { Map[name].Invoke(result, node.InnerText); } } } return result; } else { return null; } } }
internal static IEnumerable<MetadataDto> MaterializeFor(IEnumerable<string> filePaths) { filePaths = filePaths.ToList(); if (filePaths.Any()) { var tracksPerDisc = ParseTracksPerDisc(filePaths).ToList(); var discCount = tracksPerDisc.Max(x => x.Item1); foreach (var filePath in filePaths) { MetadataDto dto= null; try { dto = MetadataStore.Read(filePath); } catch { } if (dto == null) { var discAndTrack = ParseDiscAndTrack(filePath); dto = new MetadataDto(filePath) { Track = String.Format("{0}/{1}", discAndTrack.Item2, tracksPerDisc.Single(x => x.Item1 == discAndTrack.Item1).Item2), Disc = String.Format("{0}/{1}", discAndTrack.Item1, discCount), }; } IdentityMap.Put(dto); yield return dto; } } }
static internal IEnumerable <MetadataDto> MaterializeFor(IEnumerable <string> filePaths) { filePaths = filePaths.ToList(); if (filePaths.Any()) { var tracksPerDisc = ParseTracksPerDisc(filePaths).ToList(); var discCount = tracksPerDisc.Max(x => x.Item1); foreach (var filePath in filePaths) { MetadataDto dto = null; try { dto = MetadataStore.Read(filePath); } catch { } if (dto == null) { var discAndTrack = ParseDiscAndTrack(filePath); dto = new MetadataDto(filePath) { Track = String.Format("{0}/{1}", discAndTrack.Item2, tracksPerDisc.Single(x => x.Item1 == discAndTrack.Item1).Item2), Disc = String.Format("{0}/{1}", discAndTrack.Item1, discCount), }; } IdentityMap.Put(dto); yield return(dto); } } }
static public void Save(MetadataDto dto) { MetadataStore.Write(dto); }
public static void Put(MetadataDto dto) { _metadataDtoMap[dto.Id] = dto; }