/// <summary> /// Function to get a list of playlists and the playlists songs /// </summary> /// <param name="from">Number the list should start from</param> /// <returns>List of playlists</returns> public static List<Playlist> GetPlaylistWithSongs(int startFrom) { string data = GetSite(URL + "/playlists?from=" + startFrom); string[] separator = { "\n" }; string[] splitedData = data.Split(separator, StringSplitOptions.RemoveEmptyEntries); string[] separator2 = { "|" }; string[] separator3 = { "=" }; List<Playlist> playlists = new List<Playlist>(); Playlist lastPlaylist = new Playlist(); Song lastSongInfo = new Song(); int from = 0; int to = 0; int remaining = 0; for (int i = 0; i < splitedData.Length; i++) { if (splitedData[i].Contains("from") || splitedData[i].Contains("to") || splitedData[i].Contains("remaining")) { string[] rowData = splitedData[i].Split(separator3, StringSplitOptions.RemoveEmptyEntries); switch (rowData[0].ToLower()) { case "from": from = Convert.ToInt32(rowData[1]); break; case "to": to = Convert.ToInt32(rowData[1]); break; case "remaining": remaining = Convert.ToInt32(rowData[1]); break; default: break; } } else { string[] rowData = splitedData[i].Split(separator2, StringSplitOptions.RemoveEmptyEntries); switch (rowData[0].ToLower()) { case "playlist": if ((lastPlaylist.Name != string.Empty) && (lastPlaylist.Songs != null) && (lastPlaylist.Songs.Count > 0)) { playlists.Add(lastPlaylist); } lastPlaylist = new Playlist(); lastPlaylist.SpotifyURL = rowData[2]; lastPlaylist.Name = rowData[3]; lastPlaylist.Songs = new List<Song>(); break; case "track": lastSongInfo = new Song(); lastSongInfo.Track = new SongInfo() { SpotifyURL = rowData[2], Name = rowData[3] }; break; case "artist": lastSongInfo.Artist = new SongInfo() { SpotifyURL = rowData[2], Name = rowData[3] }; lastPlaylist.Songs.Add(lastSongInfo); break; case "from": from = Convert.ToInt32(rowData[1]); break; case "to": to = Convert.ToInt32(rowData[1]); break; case "remaining": remaining = Convert.ToInt32(rowData[1]); break; default: break; } } } if ((remaining > 0) && (to != from)) { playlists.AddRange(GetPlaylistWithSongs(to)); } return playlists; }
public static List<Song> Search(string searchValue) { List<Song> songList = new List<Song>(); Song lastSong = null; string data = GetSite(URL + "/search?cc=NO&query=" + searchValue); string[] separator = { "\n" }; string[] splitedData = data.Split(separator, StringSplitOptions.RemoveEmptyEntries); string[] separator2 = { "|" }; for (int i = 0; i < splitedData.Length; i++) { string[] splitedDataRow = splitedData[i].Split(separator2, StringSplitOptions.RemoveEmptyEntries); if (splitedDataRow[1] == "0") { if (lastSong != null) { songList.Add(lastSong); } lastSong = new Song(); } switch (splitedDataRow[0]) { case "artist": lastSong.Artist = new SongInfo() { Name = splitedDataRow[3], SpotifyURL = splitedDataRow[2] }; break; case "track": lastSong.Track = new SongInfo() { Name = splitedDataRow[3], SpotifyURL = splitedDataRow[2] }; break; case "album": lastSong.Album = new SongInfo() { Name = splitedDataRow[3], SpotifyURL = splitedDataRow[2] }; break; } } return songList; }