Example #1
0
        private void CheckTitle()
        {
            string currentTitle = Spotify.GetCurrentTrack();

            if (!string.IsNullOrEmpty(currentTitle) && currentTitle != previousTitle)
            {
                string part1, part2;

                // set the previous title asap so that the next timer call to this function will
                // fail fast (setting it at the end may cause multiple web requests)
                previousTitle = currentTitle;

                if (SplitTitle(currentTitle, out part1, out part2))
                {
                    this.Dispatcher.Invoke((Action) delegate { Title1.Text = part2; Title2.Text = part1; }, System.Windows.Threading.DispatcherPriority.Normal);

                    foreach (var p in this.Plugins)
                    {
                        try
                        {
                            p.TrackChanged(part1, part2);
                        }
                        catch (Exception)
                        {
                            //For now we swallow any plugin errors.
                        }
                    }
                }

                try
                {
                    //Use the iTunes API to get the cover art
                    String url  = "https://itunes.apple.com/search?term=" + part2 + "&attribute=songTerm&entity=album";
                    var    json = new WebClient().DownloadString(url);

                    iTunesResult deserializedJson = JsonConvert.DeserializeObject <iTunesResult>(json);

                    //Filter tracks by artist
                    List <iTunesTrack> resultsForArtist = getResultsForArtist(deserializedJson, part1);

                    //Get the oldest track (filters out all the "best of" albums, etc.)
                    iTunesTrack oldestTrack = getOldestTitle(resultsForArtist);

                    coverUrl = oldestTrack.artworkUrl100;
                }
                catch (Exception)
                {
                    coverUrl = "SpotifyToastifyLogo.png";
                }

                this.Dispatcher.Invoke((Action) delegate { FadeIn(); }, System.Windows.Threading.DispatcherPriority.Normal);
            }
        }
Example #2
0
        private List <iTunesTrack> getResultsForArtist(iTunesResult data, String artist)
        {
            List <iTunesTrack> returnList = new List <iTunesTrack>();

            foreach (iTunesTrack result in data.results)
            {
                if (result.artistName.Equals(artist))
                {
                    returnList.Add(result);
                }
            }

            return(returnList);
        }