public static int CalculateMatchScore(AlbumModel model, MusicBrainzAlbumsResultRow result)
        {
            int score = 0;

            if (String.Equals(model.Name, result.Name, StringComparison.OrdinalIgnoreCase))
                score += 3;

            if (String.Equals(model.Artist, result.Artist, StringComparison.OrdinalIgnoreCase))
                score += 2;

            if (result.Score > 90)
                score += 2;

            if (model.SongsCount == result.NumberOfTracks)
            {
                score += 2;
            }
            else
            {
                if (Math.Abs(model.SongsCount - result.NumberOfTracks) < 2)
                    score += 1;
                else
                    score -= 1;
            }

            return score;
        }
        private async Task FindAndSetAlbumArtAsync(AlbumModel forAlbum)
        {
            string query = BuildQueryUrl(forAlbum.Name);

            var foundAlbums = await ParseResultsIntoModelsAsync(query);

            var bestMatch = foundAlbums.OrderByDescending(
                    result => ResultMatchScoreCalculator.CalculateMatchScore(forAlbum, result)).First();
            
            string albumArt = await GetAlbumArtUrl(bestMatch);

            var downloadedImage = await DownloadAlbumArtAsync(albumArt);

            forAlbum.ArtPath = await StorageHelper.SaveImageAsync(downloadedImage);

            Debug.WriteLine(albumArt);
        }
        private async Task SetAlbumArtIfExists(AlbumModel album)
        {
            var albumFolder = GetFolderPathFromFileName(album.Songs[0].Path);

            StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(albumFolder);

            if (folder != null)
            {
                var files = await folder.GetFilesAsync();

                var imageFile = files.FirstOrDefault(file => ConstantValues.FileExtensions.Images.Contains(file.FileType));

                if (imageFile != null)
                {
                    // oh my, finally we have image art
                    album.ArtPath = imageFile.Path;
                }
            }
        }
 public static int CalculateScoreFromRules(AlbumModel model, MusicBrainzAlbumsResultRow result)
 {
     return Rules.Sum(rule => rule(model, result));
 }
示例#5
0
 protected bool Equals(AlbumModel other)
 {
     return string.Equals(Name, other.Name) && string.Equals(Artist, other.Artist) && SongsCount == other.SongsCount;
 }