private bool ValidateTag(IId3Tag id3Tag) { if (id3Tag == null) { return(false); } if (id3Tag.Artists == null) { return(false); } if (string.IsNullOrEmpty(id3Tag.Artists.TextValue)) { return(false); } if (id3Tag.Album == null) { return(false); } if (string.IsNullOrEmpty(id3Tag.Album.TextValue)) { return(false); } if (id3Tag.Title == null) { return(false); } if (string.IsNullOrEmpty(id3Tag.Title.TextValue)) { return(false); } return(true); }
public FileAnalysed AnalyseFile(IMp3Stream mp3File, string filePath) { if (mp3File == null) { throw new ArgumentNullException(nameof(mp3File)); } if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException(nameof(filePath)); } if (!_fileSystem.FileExists(filePath)) { throw new ArgumentException("File does not exist.", nameof(filePath)); } if (AnalyserProgress != null) { AnalyserProgress(this, new AnalyserProgressEventArgs(filePath)); } if (!mp3File.HasTags) { return new FileAnalysed { Artist = null, Album = null, Title = null, FilePath = filePath, Id3TagIncomplete = true } } ; var availableTagVersions = mp3File.AvailableTagVersions.OrderBy(v => v.Major).LastOrDefault(); if (availableTagVersions == null) { return new FileAnalysed { Artist = null, Album = null, Title = null, FilePath = filePath, Id3TagIncomplete = true } } ; IId3Tag id3Tag = null; try { id3Tag = mp3File.GetTag(availableTagVersions.Major, availableTagVersions.Minor); } catch {} bool isPartOfCollection = false; if (id3Tag == null || id3Tag.Band == null || id3Tag.Artists == null) { isPartOfCollection = false; } else { isPartOfCollection = !string.IsNullOrEmpty(id3Tag.Band.TextValue) && id3Tag.Band.TextValue.ToLower() != id3Tag.Artists.TextValue.ToLower() && id3Tag.Band == _collectionMarker; } var tagComplete = ValidateTag(id3Tag); return(new FileAnalysed { Artist = (id3Tag == null || id3Tag.Artists == null)?null: id3Tag.Artists.TextValue, Album = (id3Tag == null || id3Tag.Album == null) ?null :id3Tag.Album.TextValue, Title = (id3Tag == null || id3Tag.Title == null)?null:id3Tag.Title.TextValue, Track = (id3Tag == null || id3Tag.Track == null)?null:id3Tag.Track.TextValue, FilePath = filePath, InCollectionPath = _collectionPaths.Any(c => filePath.ToLower().Contains(c.ToLower())), MarkedAsPartOfCollection = isPartOfCollection, Id3TagIncomplete = !tagComplete }); }