Exemple #1
0
        /// <summary>
        /// Does image exist with the same filename
        /// </summary>
        /// <param name="filename">Name of the File (ie a CUE file)</param>
        /// <returns>Null if not found else populated image</returns>
        public AudioMetaDataImage ImageForFilename(string filename)
        {
            AudioMetaDataImage imageMetaData = null;

            if (string.IsNullOrEmpty(filename))
            {
                return(imageMetaData);
            }
            try
            {
                var fileInfo     = new FileInfo(filename);
                var ReleaseCover = Path.ChangeExtension(filename, "jpg");
                if (File.Exists(ReleaseCover))
                {
                    using (var processor = new ImageProcessor(this.Configuration))
                    {
                        imageMetaData = new AudioMetaDataImage
                        {
                            Data     = processor.Process(File.ReadAllBytes(ReleaseCover)),
                            Type     = AudioMetaDataImageType.FrontCover,
                            MimeType = FileProcessor.DetermineFileType(fileInfo)
                        };
                    }
                }
                else
                {
                    // Is there a picture in filename folder (for the Release)
                    var pictures  = fileInfo.Directory.GetFiles("*.jpg");
                    var tagImages = new List <AudioMetaDataImage>();
                    if (pictures != null && pictures.Any())
                    {
                        FileInfo picture = null;
                        // See if there is a "cover" or "front" jpg file if so use it
                        picture = pictures.FirstOrDefault(x => x.Name.Equals("cover", StringComparison.OrdinalIgnoreCase));
                        if (picture == null)
                        {
                            picture = pictures.FirstOrDefault(x => x.Name.Equals("front", StringComparison.OrdinalIgnoreCase));
                        }
                        if (picture == null)
                        {
                            picture = pictures.First();
                        }
                        if (picture != null)
                        {
                            using (var processor = new ImageProcessor(this.Configuration))
                            {
                                imageMetaData = new AudioMetaDataImage
                                {
                                    Data     = processor.Process(File.ReadAllBytes(picture.FullName)),
                                    Type     = AudioMetaDataImageType.FrontCover,
                                    MimeType = FileProcessor.DetermineFileType(picture)
                                };
                            }
                        }
                    }
                }
            }
            catch (System.IO.FileNotFoundException)
            {
            }
            catch (Exception ex)
            {
                this.Logger.LogError(ex, ex.Serialize());
            }
            return(imageMetaData);
        }