/// <summary> /// NEEDS PROPER REFACTORING /// </summary> /// <param name="urlToGet"></param> /// <param name="trackToGetId"></param> /// <param name="userId"></param> /// <param name="trackTitle"></param> /// <param name="resolveURLJson"></param> private static void DownloadSet(string urlToGet, ref string trackToGetId, ref string userId, ref string trackTitle, ref dynamic resolveURLJson) { resolveURLJson = SendAPIRequest(_api.MakeCallResolveURL(urlToGet)); trackToGetId = resolveURLJson["id"]; string setName = resolveURLJson["user"]["username"] + " - " + resolveURLJson["title"]; userId = resolveURLJson["user_id"]; //trackTitle = resolveURLJson["title"]; Newtonsoft.Json.Linq.JContainer tracklist = resolveURLJson["tracks"]; List <Track> tracks = new List <Track>(); foreach (var t in tracklist.Children()) { if (t["kind"].ToString() != "track") { ops.Log(String.Format("{0} : \n", "Found something other than a track!"), ConsoleColor.Red); ops.Log(String.Format("{0}", t.ToString()), ConsoleColor.Magenta); continue; } Track newTrack = JsonPopulatorService.GetTrackFromJToken(t); tracks.Add(newTrack); } PreviewSet(urlToGet); string theResult = ""; foreach (Track t in tracks) { try { theResult += GrabTrackById(t.Id, setName) + "\n\n"; } catch (Exception ex) { ExceptionThrown(ex, new EventArgs()); } } Console.WriteLine(theResult); //try //{ //} //catch (Exception ex) //{ // Console.WriteLine(trackToGetId.ToString() + " " + ex.Message); //} //finally //{ // Console.WriteLine(trackToGetId.ToString() + " finished."); //} }
/// <summary> /// NEEDS PROPER REFACTORING /// returns the list of track URIs /// </summary> /// <param name="urlToGet"></param> /// <param name="trackToGetId"></param> /// <param name="userId"></param> /// <param name="trackTitle"></param> /// <param name="resolveURLJson"></param> private static List <string> PreviewSet(string urlToGet) { dynamic resolveURLJson = SendAPIRequest(_api.MakeCallResolveURL(urlToGet)); string trackToGetId = resolveURLJson["id"]; string setName = resolveURLJson["user"]["username"] + " - " + resolveURLJson["title"]; string userId = resolveURLJson["user_id"]; //trackTitle = resolveURLJson["title"]; Newtonsoft.Json.Linq.JContainer tracklist = resolveURLJson["tracks"]; List <Track> tracks = new List <Track>(); double playlistSize = 0; foreach (var t in tracklist.Children()) { if (t["kind"].ToString() != "track") { ops.Log(String.Format("{0} : \n", "Found something other than a track!"), ConsoleColor.Red); ops.Log(String.Format("{0}", t.ToString()), ConsoleColor.Magenta); continue; } Track newTrack = JsonPopulatorService.GetTrackFromJToken(t); tracks.Add(newTrack); } playlistSize = tracks.Sum(x => x.GetSizeInMegabytes()); ops.Log(String.Format("{0} ", setName), ConsoleColor.Green); ops.Log(String.Format("In this set listing there are {0} track(s):", tracks.Count), ConsoleColor.White); ops.Log(String.Format("Est. Total playlist size: "), ConsoleColor.White); ops.Log(String.Format("{0:N1}MB", playlistSize), ConsoleColor.Cyan); ops.LogLines(tracks.Select(t => t.ToString()).ToArray()); //tracks.ForEach(x => GetSongInfo(x.Uri)); return(tracks.Select(x => x.Uri).ToList()); }