Example #1
0
        /// <summary>
        /// Checks if track changed.
        /// </summary>
        protected void CheckIfTrackChanged()
        {
            Track currentTrack = Spotify.GetCurrentTrack();

            if (currentTrack == null && !Spotify.IsAvailable())
            {
                //First stop the hook to prevent multiple occurences of popup.
                if (objectNameChangeHook != null)
                {
                    objectNameChangeHook.Stop();
                }

                //show error no spotify, stop running?
                MessageBox.Show("Error Spotify is not running, Spotify Notifier will now exit.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Application.Current.Shutdown();
            }
            else if ((track == null && currentTrack != null) || (track != null && currentTrack != null && !track.Equels(currentTrack)))
            {
                track = currentTrack;

                if (TrackChanged != null)
                {
                    TrackChanged(this, new EventArgs());
                }
            }
            else
            {
                track = currentTrack;
            }
        }
Example #2
0
        /// <summary>
        /// Gets the cover URL.
        /// </summary>
        /// <param name="track">The track.</param>
        /// <returns>A cover url if succesfull; otherwise the url points to /Resources/Icon.ico</returns>
        public static string GetCoverUrl(Track track)
        {
            string coverUrl = "/Resources/Icon.ico";

            string url = "http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=" + apiKey;
            url += "&artist=" + track.Artist;
            url += "&track=" + track.Title;
            Uri uri = new Uri(url);

            try
            {
                XPathDocument doc = new XPathDocument(uri.AbsoluteUri);
                XPathNavigator nav = doc.CreateNavigator();

                if (nav.SelectSingleNode("/lfm/track/album/image[@size='small']") != null)
                {
                    coverUrl = nav.SelectSingleNode("/lfm/track/album/image[@size='small']").Value;
                }
            }
            catch (System.Net.WebException)
            {
                //Ignore web exceptions.
            }

            return coverUrl;
        }
Example #3
0
        /// <summary>
        /// Gets the current track.
        /// </summary>
        /// <returns>A <c>Track</c> if it can be found.</returns>
        public static Track GetCurrentTrack()
        {
            Track track = null;

            if (Spotify.IsAvailable())
            {
                //Get the Spotify handle
                IntPtr handle = GetHandle();

                //Get the length of the window text
                int length = GetWindowTextLength(handle);

                //Get the window text
                StringBuilder sb = new StringBuilder(length + 1);
                GetWindowText(handle, sb, sb.Capacity);
                string windowText = sb.ToString();

                //Remove prefix "Spotify - " + trim the string
                windowText = windowText.Replace("Spotify - ", "").Trim();
                string[] windowTextSplit = windowText.Split('\u2013'); //Spotify uses an en dash to separate Artist and Title (Thank you Toastify)

                if (windowTextSplit.Length == 2)
                {
                    track = new Track
                    {
                        Artist = windowTextSplit[0].Trim(),
                        Title = windowTextSplit[1].Trim()
                    };
                }
            }

            return track;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TrackNotificationBalloon"/> class.
 /// </summary>
 /// <param name="track">The track.</param>
 public TrackNotificationBalloon(Track track)
     : this()
 {
     this.SetTrack(track);
 }
 /// <summary>
 /// Sets the track.
 /// </summary>
 /// <param name="track">The track.</param>
 public void SetTrack(Track track)
 {
     Title = track.Title;
     Artist = track.Artist;
     Cover = track.CoverUrl;
 }
Example #6
0
 /// <summary>
 /// Checks if the specified track Equelses this track instance.
 /// </summary>
 /// <param name="track">The track.</param>
 /// <returns><c>true</c> if equel; otherwise false.</returns>
 /// <remarks>Does not look at the <c>CoverUrl</c></remarks>
 internal bool Equels(Track track)
 {
     return this.Title.Equals(track.Title, StringComparison.OrdinalIgnoreCase) && this.Artist.Equals(track.Artist, StringComparison.OrdinalIgnoreCase);
 }