public async Task Scrobble() { InProgress = true; var appsettings = new ApplicationSettingsService(); var apikey = appsettings.Get <string>("apikey"); var apisecret = appsettings.Get <string>("apisecret"); var username = appsettings.Get <string>("username"); var pass = appsettings.Get <string>("pass"); var auth = new LastAuth(apikey, apisecret); await auth.GetSessionTokenAsync(username, pass); var trackApi = new Core.Api.TrackApi(auth); var scrobble = new Scrobble(Artist, Album, Track, DateTime.UtcNow) { AlbumArtist = AlbumArtist }; var response = await trackApi.ScrobbleAsync(scrobble); Successful = response.Success; InProgress = false; }
public async Task UpdateLastFm() { try { _lastAuth = new LastAuth(LAST_FM_API_KEY, LAST_FM_API_SECRET); var session = _settingsService.GetNoCache <LastUserSession>(LAST_FM_USER_SESSION_PARAMETER); if (session == null) { _lastAuth = null; _scrobbler = null; return; } _lastAuth.LoadSession(session); #if WINDOWS_UWP _scrobbler = new Scrobbler(_lastAuth); #else var dbFile = await ApplicationData.Current.LocalFolder.CreateFileAsync( "scrobbler.db", CreationCollisionOption.OpenIfExists); _scrobbler = new SQLiteScrobbler(_lastAuth, dbFile.Path); #endif } catch (Exception ex) { _lastAuth = null; _scrobbler = null; _logService.LogException(ex); } }
/// <summary> /// Initializes a new instance of the ViewModelLocator class. /// </summary> public ViewModelLocator() { ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); var auth = new LastAuth(LastFm.TEST_APIKEY, LastFm.TEST_APISECRET); SimpleIoc.Default.Register <ILastAuth>(() => auth); SimpleIoc.Default.Register <MainViewModel>(); }
/// <summary> /// Initializes a new instance of the ViewModelLocator class. /// </summary> public ViewModelLocator() { ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); var auth = new LastAuth("a6ab4b9376e54cdb06912bfbd9c1f288", "3aa7202fd1bc6d5a7ac733246cbccc4b"); SimpleIoc.Default.Register <ILastAuth>(() => auth); SimpleIoc.Default.Register <MainViewModel>(); }
public LastFMContext(Context context) { Context = context; //SourceUser = "******"; LastAuth auth = new LastAuth(Token.CLIENT, Token.SECRET); client = new LastfmClient(auth); ReythScrobbles = new List <LastTrack>(); GinaScrobbles = new List <LastTrack>(); }
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(); }
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(); }
public async Task GetInfo() { InProgress = true; var appsettings = new ApplicationSettingsService(); var apikey = appsettings.Get <string>("apikey"); var apisecret = appsettings.Get <string>("apisecret"); var username = appsettings.Get <string>("username"); var pass = appsettings.Get <string>("pass"); var auth = new LastAuth(apikey, apisecret); var response = await auth.GetSessionTokenAsync(username, pass); if (response.Success && auth.Authenticated) { ClearLists(); var artistApi = new Core.Api.ArtistApi(auth); var topTracks = await artistApi.GetTopTracksForArtistAsync(ArtistName); if (topTracks.Success) { TopTracks = topTracks; } var topAlbums = await artistApi.GetTopAlbumsForArtistAsync(ArtistName); if (topAlbums.Success) { TopAlbums = topAlbums; } var similarArtists = await artistApi.GetSimilarArtistsAsync(ArtistName, false, 20); if (similarArtists.Success) { SimilarArtists = similarArtists; } var artist = await artistApi.GetArtistInfoAsync(ArtistName); if (artist.Success) { LastArtist = artist.Content; } } InProgress = false; }
private async void Window_Loaded(object sender, RoutedEventArgs e) { SourceUser = "******"; LastAuth auth = new LastAuth(Token.CLIENT, Token.SECRET); client = new LastfmClient(auth); ReythScrobbles = new ObservableCollection <LastTrack>(); GinaScrobbles = new ObservableCollection <LastTrack>(); leftListView.ItemsSource = ReythScrobbles; rightListView.ItemsSource = GinaScrobbles; await Authenticate(); ReloadScrobbles(); }
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> >()); }
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> >()); }
private async Task Authenticate() { var appsettings = new ApplicationSettingsService(); var apikey = appsettings.Get <string>("apikey"); var apisecret = appsettings.Get <string>("apisecret"); var username = appsettings.Get <string>("username"); var pass = appsettings.Get <string>("pass"); var auth = new LastAuth(apikey, apisecret); InProgress = true; await auth.GetSessionTokenAsync(username, pass); InProgress = false; Auth = auth; }
public Search(string ApiKey, string ApiSecret, IUserApi userApi = null, ILibraryApi libraryApi = null) { this.ApiKey = ApiKey; this.ApiSecret = ApiSecret; Auth = new LastAuth(ApiKey, ApiSecret); if (userApi == null) { this.userApi = new IF.Lastfm.Core.Api.UserApi(Auth); } else { this.userApi = userApi; } if (libraryApi == null) { this.libraryApi = new IF.Lastfm.Core.Api.LibraryApi(); } else { this.libraryApi = libraryApi; } }
public virtual void Initialise() { var testApiKey = "59dd1140db864fd4a68ca820709eaf98"; var testApiSecret = "fa45357dcd914671a22def63cbe79a46"; var testUserSession = new LastUserSession { IsSubscriber = false, Token = "071a119a9aac4942b1b05328a5591f55", Username = "******" }; MockAuth = new Mock <ILastAuth>(); MockAuth.SetupGet(m => m.Authenticated).Returns(true); MockAuth.SetupGet(m => m.ApiKey).Returns(testApiKey); var stubAuth = new LastAuth(testApiKey, testApiSecret); stubAuth.LoadSession(testUserSession); MockAuth.Setup(m => m.GenerateMethodSignature(It.IsAny <string>(), It.IsAny <Dictionary <string, string> >())) .Returns <string, Dictionary <string, string> >((method, parameters) => stubAuth.GenerateMethodSignature(method, parameters)); FakeResponseHandler = new QueueFakeResponseHandler(); Scrobbler = GetScrobbler(); }
public LastFMScrobbler(string apiKey, string apiSig) { _auth = new LastAuth(apiKey, apiSig); }
public void Logout() { _credentialHelper.DeleteCredentials("lastfm"); _auth = new LastAuth(ApiKeys.LastFmId, ApiKeys.LastFmSecret); OnAuthStateChanged(); }
public LastfmClient(string apiKey, string apiSecret, HttpClient httpClient = null, ScrobblerBase scrobbler = null) : base(httpClient) { _lastAuth = new LastAuth(apiKey, apiSecret, httpClient); _scrobbler = scrobbler; }
public LastfmClient(LastAuth auth, HttpClient httpClient = null, ScrobblerBase scrobbler = null) : base(httpClient) { _lastAuth = auth; _scrobbler = scrobbler; }
public LastfmClient(string apiKey, string apiSecret, HttpClient httpClient = null) : base(httpClient) { _lastAuth = new LastAuth(apiKey, apiSecret, httpClient); }
public async Task <IEnumerable <AudioMetaData> > TracksForRelease(string artist, string Release) { if (string.IsNullOrEmpty(artist) || string.IsNullOrEmpty(Release)) { return(null); } var result = new List <AudioMetaData>(); try { var responseCacheKey = string.Format("uri:lastFm:artistAndRelease:{0}:{1}", artist, Release); LastAlbum releaseInfo = this.CacheManager.Get <LastAlbum>(responseCacheKey); if (releaseInfo == null) { try { var auth = new LastAuth(this.ApiKey.Key, this.ApiKey.KeySecret); var albumApi = new AlbumApi(auth); // this is an unauthenticated call to the API var response = await albumApi.GetInfoAsync(artist, Release); releaseInfo = response.Content; if (releaseInfo != null) { this.CacheManager.Add(responseCacheKey, releaseInfo); } } catch { this.Logger.LogWarning("LastFmAPI: Error Getting Tracks For Artist [{0}], Release [{1}]", artist, Release); } } if (releaseInfo != null && releaseInfo.Tracks != null && releaseInfo.Tracks.Any()) { var tracktotal = releaseInfo.Tracks.Where(x => x.Rank.HasValue).Max(x => x.Rank); List <AudioMetaDataImage> images = null; if (releaseInfo.Images != null) { images = releaseInfo.Images.Select(x => new AudioMetaDataImage { Url = x.AbsoluteUri }).ToList(); } foreach (var track in releaseInfo.Tracks) { result.Add(new AudioMetaData { Artist = track.ArtistName, Release = track.AlbumName, Title = track.Name, Year = releaseInfo.ReleaseDateUtc != null ? (int?)releaseInfo.ReleaseDateUtc.Value.Year : null, TrackNumber = (short?)track.Rank, TotalTrackNumbers = tracktotal, Time = track.Duration, LastFmId = track.Id, ReleaseLastFmId = releaseInfo.Id, ReleaseMusicBrainzId = releaseInfo.Mbid, MusicBrainzId = track.Mbid, Images = images }); } } } catch (System.Exception ex) { this.Logger.LogError(ex, string.Format("LastFm: Error Getting Tracks For Artist [{0}], Release [{1}]", artist, Release)); } return(result); }
public void Initialise() { Auth = new LastAuth(LastFm.TEST_APIKEY, LastFm.TEST_APISECRET); Auth.GetSessionTokenAsync(INTEGRATION_TEST_USER, INTEGRATION_TEST_PASSWORD).Wait(); }
public virtual void Initialise() { var testApiKey = "59dd1140db864fd4a68ca820709eaf98"; var testApiSecret = "fa45357dcd914671a22def63cbe79a46"; var testUserSession = new LastUserSession { IsSubscriber = false, Token = "071a119a9aac4942b1b05328a5591f55", Username = "******" }; MockAuth = new Mock<ILastAuth>(); MockAuth.SetupGet(m => m.Authenticated).Returns(true); MockAuth.SetupGet(m => m.ApiKey).Returns(testApiKey); var stubAuth = new LastAuth(testApiKey, testApiSecret); stubAuth.LoadSession(testUserSession); MockAuth.Setup(m => m.GenerateMethodSignature(It.IsAny<string>(), It.IsAny<Dictionary<string, string>>())) .Returns<string, Dictionary<string, string>>((method, parameters) => stubAuth.GenerateMethodSignature(method, parameters)); FakeResponseHandler = new QueueFakeResponseHandler(); Scrobbler = GetScrobbler(); }