public async Task <IEnumerable <MetaDataItem> > GetMetaData(string fileName) { var result = new List <MetaDataItem>(); var metaData = default(IDictionary <string, string>); foreach (var extractor in this.Extractors) { if (!extractor.Extract(fileName, out metaData)) { continue; } foreach (var key in metaData.Keys) { var name = default(string); if (!CommonMetaData.Lookup.TryGetValue(key, out name)) { name = key; } result.Add(this.GetMetaData(name, metaData[key])); } break; } if (this.LooseImages.Value) { foreach (var type in new[] { ArtworkType.FrontCover, ArtworkType.BackCover }) { if (!ArtworkTypes.HasFlag(type)) { continue; } var value = this.ArtworkProvider.Find(fileName, type); if (!string.IsNullOrEmpty(value) && File.Exists(value)) { if (this.CopyImages.Value) { value = await this.ImportImage(value, value).ConfigureAwait(false); } result.Add(new MetaDataItem() { Name = Enum.GetName(typeof(ArtworkType), type), Value = value, Type = MetaDataItemType.Image }); } } } return(result); }
private static async Task <bool> ReadEmbedded(TagLibMetaDataSource source, IList <MetaDataItem> metaDatas, File file) { var types = ArtworkType.None; try { if (file.InvariantStartPosition > TagLibMetaDataSource.MAX_TAG_SIZE) { Logger.Write(typeof(ImageManager), LogLevel.Warn, "Not importing images from file \"{0}\" due to size: {1} > {2}", file.Name, file.InvariantStartPosition, TagLibMetaDataSource.MAX_TAG_SIZE); return(false); } var pictures = file.Tag.Pictures; if (pictures != null) { foreach (var fallback in new[] { false, true }) { foreach (var picture in pictures.OrderBy(picture => GetPicturePriority(picture))) { var type = GetArtworkType(picture.Type, fallback); if (!ArtworkTypes.HasFlag(type) || types.HasFlag(type)) { continue; } if (fallback) { if (!string.IsNullOrEmpty(picture.Description)) { //If we're in fallback (i.e the picture type isn't right) then ignore "pictures" with a description as it likely means the data has a specific purpose. Logger.Write(typeof(ImageManager), LogLevel.Warn, "Not importing image from file \"{0}\" due to description: {1}", file.Name, picture.Description); continue; } Logger.Write(typeof(ImageManager), LogLevel.Warn, "Importing image from file \"{0}\" with bad type: {1}.", file.Name, Enum.GetName(typeof(PictureType), picture.Type)); source.AddWarning(file.Name, string.Format("Image has bad type: {0}.", Enum.GetName(typeof(PictureType), picture.Type))); } if (string.IsNullOrEmpty(picture.MimeType)) { Logger.Write(typeof(ImageManager), LogLevel.Warn, "Importing image from file \"{0}\" with empty mime type.", file.Name); source.AddWarning(file.Name, "Image has empty mime type."); } else if (!MimeMapping.Instance.IsImage(picture.MimeType)) { Logger.Write(typeof(ImageManager), LogLevel.Warn, "Importing image from file \"{0}\" with bad mime type: {1}", file.Name, picture.MimeType); source.AddWarning(file.Name, string.Format("Image has bad mime type: {0}", picture.MimeType)); } if (picture.Data.Count > source.MaxImageSize.Value * 1024000) { Logger.Write(typeof(ImageManager), LogLevel.Warn, "Not importing image from file \"{0}\" due to size: {1} > {2}", file.Name, picture.Data.Count, source.MaxImageSize.Value * 1024000); source.AddWarning(file.Name, string.Format("Image was not imported due to size: {0} > {1}", picture.Data.Count, source.MaxImageSize.Value * 1024000)); continue; } metaDatas.Add(new MetaDataItem(Enum.GetName(typeof(ArtworkType), type), MetaDataItemType.Image) { Value = await ImportImage(file, picture, type, false).ConfigureAwait(false) }); if (ArtworkTypes.HasFlag(types |= type)) { //We have everything we need. return(true); } } } } } catch (Exception e) { Logger.Write(typeof(ImageManager), LogLevel.Warn, "Failed to read pictures: {0} => {1}", file.Name, e.Message); } return(types != ArtworkType.None); }