private async void PlaybackService_PlaybackSuccess(bool isPlayingPreviousTrack)
        {
            if (this.SignInState == SignInState.SignedIn && this.isEnabled)
            {
                // As soon as a track starts playing, send a Now Playing request.
                this.trackStartTime = DateTime.Now;
                this.canScrobble    = true;
                string artist     = this.playbackService.PlayingTrack.ArtistName != Defaults.UnknownArtistString ? this.playbackService.PlayingTrack.ArtistName : string.Empty;
                string trackTitle = this.playbackService.PlayingTrack.TrackTitle;
                string albumTitle = this.playbackService.PlayingTrack.AlbumTitle != Defaults.UnknownAlbumString ? this.playbackService.PlayingTrack.AlbumTitle : string.Empty;

                if (!string.IsNullOrEmpty(artist) && !string.IsNullOrEmpty(trackTitle))
                {
                    bool isSuccess = await LastfmAPI.TrackUpdateNowPlaying(
                        this.username,
                        this.password,
                        this.sessionKey,
                        artist,
                        trackTitle,
                        albumTitle);

                    if (isSuccess)
                    {
                        LogClient.Instance.Logger.Info("Successfully updated Now Playing for track '{0} - {1}'", artist, trackTitle);
                    }
                    else
                    {
                        LogClient.Instance.Logger.Error("Could not update Now Playing for track '{0} - {1}'", artist, trackTitle);
                    }
                }
            }
        }
Beispiel #2
0
        public static async Task <BitmapImage> LoadCoverFromWeb(PlayableBase track, DirectoryInfo di, bool useArtist = true)
        {
            var config = HurricaneSettings.Instance.Config;

            if (config.SaveCoverLocal)
            {
                if (!di.Exists)
                {
                    di.Create();
                }
            }

            return(await LastfmAPI.GetImage(config.DownloadAlbumCoverQuality, config.SaveCoverLocal, di, track, config.TrimTrackname, useArtist));
        }
        private async void PlaybackService_PlaybackProgressChanged(object sender, EventArgs e)
        {
            if (this.SignInState == SignInState.SignedIn && this.isEnabled)
            {
                // When is a scrobble a scrobble?
                // - The track must be longer than 30 seconds
                // - And the track has been played for at least half its duration, or for 4 minutes (whichever occurs earlier)
                string artist     = this.playbackService.PlayingTrack.ArtistName != Defaults.UnknownArtistString ? this.playbackService.PlayingTrack.ArtistName : string.Empty;
                string trackTitle = this.playbackService.PlayingTrack.TrackTitle;
                string albumTitle = this.playbackService.PlayingTrack.AlbumTitle != Defaults.UnknownAlbumString ? this.playbackService.PlayingTrack.AlbumTitle : string.Empty;

                if (this.canScrobble && !string.IsNullOrEmpty(artist) && !string.IsNullOrEmpty(trackTitle))
                {
                    TimeSpan currentTime = this.playbackService.GetCurrentTime;
                    TimeSpan totalTime   = this.playbackService.GetTotalTime;

                    if (totalTime.TotalSeconds > 30)
                    {
                        if (currentTime.TotalSeconds >= totalTime.TotalSeconds / 2 | currentTime.TotalMinutes > 4)
                        {
                            this.canScrobble = false;

                            bool isSuccess = await LastfmAPI.TrackScrobble(
                                this.username,
                                this.password,
                                this.sessionKey,
                                artist,
                                trackTitle,
                                albumTitle,
                                this.trackStartTime);

                            if (isSuccess)
                            {
                                LogClient.Instance.Logger.Info("Successfully Scrobbled track '{0} - {1}'", artist, trackTitle);
                            }
                            else
                            {
                                LogClient.Instance.Logger.Error("Could not Scrobble track '{0} - {1}'", artist, trackTitle);
                            }
                        }
                    }
                }
            }
        }
        public async Task SignIn()
        {
            this.sessionKey = await LastfmAPI.GetMobileSession(this.username, this.password);

            if (!string.IsNullOrEmpty(this.sessionKey))
            {
                XmlSettingsClient.Instance.Set <string>("Lastfm", "Username", this.username);
                XmlSettingsClient.Instance.Set <string>("Lastfm", "Password", this.password);
                XmlSettingsClient.Instance.Set <string>("Lastfm", "Key", this.sessionKey);
                LogClient.Instance.Logger.Info("User '{0}' successfully signed in to Last.fm.", this.username);
                this.SignInState = SignInState.SignedIn;
            }
            else
            {
                LogClient.Instance.Logger.Error("User '{0}' could not sign in to Last.fm.", this.username);
                this.SignInState = SignInState.Error;
            }

            this.SignInStateChanged(this.SignInState);
        }