/// <summary>
        /// Query Lastfm for similar Artists
        /// </summary>
        /// <remarks>Executed via Kernel Scheduler</remarks>
        public static void QueryLastfm()
        {
            if (!ServiceManager.Get <Network>().Connected)
            {
                return;
            }

            DatabaseTrackInfo currentTrack = ServiceManager.PlayerEngine.ActiveEngine.CurrentTrack as DatabaseTrackInfo;

            if (currentTrack == null)
            {
                return;
            }

            LastfmArtistData artist = new LastfmArtistData(currentTrack.AlbumArtist);

            LastfmData <SimilarArtist> lastfmSimilarArtists;

            // Gotta catch 'em all Pattern
            try {
                lastfmSimilarArtists = artist.SimilarArtists;
            } catch (Exception e) {
                Log.Warning(e.ToString());
                return;
            }

            // Artists from LastfmQuery
            // - Numbers are filtered
            // - Ordered by Matching Score
            var lastfmArtists = lastfmSimilarArtists.Where(a => !IsNumber(a.Name)).OrderByDescending(a => a.Match).Select(a => a);

            // Artists that are present on local database
            // - Reduced by max number to get
            var newArtists = GetPresentArtists(lastfmArtists);

            Log.DebugFormat("RandomByLastfmSimilarArtists: {0} present similar Artists, adding {1} with factor {2}", weightedRandom.Count, newArtists.Count(), weightedRandom.Value(currentTrack.ArtistId));

            foreach (int currentId in newArtists.Keys)
            {
                weightedRandom.Add(currentId, newArtists[currentId], currentTrack.ArtistId);
            }

            if (weightedRandom.Count > MAX_ARTISTS)
            {
                Log.Debug("RandomByLastfmSimilarArtists: Maximum reached, clearing random artists");
                LimitList();
            }

            processedArtists.Add(currentTrack.ArtistId);
        }
示例#2
0
        private void UpdateForArtist(string artist)
        {
            try {
                LastfmArtistData artist_data = new LastfmArtistData(artist);

                // Make sure all the album art is downloaded
                foreach (SimilarArtist similar in artist_data.SimilarArtists)
                {
                    DataCore.DownloadContent(similar.SmallImageUrl);
                }

                UpdateForArtist(artist, artist_data.SimilarArtists, artist_data.TopAlbums, artist_data.TopTracks);
            } catch (Exception e) {
                Log.Exception(e);
            }
        }
示例#3
0
        private void UpdateForArtist(string artist)
        {
            try {
                LastfmArtistData artist_data = new LastfmArtistData (artist);

                // Make sure all the album art is downloaded
                foreach (SimilarArtist similar in artist_data.SimilarArtists) {
                    DataCore.DownloadContent (similar.SmallImageUrl);
                }

                UpdateForArtist (artist, artist_data.SimilarArtists, artist_data.TopAlbums, artist_data.TopTracks);
            } catch (Exception e) {
                Log.Exception (e);
            }
        }
        /// <summary>
        /// Query Lastfm for similar Artists
        /// </summary>
        /// <remarks>Executed via Kernel Scheduler</remarks>
        public static void QueryLastfm ()
        {
            if(!ServiceManager.Get<Network>().Connected)
                return;

            DatabaseTrackInfo currentTrack = ServiceManager.PlayerEngine.ActiveEngine.CurrentTrack as DatabaseTrackInfo;
            if (currentTrack == null)
                return;
            
            LastfmArtistData artist = new LastfmArtistData (currentTrack.AlbumArtist);
            
            LastfmData<SimilarArtist> lastfmSimilarArtists;
            
            // Gotta catch 'em all Pattern
            try {
                lastfmSimilarArtists = artist.SimilarArtists;
            } catch (Exception e) {
                Log.Warning (e.ToString ());
                return;
            }
            
            // Artists from LastfmQuery
            // - Numbers are filtered
            // - Ordered by Matching Score
            var lastfmArtists = lastfmSimilarArtists.Where (a => !IsNumber (a.Name)).OrderByDescending (a => a.Match).Select (a => a);
            
            // Artists that are present on local database
            // - Reduced by max number to get
            var newArtists = GetPresentArtists (lastfmArtists);
            
            Log.DebugFormat ("RandomByLastfmSimilarArtists: {0} present similar Artists, adding {1} with factor {2}", weightedRandom.Count, newArtists.Count (), weightedRandom.Value (currentTrack.ArtistId));
            
            foreach (int currentId in newArtists.Keys) {
                weightedRandom.Add (currentId, newArtists[currentId], currentTrack.ArtistId);
            }
            
            if (weightedRandom.Count > MAX_ARTISTS) {
                Log.Debug ("RandomByLastfmSimilarArtists: Maximum reached, clearing random artists");
                LimitList ();
            }
            
            processedArtists.Add (currentTrack.ArtistId);
        }