示例#1
0
 public IArtistApi LastFmArtistRepository()
 {
     if (this._artistApi == null)
     {
         this._artistApi = _lastfmClient.Artist;
     }
     return(_artistApi);
 }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LastFmApi"/> class.
        /// </summary>
        /// <param name="config">The config.</param>
        public LastFmApi(ILastFmConfig config)
        {
            Config = config;

            Track  = new TrackApi(this);
            Tag    = new TagApi(this);
            Album  = new AlbumApi(this);
            Artist = new ArtistApi(this);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LastFmApi"/> class.
        /// </summary>
        /// <param name="config">The config.</param>
        public LastFmApi(ILastFmConfig config)
        {
            Config = config;

            Track = new TrackApi(this);
            Tag = new TagApi(this);
            Album = new AlbumApi(this);
            Artist = new ArtistApi(this);
        }
示例#4
0
 public ScrobblerService(ICredentialHelper credentialHelper)
 {
     _credentialHelper = credentialHelper;
     _auth             = new LastAuth(ApiKeys.LastFmId, ApiKeys.LastFmSecret);
     _albumApi         = new AlbumApi(_auth);
     _artistApi        = new ArtistApi(_auth);
     _chartApi         = new ChartApi(_auth);
     _trackApi         = new TrackApi(_auth);
     _userApi          = new UserApi(_auth);
     GetSessionTokenAsync();
 }
示例#5
0
 public ScrobblerService()
 {
     //  _credentialHelper = credentialHelper;
     _auth      = new LastAuth(ApiKeys.LastFmId, ApiKeys.LastFmSecret);
     _albumApi  = new AlbumApi(_auth);
     _artistApi = new ArtistApi(_auth);
     _chartApi  = new ChartApi(_auth);
     _trackApi  = new TrackApi(_auth);
     // _userApi = new UserApi(_auth);
     // loadthis();
 }
示例#6
0
        private async Task <Dictionary <string, HashSet <string> > > GetGenres(HashSet <string> artistIds)
        {
            const int MaxLimit = 50;

            Dictionary <string, HashSet <string> > genres = new Dictionary <string, HashSet <string> >();

            List <string>          artistIdsList = artistIds.ToList();
            List <Task <dynamic> > tasks         = new List <Task <dynamic> >();

            for (int index = 0; index < artistIdsList.Count; index += MaxLimit)
            {
                List <string> subset    = artistIdsList.GetRange(index, Math.Min(MaxLimit, artistIds.Count - index));
                ArtistApi     artistApi = new ArtistApi()
                {
                    AuthorizationHeader = new AuthorizationHeader(await this.RunAsync(this.AccessTokenTask))
                };

                tasks.Add(artistApi.GetArtists(subset));
            }

            if (!tasks.Any())
            {
                return(genres);
            }

            List <dynamic> items = new List <dynamic>();

            foreach (dynamic x in await Task.WhenAll(tasks))
            {
                items.AddRange(x.artists);
            }

            foreach (dynamic x in items)
            {
                string artistId = x.id;
                IEnumerable <string> newGenres  = x.genres.ToObject <IEnumerable <string> >();
                HashSet <string>     genresHash = new HashSet <string>();
                if (newGenres.Any())
                {
                    genresHash.UnionWith(newGenres.Select(CultureInfo.CurrentCulture.TextInfo.ToTitleCase));
                }
                else
                {
                    genresHash.Add("(Unclassified)");
                }

                genres.Add(artistId, genresHash);
            }

            return(genres);
        }
示例#7
0
        public async Task <OperationResult <IEnumerable <ArtistSearchResult> > > PerformArtistSearch(string query, int resultsCount)
        {
            try
            {
                var cacheKey = $"uri:lastfm:artistsearch:{ query.ToAlphanumericName() }";
                var data     = await CacheManager.GetAsync <ArtistSearchResult>(cacheKey, async() =>
                {
                    Logger.LogTrace("LastFmHelper:PerformArtistSearch:{0}", query);
                    var auth     = new LastAuth(ApiKey.Key, ApiKey.KeySecret);
                    var albumApi = new ArtistApi(auth);
                    var response = await albumApi.GetInfoAsync(query);
                    if (!response.Success)
                    {
                        return(null);
                    }
                    var lastFmArtist = response.Content;
                    var result       = new ArtistSearchResult
                    {
                        ArtistName    = lastFmArtist.Name,
                        LastFMId      = lastFmArtist.Id,
                        MusicBrainzId = lastFmArtist.Mbid,
                        Bio           = lastFmArtist.Bio != null ? lastFmArtist.Bio.Content : null
                    };
                    if (lastFmArtist.Tags != null)
                    {
                        result.Tags = lastFmArtist.Tags.Select(x => x.Name).ToList();
                    }
                    // No longer fetching/consuming images LastFm says is violation of ToS ; https://getsatisfaction.com/lastfm/topics/api-announcement-dac8oefw5vrxq
                    if (lastFmArtist.Url != null)
                    {
                        result.Urls = new[] { lastFmArtist.Url.ToString() };
                    }
                    return(result);
                }, "uri:metadata");

                return(new OperationResult <IEnumerable <ArtistSearchResult> >
                {
                    IsSuccess = data != null,
                    Data = new[] { data }
                });
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, ex.Serialize());
            }

            return(new OperationResult <IEnumerable <ArtistSearchResult> >());
        }
示例#8
0
        public async Task <OperationResult <IEnumerable <ArtistSearchResult> > > PerformArtistSearch(string query, int resultsCount)
        {
            try
            {
                this.Logger.LogTrace("LastFmHelper:PerformArtistSearch:{0}", query);
                var auth     = new LastAuth(this.ApiKey.Key, this.ApiKey.KeySecret);
                var albumApi = new ArtistApi(auth);
                var response = await albumApi.GetInfoAsync(query);

                if (!response.Success)
                {
                    return(new OperationResult <IEnumerable <ArtistSearchResult> >());
                }
                var lastFmArtist = response.Content;
                var result       = new ArtistSearchResult
                {
                    ArtistName    = lastFmArtist.Name,
                    LastFMId      = lastFmArtist.Id,
                    MusicBrainzId = lastFmArtist.Mbid,
                    Bio           = lastFmArtist.Bio != null ? lastFmArtist.Bio.Content : null
                };
                if (lastFmArtist.Tags != null)
                {
                    result.Tags = lastFmArtist.Tags.Select(x => x.Name).ToList();
                }
                if (lastFmArtist.MainImage != null && (lastFmArtist.MainImage.ExtraLarge != null || lastFmArtist.MainImage.Large != null))
                {
                    result.ArtistThumbnailUrl = (lastFmArtist.MainImage.ExtraLarge ?? lastFmArtist.MainImage.Large).ToString();
                }
                if (lastFmArtist.Url != null)
                {
                    result.Urls = new string[] { lastFmArtist.Url.ToString() };
                }
                return(new OperationResult <IEnumerable <ArtistSearchResult> >
                {
                    IsSuccess = response.Success,
                    Data = new List <ArtistSearchResult> {
                        result
                    }
                });
            }
            catch (Exception ex)
            {
                this.Logger.LogError(ex, ex.Serialize());
            }
            return(new OperationResult <IEnumerable <ArtistSearchResult> >());
        }