Beispiel #1
0
        private static IEnumerable <SpotifyArtist> GetArtistsForTrack(PlaylistTrack oPlaylistTrack)
        {
            List <SpotifyArtist> oArtists = new List <SpotifyArtist>();

            foreach (SimpleArtist oSimpleArtist in oPlaylistTrack.Track.Artists)
            {
                if (oSimpleArtist.Id == null)
                {                                                                                               //Their web model causes this to be null sometimes and I have no idea why but my only course of action is to hash the name and use that as the spotifyID
                    oSimpleArtist.Id = HashSlingingSlasher.HashString(oSimpleArtist.Name + oSimpleArtist.Type); //Using the name and the type should make it pretty darn unique I would think....
                }
                oArtists.Add(new SpotifyArtist(oSimpleArtist));
            }

            return(oArtists);
        }
Beispiel #2
0
        private static Dictionary <int, SpotifyTrack> GetTracksForPlaylist(SpotifyWebAPI oWebCLient, SimplePlaylist oSimplePlaylist, SpotifyUser oSpotifyUser)
        {
            Dictionary <int, SpotifyTrack> oTracks = new Dictionary <int, SpotifyTrack>();
            Paging <PlaylistTrack>         oPagingPlaylistTracks = oWebCLient.GetPlaylistTracks(oSimplePlaylist.Owner.Id, oSimplePlaylist.Id, market: "");
            int iPos = 0;

            foreach (PlaylistTrack oPlaylistTrack in oPagingPlaylistTracks.Items)
            {
                List <SpotifyArtist> oArtists = new List <SpotifyArtist>();
                oArtists.AddRange(GetArtistsForTrack(oPlaylistTrack));
                if (oPlaylistTrack.Track.Id == null)
                {
                    if (oPlaylistTrack.Track.Name != null && oPlaylistTrack.Track.Type != null)
                    {//Issues with some tracks having null id properties and the only way to deal with that is to try to hash an id myself
                        oPlaylistTrack.Track.Id = HashSlingingSlasher.HashString(oSimplePlaylist.Name + oSimplePlaylist.Type);
                    }
                }
                oTracks.Add(iPos, new SpotifyTrack(oPlaylistTrack, oArtists));
                iPos++;
            }
            while (oPagingPlaylistTracks.Next != null)
            {
                oPagingPlaylistTracks = oWebCLient.DownloadData <Paging <PlaylistTrack> >(oPagingPlaylistTracks.Next);
                foreach (PlaylistTrack oPlaylistTrack in oPagingPlaylistTracks.Items)
                {
                    List <SpotifyArtist> oArtists = new List <SpotifyArtist>();
                    oArtists.AddRange(GetArtistsForTrack(oPlaylistTrack));
                    if (oPlaylistTrack.Track.Id == null)
                    {
                        if (oPlaylistTrack.Track.Name != null && oPlaylistTrack.Track.Type != null)
                        {//Issues with some tracks having null id properties and the only way to deal with that is to try to hash an id myself
                            oPlaylistTrack.Track.Id = HashSlingingSlasher.HashString(oSimplePlaylist.Name + oSimplePlaylist.Type);
                        }
                    }
                    oTracks.Add(iPos, new SpotifyTrack(oPlaylistTrack, oArtists));
                    iPos++;
                }
            }

            return(oTracks);
        }