Esempio n. 1
0
        private static void ValidateUrl(string url, string title, string genre)
        {
            Console.WriteLine("Trying url: {0}", url);

            try
            {
                Uri uri = new Uri(url);
                string hostName = uri.DnsSafeHost;

                //if (!QueryDnsWithTimeout(hostName, 300))
                //{
                //    Console.WriteLine("\t   -> Url: {0} is not valid (DNS error)", url);
                //    return;
                //}

                List<String> urlsToCkeck = new List<string>();

                if (IsPlaylist(url))
                {
                    string fileName = Path.GetFileName(uri.LocalPath);
                    string tempFile = @"c:\temp.pls";

                    using (WebClientWithTimeout wc = new WebClientWithTimeout())
                    {
                        wc.Timeout = 500;
                        wc.Proxy = AppSettings.GetWebProxy();
                        wc.DownloadFile(uri, tempFile);
                    }

                    if (File.Exists(tempFile))
                    {
                        Playlist p = new Playlist();
                        p.LoadPlaylist(tempFile);

                        File.Delete(tempFile);

                        foreach (PlaylistItem item in p.AllItems)
                        {
                            urlsToCkeck.Add(item.Path);
                        }
                    }
                }
                else
                {
                    urlsToCkeck.Add(url);
                }

                foreach(string url2 in urlsToCkeck)
                {
                    //if (!QueryDnsWithTimeout(url2, 300))
                      //  continue;

                    ShoutcastStream ss = new ShoutcastStream(url2, 500);
                    if (ss.Connected)
                    {
                        RadioStation rs = new RadioStation { Genre = genre, Title = title, Url = url2 };
                        data.RadioStations.Add(rs);

                        Console.WriteLine("\t   -> Added radio station: {0}", url2);

                        ss.Close();
                        ss.Dispose();
                        ss = null;
                    }
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine("\t   ->" + ex.Message);
            }

            Console.WriteLine("\t   -> Url: {0} is not valid", url);

        }