public async static Task RetrieveMetaData(string url, Download download)
        {
            download.Status = "Retrieving Metadata";

            var values = new Dictionary <string, string>
            {
                { "youtube_url", url }
            };

            string sJson = JsonConvert.SerializeObject(values);

            var httpContent = new StringContent(sJson, Encoding.UTF8, "application/json");

            Console.WriteLine(sJson);

            //POST the object to the specified URI
            var response = await httpClient.PostAsync("https://beatsage.com/youtube_metadata", httpContent);

            //Read back the answer from server
            var responseString = await response.Content.ReadAsStringAsync();

            int attempts = 0;

            if (!response.IsSuccessStatusCode)
            {
                download.Status  = "Unable To Retrieve Metadata";
                download.IsAlive = false;
                return;
            }

            while (attempts < 2)
            {
                try
                {
                    JObject jsonString = JObject.Parse(responseString);

                    if ((int)jsonString["duration"] / 60 > 10)
                    {
                        Console.WriteLine("Failed, download greater than 10 mins!");
                        download.Status  = "Song >10 Minutes";
                        download.IsAlive = false;
                        return;
                    }

                    await CustomLevelService.Create(jsonString, download, httpClient, cts);

                    break;
                }
                catch
                {
                    attempts += 1;

                    Console.WriteLine("Failed to Create Custom Level!");
                    download.Status  = "Unable To Create Level";
                    download.IsAlive = false;
                    System.Threading.Thread.Sleep(500);
                }
            }
        }
        //Methods
        public async void RunDownloads()
        {
            Console.WriteLine("RunDownloads Started");

            while (true)
            {
                MainWindow.SaveDownloads();

                cts = new CancellationTokenSource();

                List <Download> incompleteDownloads = new List <Download>();

                foreach (Download download in downloads)
                {
                    if (download.Status == "Queued")
                    {
                        incompleteDownloads.Add(download);
                    }
                }

                Console.WriteLine("Checking for Downloads...");

                if (incompleteDownloads.Count >= 1)
                {
                    Download currentDownload = incompleteDownloads[0];
                    currentDownload.IsAlive = true;

                    if ((currentDownload.YoutubeID != "") && (currentDownload.YoutubeID != null))
                    {
                        string itemUrl = "https://www.youtube.com/watch?v=" + currentDownload.YoutubeID;

                        try
                        {
                            if (Properties.Settings.Default.enableLocalYouTubeDownload)
                            {
                                await CustomLevelService.CreateWithLocalMP3Download(itemUrl, currentDownload, httpClient, cts);
                            }
                            else
                            {
                                await DownloadManager.RetrieveMetaData(itemUrl, currentDownload);
                            }
                        }
                        catch
                        {
                            currentDownload.Status = "Unable To Retrieve Metadata";
                        }

                        currentDownload.IsAlive = false;
                        cts.Dispose();
                    }
                    else if ((currentDownload.FilePath != "") && (currentDownload.FilePath != null))
                    {
                        try
                        {
                            await CustomLevelService.CreateFromFile(currentDownload, httpClient, cts);
                        }
                        catch
                        {
                            currentDownload.Status = "Unable To Create Level";
                        }

                        currentDownload.IsAlive = false;
                        cts.Dispose();
                    }
                }

                cts.Dispose();
                System.Threading.Thread.Sleep(1000);
            }
        }
 public static async Task CreateCustomLevelWithLocalMP3Download(string url, Download download)
 {
     await CustomLevelService.CreateWithLocalMP3Download(url, download, httpClient, cts);
 }