public IEnumerator loadTopTracks()
    {
        yield return(new WaitForSeconds(2));

        usersTopTracks = spotifyManagerScript.GetUsersTopTracks();
        if (usersTopTracks == null || usersTopTracks.Items.Count == null)
        {
            Debug.LogError("usersTopTracks is null/empty");
        }
        else
        {
            for (int i = 0; i < meshRenderers.Length; i++)
            {
                string featuredPlaylistImageURL = usersTopTracks.Items[i].Album.Images[0].Url;

                GameObject meshRendererGameObject = meshRenderers[i].transform.gameObject;

                PlaylistScript playlistScript = meshRendererGameObject.GetComponent <PlaylistScript>();

                WWW imageURLWWW = new WWW(featuredPlaylistImageURL);

                yield return(imageURLWWW);

                meshRenderers[i].material.mainTexture = imageURLWWW.texture;

                playlistScript.setPlaylistName(usersTopTracks.Items[i].Name);
                playlistScript.setPlaylistURI(usersTopTracks.Items[i].Uri);
                playlistScript.setFullTrack(usersTopTracks.Items[i]);
                playlistScript.audioAnalysis = spotifyManagerScript.GetAudioAnalysis(usersTopTracks.Items[i].Id);
                playlistScript.sprite        = ConvertWWWToSprite(imageURLWWW);
            }
        }
    }
    public IEnumerator LoadChartTracks()
    {
        yield return(new WaitForSeconds(2));

        if (chartTracks == null || chartTracks.Count == 0)
        {
            Debug.LogError("Chart tracks is null/empty");
        }
        else
        {
            for (int i = 0; i < meshRenderers.Length; i++)
            {
                //i+1 because first row is header names
                ChartTrack chartTrack = (ChartTrack)chartTracks[i + 1];
                FullTrack  fullTrack  = spotifyManagerScript.GetTrack(chartTrack.apiUrl);

                if (fullTrack.HasError())
                {
                    Debug.LogError(fullTrack.Error.Status);
                    Debug.LogError(fullTrack.Error.Message);
                }
                else
                {
                    string chartTrackImageURL = fullTrack.Album.Images[0].Url;

                    GameObject meshRendererGameObject = meshRenderers[i].transform.gameObject;

                    PlaylistScript playlistScript = meshRendererGameObject.GetComponent <PlaylistScript>();

                    WWW imageURLWWW = new WWW(chartTrackImageURL);

                    yield return(imageURLWWW);

                    meshRenderers[i].material.mainTexture = imageURLWWW.texture;

                    AudioAnalysis audioAnalysis = spotifyManagerScript.GetAudioAnalysis(fullTrack.Id);

                    playlistScript.setFullTrack(fullTrack);
                    playlistScript.setPlaylistName(fullTrack.Name);
                    playlistScript.setPlaylistURI(fullTrack.Uri);
                    playlistScript.artistId            = fullTrack.Artists[0].Id;
                    playlistScript.artistName          = fullTrack.Artists[0].Name;
                    playlistScript.sprite              = ConvertWWWToSprite(imageURLWWW);
                    playlistScript.audioAnalysis       = audioAnalysis;
                    playlistScript.audioAnalysisCustom = new AudioAnalysisCustom(audioAnalysis);
                    playlistScript.trackId             = fullTrack.Id;
                    playlistScript.streams             = chartTrack.streams;
                    saveLoad.SaveTextureToFilePNG(Converter.ConvertWWWToTexture(imageURLWWW), "chartTrack" + i + ".png");
                    saveLoad.savedChartTracks.Add(new PlaylistScriptData(playlistScript));

                    Vector3 v = popCubes[i].transform.localScale;

                    if (chartTrack.streams != null)
                    {
                        popCubes[i].transform.localScale = new Vector3(v.x, float.Parse(chartTrack.streams) * streamsScaling, v.z);
                    }
                }
            }
        }
    }
    public IEnumerator loadTopTracks()
    {
        yield return(new WaitForSeconds(2));

        usersTopTracks = spotifyManagerScript.GetUsersTopTracks();
        if (usersTopTracks == null || usersTopTracks.Items.Count == 0)
        {
            Debug.LogError("usersTopTracks is null/empty");
        }
        else
        {
            for (int i = 0; i < meshRenderers.Length; i++)
            {
                string topTrackImageURL = null;

                if (usersTopTracks.Items[i].Album.Images.Count != 0)
                {
                    topTrackImageURL = usersTopTracks.Items[i].Album.Images[0].Url;
                }

                GameObject meshRendererGameObject = meshRenderers[i].transform.gameObject;

                PlaylistScript playlistScript = meshRendererGameObject.GetComponent <PlaylistScript>();

                WWW imageURLWWW = null;

                if (topTrackImageURL != null)
                {
                    imageURLWWW = new WWW(topTrackImageURL);

                    yield return(imageURLWWW);

                    meshRenderers[i].material.mainTexture = imageURLWWW.texture;
                }

                AudioAnalysis audioAnalysis = spotifyManagerScript.GetAudioAnalysis(usersTopTracks.Items[i].Id);

                playlistScript.setPlaylistName(usersTopTracks.Items[i].Name);
                playlistScript.setPlaylistURI(usersTopTracks.Items[i].Uri);
                playlistScript.setFullTrack(usersTopTracks.Items[i]);
                playlistScript.audioAnalysis = audioAnalysis;

                if (imageURLWWW != null)
                {
                    playlistScript.www    = imageURLWWW;
                    playlistScript.sprite = ConvertWWWToSprite(imageURLWWW);
                    saveLoad.SaveTextureToFilePNG(ConvertWWWToTexture(imageURLWWW), "topTrack" + i + ".png");
                }

                playlistScript.trackId             = usersTopTracks.Items[i].Id;
                playlistScript.audioAnalysisCustom =
                    new AudioAnalysisCustom(audioAnalysis);
                saveLoad.savedTopTracks.Add(new PlaylistScriptData(playlistScript));
            }
            // yield return new WaitForSeconds(saveLoad.saveTime);
            // saveLoad.Save();
        }
    }